Search in sources :

Example 26 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 27 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 28 with DataFormatException

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

the class SwfTranscoder method readSource.

// in will be closed
protected void readSource(InputStream in, long inputLength) throws IOException {
    final int uncompressedBodyLength;
    final boolean compressed;
    byte[] data;
    try {
        int n = in.read(partialHeader);
        assert n == PARTIAL_HEADER_LENGTH;
        uncompressedBodyLength = (partialHeader[4] & 0xFF | (partialHeader[5] & 0xFF) << 8 | (partialHeader[6] & 0xFF) << 16 | partialHeader[7] << 24) - PARTIAL_HEADER_LENGTH;
        compressed = partialHeader[0] == 0x43;
        data = FileUtil.loadBytes(in, compressed ? (int) inputLength - PARTIAL_HEADER_LENGTH : uncompressedBodyLength);
    } finally {
        in.close();
    }
    if (compressed) {
        final Inflater inflater = INFLATER.get();
        try {
            inflater.setInput(data);
            byte[] uncompressedData = new byte[uncompressedBodyLength];
            try {
                inflater.inflate(uncompressedData);
            } catch (DataFormatException e) {
                throw new ZipException(e.getMessage() != null ? e.getMessage() : "Invalid ZLIB data format");
            }
            data = uncompressedData;
        } finally {
            inflater.reset();
        }
    }
    buffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
    readFrameSizeFrameRateAndFrameCount(data[0]);
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) ZipException(java.util.zip.ZipException)

Example 29 with DataFormatException

use of java.util.zip.DataFormatException in project ceylon-compiler by ceylon.

the class ZipFileIndex method inflate.

private int inflate(byte[] src, byte[] dest) {
    Inflater inflater = (inflaterRef == null ? null : inflaterRef.get());
    // construct the inflater object or reuse an existing one
    if (inflater == null)
        inflaterRef = new SoftReference<Inflater>(inflater = new Inflater(true));
    inflater.reset();
    inflater.setInput(src);
    try {
        return inflater.inflate(dest);
    } catch (DataFormatException ex) {
        return -1;
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) SoftReference(java.lang.ref.SoftReference) Inflater(java.util.zip.Inflater)

Example 30 with DataFormatException

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

the class DeflateCompressor method uncompressBuffer.

public void uncompressBuffer(ByteBuffer input, ByteBuffer output) throws IOException {
    try {
        Inflater inf = inflater.get();
        inf.reset();
        byte[] buffer = getThreadLocalScratchBuffer();
        // Use half the buffer for input, half for output.
        int chunkLen = buffer.length / 2;
        while (input.remaining() > chunkLen) {
            input.get(buffer, 0, chunkLen);
            inf.setInput(buffer, 0, chunkLen);
            while (!inf.needsInput()) {
                int len = inf.inflate(buffer, chunkLen, chunkLen);
                output.put(buffer, chunkLen, len);
            }
        }
        int inputLength = input.remaining();
        input.get(buffer, 0, inputLength);
        inf.setInput(buffer, 0, inputLength);
        while (!inf.needsInput()) {
            int len = inf.inflate(buffer, chunkLen, chunkLen);
            output.put(buffer, chunkLen, len);
        }
    } catch (DataFormatException e) {
        throw new IOException(e);
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Aggregations

DataFormatException (java.util.zip.DataFormatException)52 IOException (java.io.IOException)24 Inflater (java.util.zip.Inflater)23 ByteBuffer (java.nio.ByteBuffer)9 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ByteBuf (io.netty.buffer.ByteBuf)2 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)2 EOFException (java.io.EOFException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ZipException (java.util.zip.ZipException)2 ILoader (master.flame.danmaku.danmaku.loader.ILoader)2 IllegalDataException (master.flame.danmaku.danmaku.loader.IllegalDataException)2 Danmakus (master.flame.danmaku.danmaku.model.android.Danmakus)2 BaseDanmakuParser (master.flame.danmaku.danmaku.parser.BaseDanmakuParser)2 BadPayloadException (org.eclipse.jetty.websocket.api.BadPayloadException)2 Response (org.jsoup.helper.HttpConnection.Response)2 OrcCorruptionException (com.facebook.presto.orc.OrcCorruptionException)1