|
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
|
|
From: <php...@li...> - 2007-08-24 15:31:51
|
Hi,
> $bytes = $string->getBytes();
getBytes() depends on the LOCALE. Please see your Java documentation for details.
Please use $string->getBytes("ENCODING") or use java_values($string) instead. java_values() uses
the file encoding set with java_set_file_encoding(), default is UTF-8.
Please see the README and the java_set_file_encoding() for details.
Regards,
Jost Boekemeier
__________________________________
Alles was der Gesundheit und Entspannung dient. BE A BETTER MEDIZINMANN! www.yahoo.de/clever
|
|
From: <php...@li...> - 2007-08-24 16:00:14
|
I'm afraid I don't see how this helps. (My use of a String was only an
attempt to more simply demonstrate the problem.) I'm using a class that
takes a byte array and gives a byte array:
protected byte[] data;
public byte[] getData() {
return data;
}
public void setData(byte[] value) {
this.data =3D value;
}
And this is basically how I'm testing it:
$file =3D file_get_contents('foo.pdf');
$javaObject->setData($file);
$output =3D $javaObject->getData();
strcmp($file, $output);
=09
And the bytes coming out of the getData() method are different from the
bytes going into the setData() method. Sorry for being so dense on
this.
Thanks,
Jonathan
=20
> -----Original Message-----
> From: php...@li...=20
> [mailto:php...@li...]=20
> On Behalf Of php...@li...
> Sent: Friday, August 24, 2007 11:32 AM
> To: php...@li...
> Subject: Re: [Php-java-bridge-users] Bytes are getting=20
> mistranslated somewhere
>=20
> Hi,
>=20
> > $bytes =3D $string->getBytes();
>=20
> getBytes() depends on the LOCALE. Please see your Java=20
> documentation for details.
>=20
>=20
> Please use $string->getBytes("ENCODING") or use=20
> java_values($string) instead. java_values() uses
> the file encoding set with java_set_file_encoding(), default is UTF-8.
>=20
> Please see the README and the java_set_file_encoding() for details.
>=20
>=20
> Regards,
> Jost Boekemeier
>=20
>=20
>=20
> __________________________________ =20
> Alles was der Gesundheit und Entspannung dient. BE A BETTER=20
> MEDIZINMANN! www.yahoo.de/clever
>=20
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and=20
> a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>=20
>=20
|
|
From: <php...@li...> - 2007-08-25 11:17:17
|
Hi Jonathan, > $javaObject->setData($file); > $output = $javaObject->getData(); > strcmp($file, $output); > > And the bytes coming out of the getData() method are different from the > bytes going into the setData() method. there's a test case (tests.php5/binaryData.php) which checks this. Can you please check if $file and $output have the same type and, if that's the case, please set the log level to 4 or above, open a new ticket (please use http://sourceforge.net/tracker/?func=add&group_id=117793&atid=679233) and attach the log at the end of that ticket. We'll look at this issue asap. Regards, Jost Boekemeier Wissenswertes für Bastler und Hobby Handwerker. BE A BETTER HEIMWERKER! www.yahoo.de/clever |
|
From: <php...@li...> - 2007-08-27 13:05:43
|
Last night, I discovered that I needed to use java_values() on the byte =
array before it was comparable to the original data, i.e.
$file =3D file_get_contents('foo.pdf');
$javaObject->setData($file);
$output =3D $javaObject->getData();
strcmp($file, java_values($output)); // wrapped $output in =
java_values()
Otherwise, it would try to compare $file to =
[[o:array_of_B]:"[B@1c3ee45"].
Thanks for prodding me in the right direction.
Best,
Jonathan
> -----Original Message-----
> From: php...@li...=20
> [mailto:php...@li...]=20
> On Behalf Of php...@li...
> Sent: Saturday, August 25, 2007 7:17 AM
> To: php...@li...
> Subject: Re: [Php-java-bridge-users] Bytes are getting=20
> mistranslated somewhere
>=20
> Hi Jonathan,
>=20
> > $javaObject->setData($file);
> > $output =3D $javaObject->getData();
> > strcmp($file, $output);
> > =09
> > And the bytes coming out of the getData() method are=20
> different from the
> > bytes going into the setData() method. =20
>=20
> there's a test case (tests.php5/binaryData.php) which checks this.=20
>=20
> Can you please check if $file and $output have the same type=20
> and, if that's the case, please set
> the log level to 4 or above, open a new ticket (please use
> http://sourceforge.net/tracker/?func=3Dadd&group_id=3D117793&atid=3D
> 679233) and attach the log at the
> end of that ticket. We'll look at this issue asap.
>=20
>=20
> Regards,
> Jost Boekemeier
>=20
>=20
>=20
>=20
>=20
> Wissenswertes f=FCr Bastler und Hobby Handwerker. BE A=20
> BETTER HEIMWERKER! www.yahoo.de/clever
>=20
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and=20
> a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>=20
>=20
|
|
From: <php...@li...> - 2007-08-27 18:57:43
|
Hi Jonathan,
> Last night, I discovered that I needed to use java_values() on the byte array
Yes. java_values() converts a Java object to the appropriate PHP value(s), a PHP binary string in
this case.
However, people shouldn't need to write unnatural code; whenever PHP needs to convert a proxy into
a String, it calls $proxy->__toString(). On the server side the method is called
"ObjectToString(value)".
What about adding the following code to JavaBridge.java:
public String ObjectToString(byte[] value) {
// FIXME: use the StringCache
try {
return new String( (byte[])castToString(value), getOptions().getFileEncoding());
} catch (IllegalEncodingException ex) {
// shouldn't happen
Util.printStackTrace(ex);
return new String( (byte[])castToString(value) );
}
}
Regards,
Jost Boekemeier
Machen Sie Yahoo! zu Ihrer Startseite. Los geht's:
http://de.yahoo.com/set
|