|
From: <php...@li...> - 2007-08-24 15:27:34
|
Greetings, all--
I'm trying to use an object which sets and gets a byte array, and I
noticed that the bytes I put in are different from the bytes I get out.
I was able to narrow down the problem to this brief script:
$file =3D file_get_contents("fw4.pdf");
$string =3D new Java("java.lang.String", $file);
$bytes =3D $string->getBytes();
echo strcmp($file, $bytes);
I read a binary file in (available at
http://www.irs.gov/pub/irs-pdf/fw4.pdf), put it into a Java string, and
spit out the bytes. That comparison returns -1, not equal. (For what
it's worth, when I just echo the file_get_contents(), the data comes out
fully parseable, and identical to the source file.)
I also tried to read the file in with a FileInputStream and output it
immediately to a ByteArrayOutputStream (which takes forever, by the way)
and got the same result:
$phpfile =3D file_get_contents("fw4.pdf");
$file =3D new Java('java.io.File', 'fw4.pdf');
$inputStream =3D new Java('java.io.FileInputStream', $file);
$outputStream =3D new Java('java.io.ByteArrayOutputStream');
=09
while ($inputStream->available()) {
$outputStream->write($inputStream->read());
}
$bytes =3D $outputStream->toByteArray()
=09
echo strcmp($phpfile, $bytes);
Any help on the proper handling of byte arrays would be greatly
appreciated.
Thanks,
Jonathan Abbett
|