Re: how to communicate unsigned char* to Java
- From: Ananya <Ananya@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 May 2007 20:56:00 -0700
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:.
HiSnip from GP:
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
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
- Follow-Ups:
- Re: how to communicate unsigned char* to Java
- From: Ananya
- Re: how to communicate unsigned char* to Java
- References:
- Re: how to communicate unsigned char* to Java
- From: Alexander Nickolov
- Re: how to communicate unsigned char* to Java
- From: Ananya
- Re: how to communicate unsigned char* to Java
- From: Ali
- Re: how to communicate unsigned char* to Java
- From: Günter Prossliner
- Re: how to communicate unsigned char* to Java
- From: Ali
- Re: how to communicate unsigned char* to Java
- Prev by Date: Re: how to communicate unsigned char* to Java
- Next by Date: Re: how to communicate unsigned char* to Java
- Previous by thread: Re: how to communicate unsigned char* to Java
- Next by thread: Re: how to communicate unsigned char* to Java
- Index(es):
Relevant Pages
|
Loading