Search in sources :

Example 56 with DataFormatException

use of java.util.zip.DataFormatException in project eiger by wlloyd.

the class DeflateCompressor method uncompress.

public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset) 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, output.length - outputOffset);
    } catch (DataFormatException e) {
        throw new IOException(e);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 57 with DataFormatException

use of java.util.zip.DataFormatException in project eiger by wlloyd.

the class CassandraServer method uncompress.

private static String uncompress(ByteBuffer query, Compression compression) throws InvalidRequestException {
    String queryString = null;
    // Decompress the query string.
    try {
        switch(compression) {
            case GZIP:
                FastByteArrayOutputStream byteArray = new FastByteArrayOutputStream();
                byte[] outBuffer = new byte[1024], inBuffer = new byte[1024];
                Inflater decompressor = new Inflater();
                int lenRead = 0;
                while (true) {
                    if (decompressor.needsInput())
                        lenRead = query.remaining() < 1024 ? query.remaining() : 1024;
                    query.get(inBuffer, 0, lenRead);
                    decompressor.setInput(inBuffer, 0, lenRead);
                    int lenWrite = 0;
                    while ((lenWrite = decompressor.inflate(outBuffer)) != 0) byteArray.write(outBuffer, 0, lenWrite);
                    if (decompressor.finished())
                        break;
                }
                decompressor.end();
                queryString = new String(byteArray.toByteArray(), 0, byteArray.size(), "UTF-8");
                break;
            case NONE:
                try {
                    queryString = ByteBufferUtil.string(query);
                } catch (CharacterCodingException ex) {
                    throw new InvalidRequestException(ex.getMessage());
                }
                break;
        }
    } catch (DataFormatException e) {
        throw new InvalidRequestException("Error deflating query string.");
    } catch (UnsupportedEncodingException e) {
        throw new InvalidRequestException("Unknown query string encoding.");
    }
    return queryString;
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) DataFormatException(java.util.zip.DataFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inflater(java.util.zip.Inflater) CharacterCodingException(java.nio.charset.CharacterCodingException)

Example 58 with DataFormatException

use of java.util.zip.DataFormatException in project pulsar by yahoo.

the class CompressionCodecZLib method decode.

@Override
public ByteBuf decode(ByteBuf encoded, int uncompressedLength) throws IOException {
    ByteBuf uncompressed = PooledByteBufAllocator.DEFAULT.heapBuffer(uncompressedLength, uncompressedLength);
    int len = encoded.readableBytes();
    byte[] array;
    int offset;
    if (encoded.hasArray()) {
        array = encoded.array();
        offset = encoded.arrayOffset() + encoded.readerIndex();
    } else {
        array = new byte[len];
        encoded.getBytes(encoded.readerIndex(), array);
        offset = 0;
    }
    int resultLength;
    synchronized (inflater) {
        inflater.setInput(array, offset, len);
        try {
            resultLength = inflater.inflate(uncompressed.array(), uncompressed.arrayOffset(), uncompressedLength);
        } catch (DataFormatException e) {
            throw new IOException(e);
        }
        inflater.reset();
    }
    checkArgument(resultLength == uncompressedLength);
    uncompressed.writerIndex(uncompressedLength);
    return uncompressed;
}
Also used : DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf)

Example 59 with DataFormatException

use of java.util.zip.DataFormatException in project ABPlayer by winkstu.

the class CompressionTools method decompressXML.

public static byte[] decompressXML(byte[] data) throws DataFormatException {
    byte[] dest = new byte[data.length + 2];
    System.arraycopy(data, 0, dest, 2, data.length);
    dest[0] = 0x78;
    dest[1] = 0x01;
    data = dest;
    Inflater decompresser = new Inflater();
    decompresser.setInput(data);
    byte[] bufferArray = new byte[1024];
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    try {
        int i = 1;
        while (i != 0) {
            i = decompresser.inflate(bufferArray);
            baos.write(bufferArray, 0, i);
        }
        data = baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            baos.flush();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    decompresser.end();
    return data;
}
Also used : Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException)

Example 60 with DataFormatException

use of java.util.zip.DataFormatException in project geode by apache.

the class CommandResult method saveIncomingFiles.

public void saveIncomingFiles(String directory) throws IOException {
    // dump file data if any
    try {
        GfJsonObject content = getContent();
        if (content != null) {
            GfJsonArray bytesArray = content.getJSONArray(CompositeResultData.BYTE_DATA_ACCESSOR);
            AbstractResultData.readFileDataAndDump(bytesArray, directory);
        } else {
            // TODO Abhishek - add i18n
            throw new RuntimeException("No associated files to save .. ");
        // string
        }
        numTimesSaved = numTimesSaved + 1;
    } catch (DataFormatException e) {
        throw new RuntimeException(e);
    } catch (GfJsonException e) {
        throw new RuntimeException(e);
    }
}
Also used : GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) DataFormatException(java.util.zip.DataFormatException) GfJsonObject(org.apache.geode.management.internal.cli.json.GfJsonObject) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException)

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