Re: how to communicate unsigned char* to Java



Thanks for all your input!

Actually at this point I think I figured out the code in Java fore reading
the bytes:
pixelFile = new FileInputStream("pixels.dat");
pixelData = new DataInputStream(pixelFile);
pixelByte = new byte [3*pixcount];
try
{
pixelData.read(pixelByte);
....
}
catch (IOException e)
{
}
and I know how to make the bytes unsigned integers by using & 0xff.

But I still haven't figured out the code in C++ for writing the bytes.
What I have so far is:
unsigned char *pixels = ...
char *charpixels = reinterpret_cast<char*>(pixels);
FileStream file = new FileStream(S"pixels.dat", FileMode::Create,
FileAccess::Write);
BinaryWriter binary = new BinaryWriter(file);
binary.write(charpixels, pixcount);
binary.close();

However, my compiler doesn't recognize FileStream and BinaryWriter,
and when I try:
using namespace System::IO;
the compiler says that a namespace with this name does not exist.

Is my code correct, and what "using" or "include" do I need?
By the way, I copied new FileStream(S"pixels.dat",...) from somewhere and I
don't know what the "S" means?

I posted the question "how to write a binary file" also in the vc.language
forum at:
http://msdn.microsoft.com/newsgroups/default.aspx?&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.vc.language&p=1&tid=662db087-82f1-4ab4-8802-f56c94c8d967

Thanks for reading this.


"Ali" wrote:

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: drawString with special Unicode characters to Graphics object
    ... 4.1.0-alpha does not support Unicode, so there is the first problem. ... some improvement in that I can now see special characters IF I query ... displays the string "Haussömmern", incl. ... Java program does things like this: ...
    (comp.lang.java.programmer)
  • Re: Help me!! Why java is so popular
    ... You are basically arguing that "Java is slow because it is slow". ... > Also, a JVM can pay attention to usage, provide caching, adapt at run ... I have no use for unicode in my ...
    (comp.lang.java.programmer)
  • Re: how to communicate unsigned char* to Java
    ... Strings in Java are Unicode. ... Converting random binary data into a Unicode-String and converting this ... said that java is having unicode-16 for string which is indeed 16 bit ...
    (microsoft.public.win32.programmer.networks)
  • Re: Schnittstelle - Winsock, String, Unicode
    ... Java arbeitet mit Big Endian Unicode, ... Zeichen aus dem 8bit ziel-Zeichensatz enthält, ... Unicode-Strings unterstützt werden, ...
    (microsoft.public.de.vb)
  • Re: JNI / localization / filenames
    ... fact that Java and Unicode don't match. ... fundamental assumption of the Java programming language and APIs. ... characters and enables the Java platform to continue to track the Unicode ... of 16-bit quantities using UTF-16. ...
    (comp.lang.java.programmer)

Loading