List of usage examples for java.util.zip Inflater inflate
public int inflate(ByteBuffer output) throws DataFormatException
From source file:spartanfinal.ProcessFiles.java
public byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);//from w ww . ja v a2 s. c om ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); return output; }
From source file:org.getspout.spoutapi.packet.PacketAddonData.java
@Override public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);//from w w w.j a v a 2 s . com ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); compressed = false; } }
From source file:org.getspout.spout.packet.PacketCacheFile.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(fileData); ByteArrayOutputStream bos = new ByteArrayOutputStream(fileData.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { }//from w w w .ja v a 2 s . c om } try { bos.close(); } catch (IOException e) { } fileData = bos.toByteArray(); } }
From source file:Comman.Tool.java
public byte[] Image_decompress(final byte[] data) { if (data == null || data.length == 0) { return new byte[0]; }/*from w w w .j av a 2s. co m*/ final Inflater inflater = new Inflater(); inflater.setInput(data); try (final ByteArrayOutputStream out = new ByteArrayOutputStream(data.length)) { final byte[] buffer = new byte[1024]; while (!inflater.finished()) { out.write(buffer, 0, inflater.inflate(buffer)); } return out.toByteArray(); } catch (final IOException | DataFormatException e) { System.err.println("Decompression failed! Returning the compressed data..."); return data; } }
From source file:org.getspout.spout.packet.PacketAddonData.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);//from ww w.ja v a 2 s . co m ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); compressed = false; } }
From source file:org.jmangos.realm.network.packet.wow.client.CMSG_AUTH_SESSION.java
@Override protected void readImpl() throws BufferUnderflowException, RuntimeException { this.ClientBuild = readD(); skip(4);/*from w w w .j ava 2s . c o m*/ this.accountName = readS(); skip(4); this.clientSeed = readB(4); skip(20); this.digest = readB(20); if (getAvaliableBytes() < 4) { return; } final int UncopressedSize = readD(); final byte[] compressedData = readB(getAvaliableBytes()); final Inflater decompressor = new Inflater(); decompressor.setInput(compressedData); final ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length); final byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { final int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (final DataFormatException e) { } } try { bos.close(); } catch (final IOException e) { } final byte[] decompressedData = bos.toByteArray(); if (UncopressedSize != decompressedData.length) { logger.warn("Somesing wrong with compressed addonInfo"); return; } final ChannelBuffer addonInfo = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, decompressedData); final int addonsCount = addonInfo.readInt(); this.addonLists = new ArrayList<AddonInfo>(addonsCount); for (int i = 0; i < addonsCount; i++) { final TextBuilder tb = TextBuilder.newInstance(); for (byte c; (c = addonInfo.readByte()) != 0;) { tb.append((char) c); } final String addonName = tb.toString(); TextBuilder.recycle(tb); final byte enabled = addonInfo.readByte(); final int crc = addonInfo.readInt(); /* int unk1 = */addonInfo.readInt(); this.addonLists.add(new AddonInfo(addonName, enabled, crc)); } /* int unk2 = */addonInfo.readInt(); }
From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.safe.TSafeDeflateJsonQueryHandler.java
@Override public boolean willDecode(ByteBuffer buff) { boolean valid = true; //TODO: actually check whether it's a query try {// ww w . j a va 2 s . c o m //decompress final Inflater inflater = new Inflater(true); inflater.setInput(buff.array()); int read = 0; int totalSize = 0; final List<byte[]> buffers = new LinkedList<byte[]>(); byte[] buffer = new byte[BUFFER_SIZE]; read = inflater.inflate(buffer); while (read > 0) { totalSize += read; buffers.add(buffer); buffer = new byte[BUFFER_SIZE]; read = inflater.inflate(buffer); } final byte[] data = fuse(buffers, totalSize).array(); new JSONObject(new String(data)); } catch (Exception e) { valid = false; } return valid; }
From source file:org.apache.qpid.multiconsumer.AMQTest.java
private String inflateString(String string) throws Exception { byte[] input = string.getBytes(); // First convert Base64 string back to binary array byte[] bytes = Base64.decodeBase64(input); // Set string as input data for decompressor Inflater decompressor = new Inflater(); decompressor.setInput(bytes);/*w ww. j a v a 2 s . com*/ // Decompress the data ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); byte[] output = bos.toByteArray(); // Get the decompressed data return new String(output, UTF8); }
From source file:de.hofuniversity.iisys.neo4j.websock.query.encoding.safe.TSafeDeflateJsonQueryHandler.java
@Override public WebsockQuery decode(ByteBuffer buff) throws DecodeException { WebsockQuery query = null;//from w w w . j a va 2s .c o m try { //decompress final byte[] incoming = buff.array(); final Inflater inflater = new Inflater(true); inflater.setInput(incoming); int read = 0; int totalSize = 0; final List<byte[]> buffers = new LinkedList<byte[]>(); final byte[] buffer = new byte[BUFFER_SIZE]; read = inflater.inflate(buffer); while (read > 0) { totalSize += read; buffers.add(Arrays.copyOf(buffer, read)); read = inflater.inflate(buffer); } final byte[] data = fuse(buffers, totalSize).array(); final JSONObject obj = new JSONObject(new String(data)); if (fDebug) { fTotalBytesIn += incoming.length; fLogger.log(Level.FINEST, "received compressed JSON message: " + incoming.length + " bytes\n" + "total bytes received: " + fTotalBytesIn); } query = JsonConverter.fromJson(obj); } catch (Exception e) { e.printStackTrace(); throw new DecodeException(buff, "failed to decode JSON", e); } return query; }
From source file:org.jwebsocket.util.Tools.java
/** * Inflate a byte array with Zip compression * * @param aCompressedData/* w w w .java2 s .co m*/ * @return * @throws Exception */ public static byte[] inflate(byte[] aCompressedData) throws Exception { Inflater lInflater = new Inflater(); lInflater.setInput(aCompressedData); byte[] lOut = new byte[1024 * 1000 * 5]; int lWritten = lInflater.inflate(lOut); byte[] lResult = new byte[lWritten]; System.arraycopy(lOut, 0, lResult, 0, lWritten); return lResult; }