title: Problems with using ZipOutputStream and ObjectOutputStream
body: <p>Right now, I am using the pure ObjectOutputStream to pass objects over a socket. Sometimes, these objects can become very big and cause OutOfMemory issues. I believe the objects can get compressed though, as there is much repeated data inside of them, usually. So, I attempted to wrap my socket with:</p>
  
  <pre><code>  static class CompressedSocket extends Socket {
      private ZipInputStream zis;
      private ZipOutputStream zos;
  
      CompressedSocket(InetAddress inetAddress, int port) throws IOException {
        super(inetAddress, port);
        zis = new ZipInputStream(super.getInputStream());
        zos = new ZipOutputStream(super.getOutputStream());
      }
  
      @Override
      public ZipInputStream getInputStream() throws IOException {
        return zis;
      }
  
      @Override
      public ZipOutputStream getOutputStream() throws IOException {
        return zos;
      }
    }
  </code></pre>
  
  <p>However, in the part of my class where I wrap the sockets in ObjectInput/OutputStreams, I get the following error. Here are the relevant lines:</p>
  
  <pre><code>ObjectInputStream in = null;
  ObjectOutputStream out = null;
  Object serverResponse = null;
  CompressedSocket socket = null;
  try {
      socket = new CompressedSocket(InetAddress.getByName(ipAddress), SixDofServer.PORT);
  } catch ( ... ) { ... }
  
  try {
      out = new ObjectOutputStream(socket.getOutputStream());
      in = new ObjectInputStream(socket.getInputStream());
  } catch ( ... ) { ... }
  </code></pre>
  
  <p>The error that comes out is:</p>
  
  <pre><code>java.util.zip.ZipException: no current ZIP entry
      at java.util.zip.ZipOutputStream.write(Unknown Source)
      at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
      at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
      at java.io.ObjectOutputStream.&lt;init&gt;(Unknown Source)
  </code></pre>
  
  <p>So, clearly I am not doing something right. But I am finding Google and other guides to be of little help.</p>
  
  <p>Now, if it turns out that wrapping a socket stream is just not an option, for whatever reason, I would still like to compress that object I was referring to in the beginning. Any suggestions on how to compress that object locally, then send it over the regular ObjectOutputStream?</p>