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 (8 bytes)
  2. compressed block 1 : a pair of (compressed data size [4 byte integer. Big-endian], compressed data...)
  3. compressed block 2
  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

Constructor Summary
SnappyOutputStream(OutputStream out)
           
SnappyOutputStream(OutputStream out, int blockSize)
           
 
Method Summary
 void close()
          close the stream
 void flush()
           
 void rawWrite(Object array, int byteOffset, int byteLength)
          Compress the raw byte array data.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(double[] f)
          Compress the input array data
 void write(double[] f, int off, int len)
          Compress the input double array data
 void write(float[] f)
          Compress the input array data
 void write(float[] f, int off, int len)
          Compress the input float array data
 void write(int b)
          Writes the specified byte to this output stream.
 void write(int[] f)
          Compress the input array data
 void write(int[] f, int off, int len)
          Compress the input int array data
 void write(long[] d)
          Compress the input array data
 void write(long[] d, int off, int len)
          Compress the input long array data
 void write(short[] f)
          Compress the input array data
 void write(short[] f, int off, int len)
          Compress the input short array data
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnappyOutputStream

public SnappyOutputStream(OutputStream out)
                   throws IOException
Throws:
IOException

SnappyOutputStream

public SnappyOutputStream(OutputStream out,
                          int blockSize)
                   throws IOException
Parameters:
out -
blockSize - byte size of the internal buffer size
Throws:
IOException
Method Detail

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

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(double[] f,
                  int off,
                  int len)
           throws IOException
Compress the input double array data

Parameters:
f - 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
Compress the input float array data

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

write

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

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

write

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

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

write

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

Parameters:
d -
Throws:
IOException

write

public void write(double[] f)
           throws IOException
Compress the input array data

Parameters:
f -
Throws:
IOException

write

public void write(float[] f)
           throws IOException
Compress the input array data

Parameters:
f -
Throws:
IOException

write

public void write(int[] f)
           throws IOException
Compress the input array data

Parameters:
f -
Throws:
IOException

write

public void write(short[] f)
           throws IOException
Compress the input array data

Parameters:
f -
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
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

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

close

public void close()
           throws IOException
close the stream

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException


Copyright © 2011 xerial.org. All Rights Reserved.