Search in sources :

Example 86 with Inflater

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

the class InflaterTest method testEmptyFileAndEmptyBuffer.

/**
     * http://code.google.com/p/android/issues/detail?id=11755
     */
public void testEmptyFileAndEmptyBuffer() throws Exception {
    byte[] emptyInput = deflate(new byte[0], null);
    Inflater inflater = new Inflater();
    inflater.setInput(emptyInput);
    assertFalse(inflater.finished());
    assertEquals(0, inflater.inflate(new byte[0], 0, 0));
    assertTrue(inflater.finished());
}
Also used : Inflater(java.util.zip.Inflater)

Example 87 with Inflater

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

the class PacketPlayOutMapChunk method a.

public void a(PacketDataSerializer packetdataserializer) {
    this.a = packetdataserializer.readInt();
    this.b = packetdataserializer.readInt();
    this.g = packetdataserializer.readBoolean();
    this.c = packetdataserializer.readShort();
    this.d = packetdataserializer.readShort();
    this.h = packetdataserializer.readInt();
    if (i.length < this.h) {
        i = new byte[this.h];
    }
    packetdataserializer.readBytes(i, 0, this.h);
    int i = 0;
    int j;
    for (j = 0; j < 16; ++j) {
        i += this.c >> j & 1;
    }
    j = 12288 * i;
    if (this.g) {
        j += 256;
    }
    this.f = new byte[j];
    Inflater inflater = new Inflater();
    inflater.setInput(i, 0, this.h);
    try {
        inflater.inflate(this.f);
    } catch (DataFormatException dataformatexception) {
        throw new IOException("Bad compressed data format");
    } finally {
        inflater.end();
    }
}
Also used : DataFormatException(java.util.zip.DataFormatException) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 88 with Inflater

use of java.util.zip.Inflater in project Dragonet-Legacy by DragonetMC.

the class BatchPacket method decode.

@Override
public void decode() {
    try {
        packets = new ArrayList<>();
        PEBinaryReader reader = new PEBinaryReader(new ByteArrayInputStream(this.getData()));
        //PID
        reader.readByte();
        int size = reader.readInt();
        byte[] payload = reader.read(size);
        Inflater inf = new Inflater();
        inf.setInput(payload);
        byte[] decompressedPayload = new byte[1024 * 1024 * 64];
        int decompressedSize = 0;
        try {
            decompressedSize = inf.inflate(decompressedPayload);
        } catch (DataFormatException ex) {
            this.setLength(reader.totallyRead());
            return;
        }
        inf.end();
        PEBinaryReader dataReader = new PEBinaryReader(new ByteArrayInputStream(decompressedPayload));
        int offset = 0;
        while (offset < decompressedSize) {
            int pkLen = dataReader.readInt();
            offset += 4;
            byte[] pkData = dataReader.read(pkLen);
            offset += pkLen;
            PEPacket pk = Protocol.decode(pkData);
            if (pk == null || pk.getLength() == 0) {
                packets.clear();
                return;
            }
            packets.add(pk);
        }
        this.setLength(reader.totallyRead());
    } catch (IOException e) {
    }
}
Also used : PEBinaryReader(org.dragonet.utilities.io.PEBinaryReader) DataFormatException(java.util.zip.DataFormatException) ByteArrayInputStream(java.io.ByteArrayInputStream) Inflater(java.util.zip.Inflater) IOException(java.io.IOException)

Example 89 with Inflater

use of java.util.zip.Inflater in project CodeChickenLib by Chicken-Bones.

the class PacketCustom method decompress.

/**
     * Decompresses the remaining ByteBuf (after type has been read) using Snappy
     */
private void decompress() {
    Inflater inflater = new Inflater();
    try {
        int len = readInt();
        byte[] out = new byte[len];
        inflater.setInput(array(), readerIndex(), readableBytes());
        inflater.inflate(out);
        clear();
        writeByteArray(out);
    } catch (Exception e) {
        throw new EncoderException(e);
    } finally {
        inflater.end();
    }
}
Also used : EncoderException(io.netty.handler.codec.EncoderException) Inflater(java.util.zip.Inflater) EncoderException(io.netty.handler.codec.EncoderException) IOException(java.io.IOException)

Example 90 with Inflater

use of java.util.zip.Inflater 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)

Aggregations

Inflater (java.util.zip.Inflater)108 InflaterInputStream (java.util.zip.InflaterInputStream)36 IOException (java.io.IOException)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 DataFormatException (java.util.zip.DataFormatException)30 InputStream (java.io.InputStream)24 ByteArrayInputStream (java.io.ByteArrayInputStream)14 GZIPInputStream (java.util.zip.GZIPInputStream)14 Deflater (java.util.zip.Deflater)9 Test (org.junit.Test)7 DataInputStream (java.io.DataInputStream)6 OutputStream (java.io.OutputStream)6 BufferedInputStream (java.io.BufferedInputStream)5 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 HttpURLConnection (java.net.HttpURLConnection)5 ByteBuffer (java.nio.ByteBuffer)5 JSONObject (org.json.JSONObject)5 DataOutputStream (java.io.DataOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4