private static byte[] uncompress(byte[] compressed) throws IOException { return toByteArray(new SnappyFramedInputStream(new ByteArrayInputStream(compressed))); }
@Test public void testInvalidChecksumIgnoredWhenVerificationDisabled() throws Exception { // flag = 0, size = 4, crc32c = 0, block data = [a] byte[] block = {1, 5, 0, 0, 0, 0, 0, 0, 'a'}; ByteArrayInputStream inputData = new ByteArrayInputStream(blockToStream(block)); assertEquals(toByteArray(new SnappyFramedInputStream(inputData, false)), new byte[] {'a'}); }
@Test public void testCloseIsIdempotent() throws Exception { byte[] random = getRandom(0.5, 500000); ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStream snappyOut = new SnappyFramedOutputStream(out); snappyOut.write(random); snappyOut.close(); snappyOut.close(); byte[] compressed = out.toByteArray(); InputStream snappyIn = new SnappyFramedInputStream(new ByteArrayInputStream(compressed), true); byte[] uncompressed = toByteArray(snappyIn); assertEquals(uncompressed, random); snappyIn.close(); snappyIn.close(); }
snappyInputStream, encoding)); } else if ("framing-snappy".equalsIgnoreCase(compress)) { InputStream snappyInputStream = new SnappyFramedInputStream( inputStream); reader = new BufferedReader(new InputStreamReader(
@Test public void testLargeWrites() throws Exception { byte[] random = getRandom(0.5, 500000); java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); OutputStream snappyOut = new SnappyFramedOutputStream(out); // partially fill buffer int small = 1000; snappyOut.write(random, 0, small); // write more than the buffer size snappyOut.write(random, small, random.length - small); // get compressed data snappyOut.close(); byte[] compressed = out.toByteArray(); assertTrue(compressed.length < random.length); // decompress byte[] uncompressed = uncompress(compressed); assertEquals(uncompressed, random); // decompress byte at a time InputStream in = new SnappyFramedInputStream(new ByteArrayInputStream(compressed), true); int i = 0; int c; while ((c = in.read()) != -1) { uncompressed[i++] = (byte) c; } assertEquals(i, random.length); assertEquals(uncompressed, random); }