title: TCP Socket send data in GZIP Compression format
body: <p>I am sending <code>MultiPart</code> content to my remote server to store it in filesystem. For this I am using Java <code>TCP/IP</code> protocol. For avoiding network bandwidth and TCP Input / Output buffer memory , I am sending the data in <code>GZIP</code> compressed format.  But , I cannot decompress the data received from the client. I got <strong><code>Unexpected end of ZLIB input stream</code></strong> Exception. Its due to the server is receiving data in <strong><code>chunks</code></strong>.</p>
  
  <p><strong>Java Code</strong></p>
  
  <p><strong>Client</strong> </p>
  
  <pre><code>  OutputStream out = new GZIPOutputStream(sock.getOutputStream());
    byte[] dataToSend = FileUtil.readFile(new File("/Users/bharathi/Downloads/programming_in_go.pdf"));
    out.write(dataToSend);
  </code></pre>
  
  <p><strong>Server</strong></p>
  
  <pre><code>    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;
      }
  </code></pre>
  
  <p>Is there any solution to send the data in GZIP compressed format in Socket? </p>