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());
}
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();
}
}
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) {
}
}
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();
}
}
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);
}
}
Aggregations