parquet-hadoop/src/main/java/org/apache/parquet/hadoop/codec/SnappyDecompressor.java
@Override
  public synchronized int decompress(byte[] buffer, int off, int len) throws IOException {
    SnappyUtil.validateBuffer(buffer, off, len);
	if (inputBuffer.position() == 0 && !outputBuffer.hasRemaining()) {
      return 0;
    }
    
    if (!outputBuffer.hasRemaining()) {
      inputBuffer.rewind();
      Preconditions.checkArgument(inputBuffer.position() == 0, "Invalid position of 0.");
      Preconditions.checkArgument(outputBuffer.position() == 0, "Invalid position of 0.");
      // There is compressed input, decompress it now.
      int decompressedSize = Snappy.uncompressedLength(inputBuffer);
      if (decompressedSize > outputBuffer.capacity()) {
        ByteBuffer oldBuffer = outputBuffer;
        outputBuffer = ByteBuffer.allocateDirect(decompressedSize);
        CleanUtil.clean(oldBuffer);
      }

      // Reset the previous outputBuffer (i.e. set position to 0)
      outputBuffer.clear();
      int size = Snappy.uncompress(inputBuffer, outputBuffer);
      outputBuffer.limit(size);
      // We've decompressed the entire input, reset the input now
      inputBuffer.clear();
      inputBuffer.limit(0);
      finished = true;
    }

    // Return compressed output up to 'len'
    int numBytes = Math.min(len, outputBuffer.remaining());
    outputBuffer.get(buffer, off, numBytes);
    return numBytes;	    
  }
@Override
  public synchronized int decompress(byte[] buffer, int off, int len) throws IOException {
    SnappyUtil.validateBuffer(buffer, off, len);
	if (inputBuffer.position() == 0 && !outputBuffer.hasRemaining()) {
      return 0;
    }
    
    if (!outputBuffer.hasRemaining()) {
      inputBuffer.rewind();
      Preconditions.checkArgument(inputBuffer.position() == 0, "Invalid position of 0.");
      Preconditions.checkArgument(outputBuffer.position() == 0, "Invalid position of 0.");
      // There is compressed input, decompress it now.
      int decompressedSize = Snappy.uncompressedLength(inputBuffer);
      if (decompressedSize > outputBuffer.capacity()) {
        ByteBuffer oldBuffer = outputBuffer;
        outputBuffer = ByteBuffer.allocateDirect(decompressedSize);
        CleanUtil.clean(oldBuffer);
      }

      // Reset the previous outputBuffer (i.e. set position to 0)
      outputBuffer.clear();
      int size = Snappy.uncompress(inputBuffer, outputBuffer);
      outputBuffer.limit(size);
      // We've decompressed the entire input, reset the input now
      inputBuffer.clear();
      inputBuffer.limit(0);
      finished = true;
    }

    // Return compressed output up to 'len'
    int numBytes = Math.min(len, outputBuffer.remaining());
    outputBuffer.get(buffer, off, numBytes);
    return numBytes;	    
  }
@ Override public synchronized int decompress ( byte [ ] buffer , int off , int len ) throws IOException { SnappyUtil . validateBuffer ( buffer , off , len ) ; if ( inputBuffer . position ( ) == 0 && ! outputBuffer . hasRemaining ( ) ) { return 0 ; } if ( ! outputBuffer . hasRemaining ( ) ) { inputBuffer . rewind ( ) ; Preconditions . checkArgument ( inputBuffer . position ( ) == 0 , "Invalid position of 0." ) ; Preconditions . checkArgument ( outputBuffer . position ( ) == 0 , "Invalid position of 0." ) ; // There is compressed input, decompress it now. int decompressedSize = Snappy . uncompressedLength ( inputBuffer ) ; if ( decompressedSize > outputBuffer . capacity ( ) ) { ByteBuffer oldBuffer = outputBuffer ; outputBuffer = ByteBuffer . allocateDirect ( decompressedSize ) ; CleanUtil . clean ( oldBuffer ) ; } // Reset the previous outputBuffer (i.e. set position to 0) outputBuffer . clear ( ) ; int size = Snappy . uncompress ( inputBuffer , outputBuffer ) ; outputBuffer . limit ( size ) ; // We've decompressed the entire input, reset the input now inputBuffer . clear ( ) ; inputBuffer . limit ( 0 ) ; finished = true ; } // Return compressed output up to 'len' int numBytes = Math . min ( len , outputBuffer . remaining ( ) ) ; outputBuffer . get ( buffer , off , numBytes ) ; return numBytes ; }
Fills specified buffer with uncompressed data. Returns actual number
of bytes of uncompressed data. A return value of 0 indicates that
{@link #needsInput()} should be called in order to determine if more
input data is required.

@param buffer   Buffer for the compressed data
@param off Start offset of the data
@param len Size of the buffer
@return The actual number of bytes of uncompressed data.
@throws IOException if reading or decompression fails
Fills specified buffer with uncompressed data . Returns actual number of bytes of uncompressed data . A return value of 0 indicates that { @link #needsInput () } should be called in order to determine if more input data is required .