use of java.util.zip.Deflater in project hive by apache.
the class InputJobInfo method writeObject.
/**
* Serialize this object, compressing the partitions which can exceed the
* allowed jobConf size.
* @see <a href="https://issues.apache.org/jira/browse/HCATALOG-453">HCATALOG-453</a>
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
Deflater def = new Deflater(Deflater.BEST_COMPRESSION);
ObjectOutputStream partInfoWriter = new ObjectOutputStream(new DeflaterOutputStream(oos, def));
partInfoWriter.writeObject(partitions);
partInfoWriter.close();
}
use of java.util.zip.Deflater in project dropwizard by dropwizard.
the class BiDiGzipHandlerTest method testDecompressDeflateRequestGzipCompatible.
@Test
public void testDecompressDeflateRequestGzipCompatible() throws Exception {
request.setMethod("POST");
request.setURI("/banner");
request.setHeader(HttpHeaders.CONTENT_ENCODING, "deflate");
request.setHeader(HttpHeaders.CONTENT_TYPE, PLAIN_TEXT_UTF_8);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DeflaterOutputStream deflate = new DeflaterOutputStream(baos, new Deflater(-1, true))) {
Resources.copy(Resources.getResource("assets/new-banner.txt"), deflate);
}
request.setContent(baos.toByteArray());
HttpTester.Response response = HttpTester.parseResponse(servletTester.getResponses(request.generate()));
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContent()).isEqualTo("Banner has been updated");
}
use of java.util.zip.Deflater in project jetty.project by eclipse.
the class GzipHandler method getDeflater.
/* ------------------------------------------------------------ */
@Override
public Deflater getDeflater(Request request, long content_length) {
String ua = request.getHttpFields().get(HttpHeader.USER_AGENT);
if (ua != null && !isAgentGzipable(ua)) {
LOG.debug("{} excluded user agent {}", this, request);
return null;
}
if (content_length >= 0 && content_length < _minGzipSize) {
LOG.debug("{} excluded minGzipSize {}", this, request);
return null;
}
// check the accept encoding header
HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);
if (accept == null) {
LOG.debug("{} excluded !accept {}", this, request);
return null;
}
boolean gzip = accept.contains("gzip");
if (!gzip) {
LOG.debug("{} excluded not gzip accept {}", this, request);
return null;
}
Deflater df = _deflater.get();
if (df == null)
df = new Deflater(_compressionLevel, true);
else
_deflater.set(null);
return df;
}
use of java.util.zip.Deflater in project jetty.project by eclipse.
the class DeflateFrameExtensionTest method testDeflateBasics.
@Test
public void testDeflateBasics() throws Exception {
// Setup deflater basics
Deflater compressor = new Deflater(Deflater.BEST_COMPRESSION, true);
compressor.setStrategy(Deflater.DEFAULT_STRATEGY);
// Text to compress
String text = "info:";
byte[] uncompressed = StringUtil.getUtf8Bytes(text);
// Prime the compressor
compressor.reset();
compressor.setInput(uncompressed, 0, uncompressed.length);
compressor.finish();
// Perform compression
ByteBuffer outbuf = ByteBuffer.allocate(64);
BufferUtil.clearToFill(outbuf);
while (!compressor.finished()) {
byte[] out = new byte[64];
int len = compressor.deflate(out, 0, out.length, Deflater.SYNC_FLUSH);
if (len > 0) {
outbuf.put(out, 0, len);
}
}
compressor.end();
BufferUtil.flipToFlush(outbuf, 0);
byte[] compressed = BufferUtil.toArray(outbuf);
// Clear the BFINAL bit that has been set by the compressor.end() call.
// In the real implementation we never end() the compressor.
compressed[0] &= 0xFE;
String actual = TypeUtil.toHexString(compressed);
// what pywebsocket produces
String expected = "CaCc4bCbB70200";
Assert.assertThat("Compressed data", actual, is(expected));
}
use of java.util.zip.Deflater in project elasticsearch by elastic.
the class DeflateCompressor method streamOutput.
@Override
public StreamOutput streamOutput(StreamOutput out) throws IOException {
out.writeBytes(HEADER);
final boolean nowrap = true;
final Deflater deflater = new Deflater(LEVEL, nowrap);
final boolean syncFlush = true;
OutputStream compressedOut = new DeflaterOutputStream(out, deflater, BUFFER_SIZE, syncFlush);
compressedOut = new BufferedOutputStream(compressedOut, BUFFER_SIZE);
return new OutputStreamStreamOutput(compressedOut) {
final AtomicBoolean closed = new AtomicBoolean(false);
public void close() throws IOException {
try {
super.close();
} finally {
if (closed.compareAndSet(false, true)) {
// important to release native memory
deflater.end();
}
}
}
};
}
Aggregations