class SnappyBlockCompressor {

  public Bytes uncompress(final Bytes compressedData, final LengthBounds lengthBounds)
      throws DecodingException {

    try {
      final int actualLength = Snappy.uncompressedLength(compressedData.toArrayUnsafe());
      if (!lengthBounds.isWithinBounds(actualLength)) {
        throw new DecodingException(
            String.format(
                "Uncompressed length %d is not within expected bounds %d to %d",
                actualLength, lengthBounds.getMin(), lengthBounds.getMax()));
      }
      return Bytes.wrap(Snappy.uncompress(compressedData.toArrayUnsafe()));
    } catch (IOException e) {
      throw new DecodingException("Failed to uncompress", e);
    }
  }

}