Search in sources :

Example 16 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 17 with DataFormatException

use of java.util.zip.DataFormatException in project j2objc by google.

the class OldDataFormatExceptionTest method testDataFormatException.

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

Example 18 with DataFormatException

use of java.util.zip.DataFormatException in project voltdb by VoltDB.

the class HistogramLogReader method nextIntervalHistogram.

private EncodableHistogram nextIntervalHistogram(final double rangeStartTimeSec, final double rangeEndTimeSec, boolean absolute) {
    while (scanner.hasNextLine()) {
        try {
            if (scanner.hasNext("\\#.*")) {
                // Look for explicit start time or base time notes in comments:
                if (scanner.hasNext("#\\[StartTime:")) {
                    scanner.next("#\\[StartTime:");
                    if (scanner.hasNextDouble()) {
                        // start time represented as seconds since epoch
                        startTimeSec = scanner.nextDouble();
                        observedStartTime = true;
                    }
                } else if (scanner.hasNext("#\\[BaseTime:")) {
                    scanner.next("#\\[BaseTime:");
                    if (scanner.hasNextDouble()) {
                        // base time represented as seconds since epoch
                        baseTimeSec = scanner.nextDouble();
                        observedBaseTime = true;
                    }
                }
                scanner.nextLine();
                continue;
            }
            if (scanner.hasNext("\"StartTimestamp\".*")) {
                // Legend line
                scanner.nextLine();
                continue;
            }
            // Decode: startTimestamp, intervalLength, maxTime, histogramPayload
            // Timestamp is expected to be in seconds
            final double logTimeStampInSec = scanner.nextDouble();
            if (!observedStartTime) {
                // No explicit start time noted. Use 1st observed time:
                startTimeSec = logTimeStampInSec;
                observedStartTime = true;
            }
            if (!observedBaseTime) {
                // No explicit base time noted. Deduce from 1st observed time (compared to start time):
                if (logTimeStampInSec < startTimeSec - (365 * 24 * 3600.0)) {
                    // Criteria Note: if log timestamp is more than a year in the past (compared to
                    // StartTime), we assume that timestamps in the log are not absolute
                    baseTimeSec = startTimeSec;
                } else {
                    // Timestamps are absolute
                    baseTimeSec = 0.0;
                }
                observedBaseTime = true;
            }
            final double absoluteStartTimeStampSec = logTimeStampInSec + baseTimeSec;
            final double offsetStartTimeStampSec = absoluteStartTimeStampSec - startTimeSec;
            // Timestamp length is expect to be in seconds
            final double intervalLengthSec = scanner.nextDouble();
            final double absoluteEndTimeStampSec = absoluteStartTimeStampSec + intervalLengthSec;
            final double startTimeStampToCheckRangeOn = absolute ? absoluteStartTimeStampSec : offsetStartTimeStampSec;
            if (startTimeStampToCheckRangeOn < rangeStartTimeSec) {
                scanner.nextLine();
                continue;
            }
            if (startTimeStampToCheckRangeOn > rangeEndTimeSec) {
                return null;
            }
            // Skip maxTime field, as max time can be deduced from the histogram.
            scanner.nextDouble();
            final String compressedPayloadString = scanner.next();
            final ByteBuffer buffer = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(compressedPayloadString));
            EncodableHistogram histogram = EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0);
            histogram.setStartTimeStamp((long) (absoluteStartTimeStampSec * 1000.0));
            histogram.setEndTimeStamp((long) (absoluteEndTimeStampSec * 1000.0));
            // Move to next line. Very much needed for e.g. windows CR/LF lines
            scanner.nextLine();
            return histogram;
        } catch (java.util.NoSuchElementException ex) {
            return null;
        } catch (DataFormatException ex) {
            return null;
        }
    }
    return null;
}
Also used : DataFormatException(java.util.zip.DataFormatException) ByteBuffer(java.nio.ByteBuffer)

Example 19 with DataFormatException

use of java.util.zip.DataFormatException in project mc-dev by Bukkit.

the class PacketPlayOutMapChunkBulk method a.

