I am sending MultiPart
content to my remote server to store it in filesystem. For this I am using Java TCP/IP
protocol. For avoiding network bandwidth and TCP Input / Output buffer memory , I am sending the data in GZIP
compressed format. But , I cannot decompress the data received from the client. I got Unexpected end of ZLIB input stream
Exception. Its due to the server is receiving data in chunks
.
Java Code
Client
OutputStream out = new GZIPOutputStream(sock.getOutputStream());
byte[] dataToSend = FileUtil.readFile(new File("/Users/bharathi/Downloads/programming_in_go.pdf"));
out.write(dataToSend);
Server
out = new FileOutputStream("/Users/bharathi/Documents/request_trace.log");
InputStream in = new GZIPInputStream(clntSocket.getInputStream());
int totalBytesRead = 0;
int bytesRead;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = in.read(buffer)) != -1)
{
out.write(buffer , 0 , bytesRead);
totalBytesRead += bytesRead;
}
Is there any solution to send the data in GZIP compressed format in Socket?