On Sep 22, 2005, at 8:40 PM, Patrick LeBoutillier wrote:
Jason,
Have you tried something like this:
I have. I've attached some very similar code that I've tried just to
get things working. I agree that splitting a (potentially large)
string into bytes is expensive, but if that works I'll find a way to
deal with it. I've tried enabling debugging to see whats going on.
I'll continue down that path. The core of the problem is that the
array isn't being treated as bytes.
The reason I thought I'd need to cast or coerce the data is because I
get this message at runtime:
In method write of class main::java::io::ByteArrayOutputStream: Can't
find any signature that matches the arguments passed (ARRAY
(0x82159ec), 0, 255).
Available signatures are:
write(int)
error was: Wrong number of arguments at /home/
jstelzer/projects/datapump/dp_build/hms/datapump/ext/lib/perl5/
site_perl/5.8.6/i686-linux/Inline/Java/Object.pm line 101
write([B, int, int)
error was: 128 out of range for type byte at /home/
jstelzer/projects/datapump/dp_build/hms/datapump/ext/lib/perl5/
site_perl/5.8.6/i686-linux/Inline/Java/Array.pm line 540
write([B)
error was: Wrong number of arguments at /home/
jstelzer/projects/datapump/dp_build/hms/datapump/ext/lib/perl5/
site_perl/5.8.6/i686-linux/Inline/Java/Object.pm line 101 at x.pl
line 31
use strict;
use warnings;
use Inline (
Java => 'STUDY',
SHARED_JVM => 0,
AUTOSTUDY => 1,
J2SDK => $ENV{JAVA_HOME},
CLASSPATH => $ENV{CLASSPATH},
JNI => 1,
EXTRA_JAVA_ARGS => '-Xmx128M',
DEBUG => 0,
);
use Inline::Java qw(study_classes cast caught);
study_classes(['java.io.ByteArrayOutputStream']);
my $val1 = '';
#generate binary data
for (my $i = 0; $i < 255 ; $i++) {
$val1 .= chr($i);
}
my @bytes = map { ord($_) } split('',$val1);
print "Val1:",$val1,"\n";
print "########\n";
print join('',@bytes),"\n";
print "########\n";
my $val2 = join('',map {chr($_)} @bytes),"\n";
print "Strings mismatched\n" unless ($val1 eq $val2);
my $os = new java::io::ByteArrayOutputStream();
$os->write([EMAIL PROTECTED],0,scalar(@bytes));
my @java_bytes = @{$os->toByteArray()};
print "########\n";
print join('',@java_bytes),"\n";
print "########\n";
print join('',map {chr($_)} @java_bytes),"\n";