@Test public void uncompress_randomData() { final Bytes data = Bytes.fromHexString("0x0102"); assertThatThrownBy(() -> compressor.uncompress(data, new LengthBounds(0, 1000))) .isInstanceOf(DecodingException.class); }
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); } }
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); } } }
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); } }  }
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); } }  Bytes uncompress(final Bytes compressedData, final LengthBounds lengthBounds); Bytes compress(final Bytes data); }
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); } }  Bytes uncompress(final Bytes compressedData, final LengthBounds lengthBounds); Bytes compress(final Bytes data);  }