Search in sources :

Example 21 with DataFormatException

use of java.util.zip.DataFormatException in project intellij-community by JetBrains.

the class BinaryEncoder method decode.

public static void decode(@NotNull ListIterator<String> input, long size, @NotNull ByteArrayOutputStream output) throws BinaryPatchException {
    Inflater inflater = new Inflater();
    byte[] inflated = new byte[1024];
    try {
        String line = input.next();
        while (line != null && line.length() > 0) {
            int len = getLineSizeFromChar(line.charAt(0));
            byte[] toInflate = Base85x.decode(line.substring(1));
            inflater.setInput(toInflate, 0, len);
            int resultLength;
            while (!inflater.needsInput()) {
                try {
                    resultLength = inflater.inflate(inflated);
                } catch (DataFormatException e) {
                    throw new BinaryPatchException("Can't decode binary file patch: can't decompress data");
                }
                output.write(inflated, 0, resultLength);
            }
            if (!input.hasNext())
                break;
            line = input.next();
        }
        int count = output.size();
        if (count != size) {
            throw new BinaryPatchException(String.format("Length of decoded binary patch mismatches: expected %d, received %d", size, count));
        }
    } catch (Base85x.Base85FormatException e) {
        throw new BinaryPatchException(e);
    } finally {
        inflater.end();
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) Base85x(com.intellij.openapi.diff.impl.patch.lib.base85xjava.Base85x)

Example 22 with DataFormatException

use of java.util.zip.DataFormatException in project WordPress-Android by wordpress-mobile.

the class Note method buildFromBase64EncodedData.

public static synchronized Note buildFromBase64EncodedData(String noteId, String base64FullNoteData) {
    Note note = null;
    if (base64FullNoteData == null)
        return null;
    byte[] b64DecodedPayload = Base64.decode(base64FullNoteData, Base64.DEFAULT);
    // Decompress the payload
    Inflater decompresser = new Inflater();
    decompresser.setInput(b64DecodedPayload, 0, b64DecodedPayload.length);
    //max length an Android PN payload can have
    byte[] result = new byte[4096];
    int resultLength = 0;
    try {
        resultLength = decompresser.inflate(result);
        decompresser.end();
    } catch (DataFormatException e) {
        AppLog.e(AppLog.T.NOTIFS, "Can't decompress the PN Payload. It could be > 4K", e);
    }
    String out = null;
    try {
        out = new String(result, 0, resultLength, "UTF8");
    } catch (UnsupportedEncodingException e) {
        AppLog.e(AppLog.T.NOTIFS, "Notification data contains non UTF8 characters.", e);
    }
    if (out != null) {
        try {
            JSONObject jsonObject = new JSONObject(out);
            if (jsonObject.has("notes")) {
                JSONArray jsonArray = jsonObject.getJSONArray("notes");
                if (jsonArray != null && jsonArray.length() == 1) {
                    jsonObject = jsonArray.getJSONObject(0);
                }
            }
            note = new Note(noteId, jsonObject);
        } catch (JSONException e) {
            AppLog.e(AppLog.T.NOTIFS, "Can't parse the Note JSON received in the PN", e);
        }
    }
    return note;
}
Also used : DataFormatException(java.util.zip.DataFormatException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) Inflater(java.util.zip.Inflater)

Example 23 with DataFormatException

use of java.util.zip.DataFormatException in project presto by prestodb.

the class OrcInputStream method decompressZip.

// This comes from the Apache Hive ORC code
private int decompressZip(Slice in) throws IOException {
    Inflater inflater = new Inflater(true);
    try {
        inflater.setInput((byte[]) in.getBase(), (int) (in.getAddress() - ARRAY_BYTE_BASE_OFFSET), in.length());
        allocateOrGrowBuffer(in.length() * EXPECTED_COMPRESSION_RATIO, false);
        int uncompressedLength = 0;
        while (true) {
            uncompressedLength += inflater.inflate(buffer, uncompressedLength, buffer.length - uncompressedLength);
            if (inflater.finished() || buffer.length >= maxBufferSize) {
                break;
            }
            int oldBufferSize = buffer.length;
            allocateOrGrowBuffer(buffer.length * 2, true);
            if (buffer.length <= oldBufferSize) {
                throw new IllegalStateException(String.format("Buffer failed to grow. Old size %d, current size %d", oldBufferSize, buffer.length));
            }
        }
        if (!inflater.finished()) {
            throw new OrcCorruptionException("Could not decompress all input (output buffer too small?)");
        }
        return uncompressedLength;
    } catch (DataFormatException e) {
        throw new OrcCorruptionException(e, "Invalid compressed stream");
    } finally {
        inflater.end();
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) OrcCorruptionException(com.facebook.presto.orc.OrcCorruptionException) InputStreamCheckpoint.createInputStreamCheckpoint(com.facebook.presto.orc.checkpoint.InputStreamCheckpoint.createInputStreamCheckpoint)

Example 24 with DataFormatException

use of java.util.zip.DataFormatException in project robovm by robovm.

the class OldDataFormatExceptionTest method testDataFormatExceptionString.

public void testDataFormatExceptionString() {
    DataFormatException dfe = new DataFormatException("Test");
    assertEquals(dfe.getMessage(), "Test");
}
Also used : DataFormatException(java.util.zip.DataFormatException)

Example 25 with DataFormatException

use of java.util.zip.DataFormatException in project robovm by robovm.

the class OldDataFormatExceptionTest method testDataFormatException.

public void testDataFormatException() {
    DataFormatException dfe = new DataFormatException();
    assertEquals(dfe.getMessage(), null);
}
Also used : DataFormatException(java.util.zip.DataFormatException)

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