@Override
    public void writeObject(ByteBuffer buffer, Object object) throws IOException {
        if (!(object instanceof GZIPCompressedMessage)) return;
        Message message = ((GZIPCompressedMessage)object).getMessage();

        ByteBuffer tempBuffer = ByteBuffer.allocate(512000);
        Serializer.writeClassAndObject(tempBuffer, message);

        ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
        GZIPOutputStream gzipOutput = new GZIPOutputStream(byteArrayOutput);

        tempBuffer.flip();
        gzipOutput.write(tempBuffer.array(), 0, tempBuffer.limit());
        gzipOutput.flush();
        gzipOutput.finish();
        gzipOutput.close();

        buffer.put(byteArrayOutput.toByteArray());
    }
Serializes GZIP messages.

@author Lars Wesselius
jme3-networking/src/main/java/com/jme3/network/serializing/serializers/GZIPSerializer.java