Search in sources :

Example 6 with DataFormatException

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();
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with DataFormatException

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);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 8 with DataFormatException

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);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) BadPayloadException(org.eclipse.jetty.websocket.api.BadPayloadException)

Example 9 with DataFormatException

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;
}
Also used : DataFormatException(java.util.zip.DataFormatException) BadPayloadException(org.eclipse.jetty.websocket.api.BadPayloadException) ByteBuffer(java.nio.ByteBuffer)

Example 10 with DataFormatException

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;
}
Also used : DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException)

Aggregations

DataFormatException (java.util.zip.DataFormatException)71 IOException (java.io.IOException)32 Inflater (java.util.zip.Inflater)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ByteBuffer (java.nio.ByteBuffer)9 ArrayList (java.util.ArrayList)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)5 File (java.io.File)4 BufferedOutputStream (java.io.BufferedOutputStream)3 FileOutputStream (java.io.FileOutputStream)3 URL (java.net.URL)3 ImageException (cbit.image.ImageException)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 BaseMediaHeader (cbit.vcell.export.gloworm.atoms.BaseMediaHeader)2 BaseMediaInformation (cbit.vcell.export.gloworm.atoms.BaseMediaInformation)2 HandlerReference (cbit.vcell.export.gloworm.atoms.HandlerReference)2 VideoMediaInformation (cbit.vcell.export.gloworm.atoms.VideoMediaInformation)2 GeometryException (cbit.vcell.geometry.GeometryException)2