@Test public void testGunzip_Large() throws IOException { byte[] input1 = readResource("plain.gz"); byte[] output1 = GzipDecryptor.gunzip(input1); byte[] expectedOutput1 = readResource("plain"); assertArrayEquals(expectedOutput1, output1); }
static byte[] gunzip(byte[] input) throws IOException { ByteArrayInputStream zipBytes = new ByteArrayInputStream(input); GZIPInputStream in = new GZIPInputStream(zipBytes); byte[] out = new byte[input.length * 2]; int totalRead = 0; int read; int resizeBy = input.length; while ((read = in.read(out, totalRead, out.length - totalRead - 1)) > 0) { totalRead += read; if (totalRead + 1 == out.length) { out = Arrays.copyOf(out, out.length + resizeBy); } } if (totalRead < out.length) { out = Arrays.copyOf(out, totalRead); } return out; }
GzipDecryptor implements BytesDecryptor { static byte[] gunzip(byte[] input) throws IOException { ByteArrayInputStream zipBytes = new ByteArrayInputStream(input); GZIPInputStream in = new GZIPInputStream(zipBytes); byte[] out = new byte[input.length * 2]; int totalRead = 0; int read; int resizeBy = input.length; while ((read = in.read(out, totalRead, out.length - totalRead - 1)) > 0) { totalRead += read; if (totalRead + 1 == out.length) { out = Arrays.copyOf(out, out.length + resizeBy); } } if (totalRead < out.length) { out = Arrays.copyOf(out, totalRead); } return out; } }
GzipDecryptor implements BytesDecryptor { static byte[] gunzip(byte[] input) throws IOException { ByteArrayInputStream zipBytes = new ByteArrayInputStream(input); GZIPInputStream in = new GZIPInputStream(zipBytes); byte[] out = new byte[input.length * 2]; int totalRead = 0; int read; int resizeBy = input.length; while ((read = in.read(out, totalRead, out.length - totalRead - 1)) > 0) { totalRead += read; if (totalRead + 1 == out.length) { out = Arrays.copyOf(out, out.length + resizeBy); } } if (totalRead < out.length) { out = Arrays.copyOf(out, totalRead); } return out; } GzipDecryptor(BytesDecryptor delegate); }
GzipDecryptor implements BytesDecryptor { static byte[] gunzip(byte[] input) throws IOException { ByteArrayInputStream zipBytes = new ByteArrayInputStream(input); GZIPInputStream in = new GZIPInputStream(zipBytes); byte[] out = new byte[input.length * 2]; int totalRead = 0; int read; int resizeBy = input.length; while ((read = in.read(out, totalRead, out.length - totalRead - 1)) > 0) { totalRead += read; if (totalRead + 1 == out.length) { out = Arrays.copyOf(out, out.length + resizeBy); } } if (totalRead < out.length) { out = Arrays.copyOf(out, totalRead); } return out; } GzipDecryptor(BytesDecryptor delegate); @Override byte[] decrypt(byte[] input, int inputOffset, Key key); }
GzipDecryptor implements BytesDecryptor { static byte[] gunzip(byte[] input) throws IOException { ByteArrayInputStream zipBytes = new ByteArrayInputStream(input); GZIPInputStream in = new GZIPInputStream(zipBytes); byte[] out = new byte[input.length * 2]; int totalRead = 0; int read; int resizeBy = input.length; while ((read = in.read(out, totalRead, out.length - totalRead - 1)) > 0) { totalRead += read; if (totalRead + 1 == out.length) { out = Arrays.copyOf(out, out.length + resizeBy); } } if (totalRead < out.length) { out = Arrays.copyOf(out, totalRead); } return out; } GzipDecryptor(BytesDecryptor delegate); @Override byte[] decrypt(byte[] input, int inputOffset, Key key);  }