Class SnappyOutputStream

All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

@Deprecated public class SnappyOutputStream extends AbstractSnappyOutputStream
Deprecated.
Use SnappyFramedOutputStream which implements the standard x-snappy-framed specification.
This class implements an output stream for writing Snappy compressed data. The output format is the stream header "snappy\0" followed by one or more compressed blocks of data, each of which is preceded by a seven byte header.

The first byte of the header is a flag indicating if the block is compressed or not. A value of 0x00 means uncompressed, and 0x01 means compressed.

The second and third bytes are the size of the block in the stream as a big endian number. This value is never zero as empty blocks are never written. The maximum allowed length is 32k (1 invalid input: '<'invalid input: '<' 15).

The remaining four byes are crc32c checksum of the user input data masked with the following function: ((crc >>> 15) | (crc << 17)) + 0xa282ead8

An uncompressed block is simply copied from the input, thus guaranteeing that the output is never larger than the input (not including the header).

NOTE:This data produced by this class is not compatible with the x-snappy-framed specification. It can only be read by SnappyInputStream.

  • Field Details

    • STREAM_HEADER

      static final byte[] STREAM_HEADER
      Deprecated.
    • MAX_BLOCK_SIZE

      static final int MAX_BLOCK_SIZE
      Deprecated.
      See Also:
    • MIN_COMPRESSION_RATIO

      public static final double MIN_COMPRESSION_RATIO
      Deprecated.
      Write out the uncompressed content if the compression ratio (compressed length / raw length) exceeds this value.
      See Also:
    • calculateChecksum

      private final boolean calculateChecksum
      Deprecated.
  • Constructor Details

    • SnappyOutputStream

      public SnappyOutputStream(OutputStream out) throws IOException
      Deprecated.
      Creates a Snappy output stream to write data to the specified underlying output stream.
      Parameters:
      out - the underlying output stream
      Throws:
      IOException
    • SnappyOutputStream

      private SnappyOutputStream(OutputStream out, boolean calculateChecksum) throws IOException
      Deprecated.
      Throws:
      IOException
  • Method Details

    • newChecksumFreeBenchmarkOutputStream

      public static SnappyOutputStream newChecksumFreeBenchmarkOutputStream(OutputStream out) throws IOException
      Deprecated.
      Creates a Snappy output stream with block checksums disabled. This is only useful for apples-to-apples benchmarks with other compressors that do not perform block checksums.
      Parameters:
      out - the underlying output stream
      Throws:
      IOException
    • writeHeader

      protected void writeHeader(OutputStream out) throws IOException
      Deprecated.
      Description copied from class: AbstractSnappyOutputStream
      Writes the implementation specific header or "marker bytes" to out.
      Specified by:
      writeHeader in class AbstractSnappyOutputStream
      Parameters:
      out - The underlying OutputStream.
      Throws:
      IOException
    • calculateCRC32C

      protected int calculateCRC32C(byte[] data, int offset, int length)
      Deprecated.
      Description copied from class: AbstractSnappyOutputStream
      Calculates a CRC32C checksum over the data.

      This can be overridden to provider alternative implementations (such as returning 0 if checksums are not desired).

      Overrides:
      calculateCRC32C in class AbstractSnappyOutputStream
      Returns:
      The CRC32 checksum.
    • writeBlock

      protected void writeBlock(OutputStream out, byte[] data, int offset, int length, boolean compressed, int crc32c) throws IOException
      Deprecated.
      Description copied from class: AbstractSnappyOutputStream
      Write a frame (block) to out.
      Specified by:
      writeBlock in class AbstractSnappyOutputStream
      Parameters:
      out - The OutputStream to write to.
      data - The data to write.
      offset - The offset in data to start at.
      length - The length of data to use.
      compressed - Indicates if data is the compressed or raw content. This is based on whether the compression ratio desired is reached.
      crc32c - The calculated checksum.
      Throws:
      IOException