Overview | Package | Class | Tree | Deprecated | Index | Help
| Protege 3.5 alpha
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.stanford.smi.protege.server.socket.deflate
Class PacketHeader

    java.lang.Object
      edu.stanford.smi.protege.server.socket.deflate.PacketHeader

    public class PacketHeader

extends Object

This code is based on the ideas presented in `http://javatechniques.com/blog/compressing-data-sent-over-a-socket/` by Philip Isenhour. I am very grateful for the approach that he presented. The key idea is to avoid using the GZip and the Zip streams and to use the Deflater and Inflater methods directly. In addition, Philip Isenhour essentially defines a packet type that has a header indicating the size and compressed size of the packet contents. I took these two key ideas and wrote the following code by scratch without reference to Philip Isenhour's documents. I think that some version of Philip Isenhour's ideas should find their way into the core java libraries because otherwise people will continue struggling with this problem.

I have tried several other approaches to a compressing input and compressing output stream. The first approach was to base the input and output streams on the GZip input and output stream. There are web pages on the internet that suggest that calling the GZipOutputStream's finish() method during the flush() will work. I had trouble with this approach when a write occurs on the stream after the flush() (which calls finish()). I would get exceptions indicating that the GZip Output stream was finished and therefore unwriteable.

I then tried to use the ZIPInput/OutputStreams. I would flush data by creating a ZipEntry and writing it out. This approach actually worked very well. But it had a mysterious bug where some data was either not fully written out or not read. In the rmi context things would hang. This bug was relatively rare and only happened on certain machines. I never found out what the problem was.

The beauty of Philip Isenhour's approach is that the developer can completely control how data is flushed and fully written out. The developer can also ensure that on the read method all the data is fully read. So there should not be any more rmi hangs. The only issue is whether the deflate/inflate logic is correct. This is pretty thoroughly tested in our server-client testing (though there are *always* bugs hidden somewhere).

Author:
  tredmond

Field Summary
`static byte[]` | `ALIGNMENT`

Constructor Summary
`PacketHeader(int size, int compressedSize)`

Method Summary
`int` | `getCompressedSize()`
`int` | `getSize()`
`static PacketHeader` | `read(InputStream is)`
`void` | `write(OutputStream os)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### ALIGNMENT

    public static byte[] ALIGNMENT

Constructor Detail

### PacketHeader

    public PacketHeader(int size,
                        int compressedSize)

Method Detail

### read

    public static PacketHeader read(InputStream is)
                             throws IOException

  Throws:
    `IOException`

### write

    public void write(OutputStream os)
               throws IOException

  Throws:
    `IOException`

### getSize

    public int getSize()

### getCompressedSize

    public int getCompressedSize()

Overview | Package | Class | Tree | Deprecated | Index | Help
| Protege 3.5 alpha
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug report or feature request
Protégé is a trademark of Stanford University.
Copyright (c) 1998-2012 Stanford University.