use of java.util.zip.GZIPOutputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testSmallBlockWithGZIPChunkedAtBegin.
@Test
public void testSmallBlockWithGZIPChunkedAtBegin() throws Exception {
String data = "0";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
// The header is 10 bytes, chunk at 11 bytes
byte[] bytes1 = new byte[11];
System.arraycopy(bytes, 0, bytes1, 0, bytes1.length);
byte[] bytes2 = new byte[bytes.length - bytes1.length];
System.arraycopy(bytes, bytes1.length, bytes2, 0, bytes2.length);
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
use of java.util.zip.GZIPOutputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testSmallBlockWithGZIPTrailerChunked.
@Test
public void testSmallBlockWithGZIPTrailerChunked() throws Exception {
String data = "0";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
// The trailer is 4+4 bytes, chunk the last 3 bytes
byte[] bytes1 = new byte[bytes.length - 3];
System.arraycopy(bytes, 0, bytes1, 0, bytes1.length);
byte[] bytes2 = new byte[bytes.length - bytes1.length];
System.arraycopy(bytes, bytes1.length, bytes2, 0, bytes2.length);
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
use of java.util.zip.GZIPOutputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testBigBlockOneByteAtATime.
@Test
public void testBigBlockOneByteAtATime() throws Exception {
String data = "0123456789ABCDEF";
for (int i = 0; i < 10; ++i) data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
String result = "";
GZIPContentDecoder decoder = new GZIPContentDecoder(64);
ByteBuffer buffer = ByteBuffer.wrap(bytes);
while (buffer.hasRemaining()) {
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[] { buffer.get() }));
if (decoded.hasRemaining())
result += StandardCharsets.UTF_8.decode(decoded).toString();
}
assertEquals(data, result);
assertTrue(decoder.isFinished());
}
use of java.util.zip.GZIPOutputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testStreamBigBlockOneByteAtATime.
@Test
public void testStreamBigBlockOneByteAtATime() throws Exception {
String data = "0123456789ABCDEF";
for (int i = 0; i < 10; ++i) data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
baos = new ByteArrayOutputStream();
GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(bytes), 1);
int read;
while ((read = input.read()) >= 0) baos.write(read);
assertEquals(data, new String(baos.toByteArray(), StandardCharsets.UTF_8));
}
use of java.util.zip.GZIPOutputStream in project jetty.project by eclipse.
the class GZIPContentDecoderTest method testNoBlocks.
@Test
public void testNoBlocks() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
output.close();
byte[] bytes = baos.toByteArray();
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes));
assertEquals(0, decoded.remaining());
}
Aggregations