public void a(PacketDataSerializer packetdataserializer) {
    short short1 = packetdataserializer.readShort();
    this.size = packetdataserializer.readInt();
    this.h = packetdataserializer.readBoolean();
    this.a = new int[short1];
    this.b = new int[short1];
    this.c = new int[short1];
    this.d = new int[short1];
    this.inflatedBuffers = new byte[short1][];
    if (buildBuffer.length < this.size) {
        buildBuffer = new byte[this.size];
    }
    packetdataserializer.readBytes(buildBuffer, 0, this.size);
    byte[] abyte = new byte[PacketPlayOutMapChunk.c() * short1];
    Inflater inflater = new Inflater();
    inflater.setInput(buildBuffer, 0, this.size);
    try {
        inflater.inflate(abyte);
    } catch (DataFormatException dataformatexception) {
        throw new IOException("Bad compressed data format");
    } finally {
        inflater.end();
    }
    int i = 0;
    for (int j = 0; j < short1; ++j) {
        this.a[j] = packetdataserializer.readInt();
        this.b[j] = packetdataserializer.readInt();
        this.c[j] = packetdataserializer.readShort();
        this.d[j] = packetdataserializer.readShort();
        int k = 0;
        int l = 0;
        int i1;
        for (i1 = 0; i1 < 16; ++i1) {
            k += this.c[j] >> i1 & 1;
            l += this.d[j] >> i1 & 1;
        }
        i1 = 2048 * 4 * k + 256;
        i1 += 2048 * l;
        if (this.h) {
            i1 += 2048 * k;
        }
        this.inflatedBuffers[j] = new byte[i1];
        System.arraycopy(abyte, i, this.inflatedBuffers[j], 0, i1);
        i += i1;
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 20 with DataFormatException

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

the class AbstractHistogramLogReader method nextIntervalHistogram.

private EncodableHistogram nextIntervalHistogram(final Double rangeStartTimeSec, final Double rangeEndTimeSec, boolean absolute) {
    while (scanner.hasNextLine()) {
        try {
            if (scanner.hasNext("\\#.*")) {
                // comment line
                if (scanner.hasNext("#\\[StartTime:")) {
                    scanner.next("#\\[StartTime:");
                    if (scanner.hasNextDouble()) {
                        // start time represented as seconds since epoch
                        setStartTimeSec(scanner.nextDouble());
                    }
                }
                scanner.nextLine();
                continue;
            }
            if (scanner.hasNext("\"StartTimestamp\".*")) {
                // Legend line
                scanner.nextLine();
                continue;
            }
            // Decode: startTimestamp, intervalLength, maxTime, histogramPayload
            // Timestamp start is expect to be in seconds
            final double offsetStartTimeStampSec = scanner.nextDouble();
            final double absoluteStartTimeStampSec = getStartTimeSec() + offsetStartTimeStampSec;
            // Timestamp length is expect to be in seconds
            final double intervalLengthSec = scanner.nextDouble();
            final double offsetEndTimeStampSec = offsetStartTimeStampSec + intervalLengthSec;
            final double absoluteEndTimeStampSec = getStartTimeSec() + offsetEndTimeStampSec;
            final double startTimeStampToCheckRangeOn = absolute ? absoluteStartTimeStampSec : offsetStartTimeStampSec;
            if (startTimeStampToCheckRangeOn < rangeStartTimeSec) {
                scanner.nextLine();
                continue;
            }
            if (startTimeStampToCheckRangeOn > rangeEndTimeSec) {
                return null;
            }
            // Skip maxTime field, as max time can be deduced from the histogram.
            scanner.nextDouble();
            final String compressedPayloadString = scanner.next();
            final ByteBuffer buffer = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(compressedPayloadString));
            EncodableHistogram histogram = Histogram.decodeFromCompressedByteBuffer(buffer, 0);
            histogram.setStartTimeStamp((long) (absoluteStartTimeStampSec * 1000.0));
            histogram.setEndTimeStamp((long) (absoluteEndTimeStampSec * 1000.0));
            return histogram;
        } catch (java.util.NoSuchElementException ex) {
            return null;
        } catch (DataFormatException ex) {
            return null;
        }
    }
    return null;
}
Also used : DataFormatException(java.util.zip.DataFormatException) ByteBuffer(java.nio.ByteBuffer)

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