Article View: borland.public.jbuilder.java.api
Article #2733packing and unpacking with zlib
From: Mike Evteev
Date: Wed, 03 May 2000 00:00
Date: Wed, 03 May 2000 00:00
68 lines
2411 bytes
2411 bytes
Hello All!
I must rewrite code wich pack/unpack data with zlib (Delphi version);
I spend a lot of time with no results, becouse it my firs project on java
My code is here.
import java.lang.String;
import java.io.*;
import java.util.zip.*;
public class Compressor {
public static void main (String args[]){
System.out.println(Inflate(Deflate(args[0])));
};
public static String Deflate(String InBuffer) {
ByteArrayOutputStream FOut = new ByteArrayOutputStream(InBuffer.length());
try {
DeflaterOutputStream myStream = new DeflaterOutputStream(FOut, new
Deflater(Deflater.BEST_COMPRESSION, true));
myStream.write(InBuffer.getBytes(), 0, InBuffer.length());
myStream.finish();
myStream.close();
FOut.close();
}
catch (java.io.IOException e){
System.out.println(e);
}
return FOut.toString();
} // Deflate
public static String Inflate(String InBuffer) {
StringBuffer Res = new StringBuffer(0);
byte[] Tmp = new byte[1024];
ByteArrayInputStream FIn = new ByteArrayInputStream(InBuffer.getBytes());
try {
InflaterInputStream myStream = new InflaterInputStream(FIn, new
Inflater(true), InBuffer.length() + 1);
while (myStream.read(Tmp, 0, 1024) != -1) {
Res = Res.append(Tmp.toString());
}
}
catch (java.io.IOException e){
System.out.println(e);
}
return Res.toString();
} // Inflate
} file://Compressor
If I use DeflaterOutputStream myStream = new DeflaterOutputStream(FOut, new
Deflater(Deflater.BEST_COMPRESSION, false)) on packing and
InflaterInputStream myStream = new InflaterInputStream(FIn, new
Inflater(true), InBuffer.length() + 1);
on unpacking I get -
java.util.zip.ZipException: invalid stored block lengths
If I use true and true I get
java.io.EOFException: Unexpected end of ZLIB input stream
Help me please! It's wery urgent!
Mike
Technical Details
Message-ID:
<8eqafu$sps8@bornews.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,c79989b112f3b01f,start X-Google-Attributes: gid1089d0,public From: "Mike Evteev" <mevteev@retailpro.com> Subject: packing and unpacking with zlib Date: 2000/05/03 Message-ID: <8eqafu$sps8@bornews.borland.com> X-Deja-AN: 618909899 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.api