org.xerial.snappy
Class SnappyOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.xerial.snappy.SnappyOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class SnappyOutputStream
extends OutputStream

This class implements a stream filter for writing compressed data using Snappy. The input data is blocked into 32kb size (in default), and each block is compressed and then passed to the given OutputStream. The output data format is:

  1. snappy codec header defined in SnappyCodec
  2. a pair of (compressed data size, compressed data...)
  3. a pair of (compressed data size, compressed data...)
  4. ...
Note that the compressed data created by SnappyOutputStream cannot be uncompressed by Snappy.uncompress(byte[]) since the output formats of Snappy.compress(byte[]) and SnappyOutputStream are different. Use SnappyInputStream for uncompress the data generated by SnappyOutputStream.

Author:
leo

Field Summary
protected  byte[] compressed
           
protected  OutputStream out
           
protected  byte[] uncompressed
           
 
Constructor Summary
SnappyOutputStream(OutputStream out)
           
SnappyOutputStream(OutputStream out, int blockSize)
           
 
Method Summary
 void close()
           
protected  void dump()
           
 void flush()
           
 void rawWrite(Object array, int byteOffset, int byteLength)
          Compress the raw byte array data.
 void write(byte[] b, int off, int len)
           
 void write(float[] f)
           
 void write(float[] f, int off, int len)
           
 void write(int b)
           
 void write(long[] d)
           
 void write(long[] d, int off, int len)
          Compress the input long array data
protected  void writeHeader()
           
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected final OutputStream out

uncompressed

protected byte[] uncompressed

compressed

protected byte[] compressed
Constructor Detail

SnappyOutputStream

public SnappyOutputStream(OutputStream out)
                   throws IOException
Throws:
IOException

SnappyOutputStream

public SnappyOutputStream(OutputStream out,
                          int blockSize)
                   throws IOException
Throws:
IOException
Method Detail

writeHeader

protected void writeHeader()
                    throws IOException
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(long[] d,
                  int off,
                  int len)
           throws IOException
Compress the input long array data

Parameters:
d - input array
off - offset in the array
len - the number of elements in the array to copy
Throws:
IOException

write

public void write(float[] f,
                  int off,
                  int len)
           throws IOException
Throws:
IOException

write

public void write(long[] d)
           throws IOException
Throws:
IOException

write

public void write(float[] f)
           throws IOException
Throws:
IOException

rawWrite

public void rawWrite(Object array,
                     int byteOffset,
                     int byteLength)
              throws IOException
Compress the raw byte array data.

Parameters:
array - array data of any type (e.g., byte[], float[], long[], ...)
byteOffset -
byteLength -
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

dump

protected void dump()
             throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException


Copyright © 2011. All Rights Reserved.