Re: how to communicate unsigned char* to Java



On May 22, 11:18 pm, "Günter Prossliner" <g.prossliner/gmx/at> wrote:
Hi

Well! why don't you just write it with char* and read it via
java string.

This will not work, allthough it _may_ work on some bunch of data.

Because: Strings in Java are Unicode (aka UTF-16). An not every sequence of
bytes is valid Unicode. Unicode Implementations may substitute the illegal
chars with something else, or throw an error.

Now write some funny code to elaborate those strings to
meaningful values;-)

Converting random binary data into a Unicode-String and converting this
Unicode-String back to binary data will not produce the same data again in
many cases.

While in a "none-unicode" world Strings could be used to carry some binary
data (allthough it was never a good coding practice), these techniques will
not work propery when you have unicode DataTypes and Parsers.

You just have to use the byte - Datatype to read arbitary binary data in
Java.

GP
Snip from GP:
This will not work, allthough it _may_ work on some bunch of data.

And what is the data limit of this working solution? i mean the max
size when this tech. will stop working.

Snip from GP:
Now write some funny code to elaborate those strings to
meaningful values;-)

Converting random binary data into a Unicode-String and converting this
Unicode-String back to binary data will not produce the same data again in
many cases.

char is a byte and char pointer is the size of underlying processor's
execution register (a.k.a accumulator register). And as you people
said that java is having unicode-16 for string which is indeed 16 bit
(2 bytes) for every single character that it will read from common
file systems (ramfs, ntfs etc. etc. ).

Honestly i've never been through the code for getbyte (IIRC java
function) as pointed by GP but i'm sure it would be putting the lower
byte (or say it higher byte ) unusable when it comes to 8 bit (a byte
UTF-8) data. So, the point is that you are suppose to put 8 bit data
in 16 bit place, is it that hard to do? Oh, yeah, go for libraries
that might save your immediate code but can't say that it will never
have the latency lib call time overhead too.


ali

.



Relevant Pages

  • Re: TripleDES output size
    ... It is probably a good idea to use either Unicode or UTF-8 if you may need to ... You also have the option of not storing the data in SQL as string but as ... If you convert from your binary data to string with Base64 (which is ... Anyway, as I need to use Italian character set, I think I'm forced to ...
    (microsoft.public.dotnet.security)
  • Re: Tranfering unicod charcters in Socket programming!
    ... You are telling about conversion b/w MBCS to Unicode. ... If this is not possible Shall I try with string to wstring ... int SendStringAsUnicode ...
    (microsoft.public.win32.programmer.networks)
  • Re: using structs like BROWSEINFO and OPENFILENAME (string members
    ... your discussion of unicode ... vs ansi reminded me to recheck my typelib and found a couple of errors. ... > is declared as string, the other is declared as long. ...
    (microsoft.public.vb.winapi)
  • Re: Tranfering unicod charcters in Socket programming!
    ... As you said I have to use std::wstring for unicode characters .But ... std::string object, which is a wrapper over ANSI string. ... int CParser::RetrieveCmd(string strRecvbuf, string* strCmd, ... bytesRecv - is the number of bytes. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Tranfering unicod charcters in Socket programming!
    ... unicode string and back again. ... bytesRecv = SOCKET_ERROR; ... Rlp has doen to fix unicode ...
    (microsoft.public.win32.programmer.networks)