use of java.util.zip.DataFormatException in project hazelcast by hazelcast.
the class IOUtil method decompress.
public static byte[] decompress(byte[] compressedData) throws IOException {
if (compressedData.length == 0) {
return compressedData;
}
Inflater inflater = new Inflater();
inflater.setInput(compressedData);
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
byte[] buf = new byte[1024];
while (!inflater.finished()) {
try {
int count = inflater.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {
Logger.getLogger(IOUtil.class).finest("Decompression failed", e);
}
}
bos.close();
inflater.end();
return bos.toByteArray();
}
use of java.util.zip.DataFormatException in project cassandra by apache.
the class DeflateCompressor method uncompress.
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) throws IOException {
Inflater inf = inflater.get();
inf.reset();
inf.setInput(input, inputOffset, inputLength);
if (inf.needsInput())
return 0;
// We assume output is big enough
try {
return inf.inflate(output, outputOffset, maxOutputLength);
} catch (DataFormatException e) {
throw new IOException(e);
}
}
use of java.util.zip.DataFormatException in project jetty.project by eclipse.
the class DeflateFrameExtension method incomingFrame.
@Override
public void incomingFrame(Frame frame) {
if (frame.getType().isControl() || !frame.isRsv1() || !frame.hasPayload()) {
nextIncomingFrame(frame);
return;
}
try {
ByteAccumulator accumulator = newByteAccumulator();
decompress(accumulator, frame.getPayload());
decompress(accumulator, TAIL_BYTES_BUF.slice());
forwardIncoming(frame, accumulator);
} catch (DataFormatException e) {
throw new BadPayloadException(e);
}
}
use of java.util.zip.DataFormatException in project jetty.project by eclipse.
the class PerMessageDeflateExtension method incomingFrame.
@Override
public void incomingFrame(Frame frame) {
// Subsequent continuation frames don't have RSV1 set, but are compressed.
if (frame.getType().isData()) {
incomingCompressed = frame.isRsv1();
}
if (OpCode.isControlFrame(frame.getOpCode()) || !incomingCompressed) {
nextIncomingFrame(frame);
return;
}
ByteAccumulator accumulator = newByteAccumulator();
try {
ByteBuffer payload = frame.getPayload();
decompress(accumulator, payload);
if (frame.isFin()) {
decompress(accumulator, TAIL_BYTES_BUF.slice());
}
forwardIncoming(frame, accumulator);
} catch (DataFormatException e) {
throw new BadPayloadException(e);
}
if (frame.isFin())
incomingCompressed = false;
}
use of java.util.zip.DataFormatException in project tomcat by apache.
the class PerMessageDeflate method getMoreData.
@Override
public TransformationResult getMoreData(byte opCode, boolean fin, int rsv, ByteBuffer dest) throws IOException {
// a WebSocket method. Pass them straight through.
if (Util.isControl(opCode)) {
return next.getMoreData(opCode, fin, rsv, dest);
}
if (!Util.isContinuation(opCode)) {
// First frame in new message
skipDecompression = (rsv & RSV_BITMASK) == 0;
}
// Pass uncompressed frames straight through.
if (skipDecompression) {
return next.getMoreData(opCode, fin, rsv, dest);
}
int written;
boolean usedEomBytes = false;
while (dest.remaining() > 0) {
// Space available in destination. Try and fill it.
try {
written = inflater.inflate(dest.array(), dest.arrayOffset() + dest.position(), dest.remaining());
} catch (DataFormatException e) {
throw new IOException(sm.getString("perMessageDeflate.deflateFailed"), e);
}
dest.position(dest.position() + written);
if (inflater.needsInput() && !usedEomBytes) {
if (dest.hasRemaining()) {
readBuffer.clear();
TransformationResult nextResult = next.getMoreData(opCode, fin, (rsv ^ RSV_BITMASK), readBuffer);
inflater.setInput(readBuffer.array(), readBuffer.arrayOffset(), readBuffer.position());
if (TransformationResult.UNDERFLOW.equals(nextResult)) {
return nextResult;
} else if (TransformationResult.END_OF_FRAME.equals(nextResult) && readBuffer.position() == 0) {
if (fin) {
inflater.setInput(EOM_BYTES);
usedEomBytes = true;
} else {
return TransformationResult.END_OF_FRAME;
}
}
}
} else if (written == 0) {
if (fin && (isServer && !clientContextTakeover || !isServer && !serverContextTakeover)) {
inflater.reset();
}
return TransformationResult.END_OF_FRAME;
}
}
return TransformationResult.OVERFLOW;
}
Aggregations