Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FlateDecode with Java Problems

740 views
Skip to first unread message

Cameron Taggart

unread,
May 8, 2002, 10:38:21 PM5/8/02
to
I am trying to decompress (inflate) a flate compressed stream using the Java
2 SDK SE v1.4. Although flate compression is built in to Java, I am having
some major issues. I'm using the the following couple of classes:

ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); // in
InflaterInputStream iis = new InflaterInputStream( bais ); // wrap in

Should I be using InflaterInputStream or ZipInputStream? Are their setting
in the stream dictionary that are needed for decoding? Like, what does the
"/S 36" mean in the following object? I've been looking in the PDF
Reference Guide, but I haven't had any luck.

14 0 obj
<< /S 36 /Filter /FlateDecode /Length 15 0 R >>
stream
H?b``ŕb``ęc...
endstream
endobj

Here are the errors I'm receiving:

java.util.zip.ZipException: incomplete dynamic bit lengths tree
java.util.zip.ZipException: invalid distance code
java.util.zip.ZipException: invalid bit length repeat

Anyone know why I might be getting errors like these errors? Any help
decoding flate streams in Java would be greately appreciated.

Thanks,
Cameron


ma...@idrsolutions.com

unread,
May 9, 2002, 1:59:52 PM5/9/02
to
Cameron Taggart wrote:

> I am trying to decompress (inflate) a flate compressed stream using the
> Java
> 2 SDK SE v1.4. Although flate compression is built in to Java, I am
> having
> some major issues. I'm using the the following couple of classes:
>
> ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); // in
> InflaterInputStream iis = new InflaterInputStream( bais ); // wrap in
>
> Should I be using InflaterInputStream or ZipInputStream? Are their
> setting
> in the stream dictionary that are needed for decoding? Like, what does
> the
> "/S 36" mean in the following object? I've been looking in the PDF
> Reference Guide, but I haven't had any luck.
>
> 14 0 obj
> << /S 36 /Filter /FlateDecode /Length 15 0 R >>
> stream

> H?b``àb``êc...


> endstream
> endobj
>
> Here are the errors I'm receiving:
>
> java.util.zip.ZipException: incomplete dynamic bit lengths tree
> java.util.zip.ZipException: invalid distance code
> java.util.zip.ZipException: invalid bit length repeat
>
> Anyone know why I might be getting errors like these errors? Any help
> decoding flate streams in Java would be greately appreciated.
>
> Thanks,
> Cameron

You can use the FlateDecoder built into Adobe's discontinued bean....

MArk

na...@volantia.com

unread,
May 14, 2002, 5:28:31 AM5/14/02
to
You should use InflaterInputStream.
However, take out the stream part only, not object part.
Don't forget to take out the line end (Carriage return-0x0d and line
feed-0x0a) after 'stream'.

nate

ma...@idrsolutions.com wrote in message news:<abeden$t7g$1...@knossos.btinternet.com>...


> Cameron Taggart wrote:
>
> > I am trying to decompress (inflate) a flate compressed stream using the
> > Java
> > 2 SDK SE v1.4. Although flate compression is built in to Java, I am
> > having
> > some major issues. I'm using the the following couple of classes:
> >
> > ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); // in
> > InflaterInputStream iis = new InflaterInputStream( bais ); // wrap in
> >
> > Should I be using InflaterInputStream or ZipInputStream? Are their
> > setting
> > in the stream dictionary that are needed for decoding? Like, what does
> > the
> > "/S 36" mean in the following object? I've been looking in the PDF
> > Reference Guide, but I haven't had any luck.
> >
> > 14 0 obj
> > << /S 36 /Filter /FlateDecode /Length 15 0 R >>
> > stream

> > H?b``ŕb``ęc...

ma...@idrsolutions.com

unread,
May 14, 2002, 7:38:19 AM5/14/02
to
na...@volantia.com wrote:

>> > H?b``àb``êc...


>> > endstream
>> > endobj
>> >
>> > Here are the errors I'm receiving:
>> >
>> > java.util.zip.ZipException: incomplete dynamic bit lengths tree
>> > java.util.zip.ZipException: invalid distance code
>> > java.util.zip.ZipException: invalid bit length repeat
>> >
>> > Anyone know why I might be getting errors like these errors? Any help
>> > decoding flate streams in Java would be greately appreciated.
>> >
>> > Thanks,
>> > Cameron
>>
>> You can use the FlateDecoder built into Adobe's discontinued bean....
>>
>> MArk

Here's my code.

MArk

//////////////////////////////////////////////////
/**
* flate decode using adobes class
*/
private byte[] flateDecode(byte[] data,String filter_list,String
decode_params){


Object key;
Object value;
byte[] processed_data=null;

Integer Predictor=new Integer(1);
Integer Colors=new Integer(1);
Integer BitsPerComponent=new Integer(8);
Integer Columns=new Integer(1);
Integer EarlyChange=new Integer(1);

try{

//put params in object
FilterParams params=new FilterParams();

//reset vales
StringTokenizer values=new StringTokenizer(decode_params,"< >");
while(values.hasMoreTokens()){
key=values.nextToken();
String test=key.toString();

if(test.startsWith("/")){
value=values.nextElement();

//set values
if(test.equals("/Predictor"))
Predictor=new Integer(value.toString());
if(test.equals("/Colors"))
Colors=new Integer(value.toString());
if(test.equals("/BitsPerComponent"))
BitsPerComponent=new Integer(value.toString());
if(test.equals("/Columns"))
Columns=new Integer(value.toString());
if(test.equals("/EarlyChange"))
EarlyChange=new Integer(value.toString());
}
}

params.put("Predictor",Predictor);
params.put("Colors",Colors);
params.put("BitsPerComponent",BitsPerComponent);
params.put("Columns",Columns);
params.put("EarlyChange",EarlyChange);

FlateInputStream flate_filter=
new FlateInputStream(new BufferedInputStream(new
ByteArrayInputStream(data)),params);

ByteArrayOutputStream out=new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int bytes_read;

//loop to write the data
while((bytes_read =flate_filter.read(buffer))!=-1){
out.write(buffer,0,bytes_read);
}

//close and get the data
flate_filter.close();
out.close();

processed_data=out.toByteArray();

}catch(Exception e){
LogWriter.writeLog("Exception "+e+" accessing flate filter");
}

return processed_data;
}

Cameron Taggart

unread,
May 18, 2002, 6:28:41 PM5/18/02
to
Where do I find FlateInputStream? I assume it is in Adobe's discontinued
bean, but where do I get that?

Cameron

<ma...@idrsolutions.com> wrote in message
news:abqsv9$mh9$1...@helle.btinternet.com...

> >> > H?b``ŕb``ęc...

0 new messages