I want to unzip a file over a socket connection, while it works with small chunks of data, i get a "java.util.zip.DataFormatException: incorrect data check" when retrieving larger files.
client code:
GeSHi (java):
byte[] bytesOut = baos.toByteArray();
compressor.
setLevel(Deflater.
BEST_SPEED);
compressor.setInput(bytesOut);
compressor.finish();
byte[] buf = new byte[100];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
try {
bos.close();
e.printStackTrace();
}
byte[] compressedData = bos.toByteArray();
System.
out.
println("COMPRESSED " + compressedData.
length);
out.write(compressedData);
out.close();
skt.close();
Created by GeSHI 1.0.7.20
server code
GeSHi (java):
byte[] buffer = new byte[100];
int bytesRead = -1;
while((bytesRead = in.read(buffer)) > -1) {
out.write(buffer, 0, bytesRead);
}
in.close();
byte[] imageBytes = out.toByteArray();
decompressor.setInput(imageBytes);
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(imageBytes);
bos.write(imageBytes, 0, count);
e.printStackTrace();
}
}
try {
decompressor.end();
bos.close();
e.printStackTrace();
}
Created by GeSHI 1.0.7.20
Is there some limitation when reading compressed data trough the net or is my code not efficient enough to do so? I haven't done similiar things before so i might have missed something important.
Thanks