List of usage examples for java.util.zip Inflater finished
boolean finished
To view the source code for java.util.zip Inflater finished.
Click Source Link
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 www . j av a 2 s . c o m } try { bos.close(); } catch (IOException e) { } fileData = bos.toByteArray(); } }
From source file:org.getspout.spout.packet.PacketAddonData.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);/*from w ww.j a v a 2 s. c o 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);/* ww w .ja v a 2s.co 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:spartanfinal.ProcessFiles.java
public byte[] decompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(); inflater.setInput(data);// w w w . ja v a 2 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: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 a v a 2s . c om*/ 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.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 w w. j a v a2s . c o m // 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:io.gomint.server.network.packet.PacketLogin.java
@Override public void deserialize(PacketBuffer buffer) { this.protocol = buffer.readInt(); // Decompress inner data (i don't know why you compress inside of a Batched Packet but hey) byte[] compressed = new byte[buffer.readInt()]; buffer.readBytes(compressed);//from w ww.ja v a 2s .c o m Inflater inflater = new Inflater(); inflater.setInput(compressed); ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { byte[] comBuffer = new byte[1024]; while (!inflater.finished()) { int read = inflater.inflate(comBuffer); bout.write(comBuffer, 0, read); } } catch (DataFormatException e) { System.out.println("Failed to decompress batch packet" + e); return; } // More data please ByteBuffer byteBuffer = ByteBuffer.wrap(bout.toByteArray()); byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byte[] stringBuffer = new byte[byteBuffer.getInt()]; byteBuffer.get(stringBuffer); // Decode the json stuff try { JSONObject jsonObject = (JSONObject) new JSONParser().parse(new String(stringBuffer)); JSONArray chainArray = (JSONArray) jsonObject.get("chain"); if (chainArray != null) { this.validationKey = parseBae64JSON((String) chainArray.get(chainArray.size() - 1)); // First key in chain is last response in chain #brainfuck :D for (Object chainObj : chainArray) { decodeBase64JSON((String) chainObj); } } } catch (ParseException e) { e.printStackTrace(); } // Skin comes next this.skin = new byte[byteBuffer.getInt()]; byteBuffer.get(this.skin); }
From source file:nl.nn.adapterframework.util.JdbcUtil.java
public static String getBlobAsString(Blob blob, String column, String charset, boolean xmlEncode, boolean blobIsCompressed, boolean blobSmartGet, boolean encodeBlobBase64) throws IOException, JdbcException, SQLException, JMSException { if (encodeBlobBase64) { InputStream blobStream = JdbcUtil.getBlobInputStream(blob, column, blobIsCompressed); return Misc.streamToString(new Base64InputStream(blobStream, true), null, false); }/* www .j ava2 s .com*/ if (blobSmartGet) { if (blob == null) { log.debug("no blob found in column [" + column + "]"); return null; } int bl = (int) blob.length(); InputStream is = blob.getBinaryStream(); byte[] buf = new byte[bl]; int bl1 = is.read(buf); Inflater decompressor = new Inflater(); decompressor.setInput(buf); ByteArrayOutputStream bos = new ByteArrayOutputStream(buf.length); byte[] bufDecomp = new byte[1024]; boolean decompresOK = true; while (!decompressor.finished()) { try { int count = decompressor.inflate(bufDecomp); if (count == 0) { break; } bos.write(bufDecomp, 0, count); } catch (DataFormatException e) { log.debug("message in column [" + column + "] is not compressed"); decompresOK = false; break; } } bos.close(); if (decompresOK) buf = bos.toByteArray(); Object result = null; ObjectInputStream ois = null; boolean objectOK = true; try { ByteArrayInputStream bis = new ByteArrayInputStream(buf); ois = new ObjectInputStream(bis); result = ois.readObject(); } catch (Exception e) { log.debug("message in column [" + column + "] is probably not a serialized object: " + e.getClass().getName()); objectOK = false; } if (ois != null) ois.close(); String rawMessage; if (objectOK) { if (result instanceof IMessageWrapper) { rawMessage = ((IMessageWrapper) result).getText(); } else if (result instanceof TextMessage) { rawMessage = ((TextMessage) result).getText(); } else { rawMessage = (String) result; } } else { rawMessage = new String(buf, charset); } String message = XmlUtils.encodeCdataString(rawMessage); return message; } return Misc.readerToString(getBlobReader(blob, column, charset, blobIsCompressed), null, xmlEncode); }
From source file:org.apache.pdfbox.filter.FlateFilter.java
private ByteArrayOutputStream decompress(InputStream in) throws IOException, DataFormatException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; int read = in.read(buf); if (read > 0) { Inflater inflater = new Inflater(); inflater.setInput(buf, 0, read); byte[] res = new byte[2048]; while (true) { int resRead = inflater.inflate(res); if (resRead != 0) { out.write(res, 0, resRead); continue; }/* w w w.ja v a2 s . c o m*/ if (inflater.finished() || inflater.needsDictionary() || in.available() == 0) { break; } read = in.read(buf); inflater.setInput(buf, 0, read); } } out.close(); return out; }
From source file:de.btobastian.javacord.utils.DiscordWebsocketAdapter.java
@Override public void onBinaryMessage(WebSocket websocket, byte[] binary) throws Exception { Inflater decompressor = new Inflater(); decompressor.setInput(binary);// ww w.j a v a 2s. c om ByteArrayOutputStream bos = new ByteArrayOutputStream(binary.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count; try { count = decompressor.inflate(buf); } catch (DataFormatException e) { logger.warn("An error occurred while decompressing data", e); return; } bos.write(buf, 0, count); } try { bos.close(); } catch (IOException ignored) { } byte[] decompressedData = bos.toByteArray(); try { onTextMessage(websocket, new String(decompressedData, "UTF-8")); } catch (UnsupportedEncodingException e) { logger.warn("An error occurred while decompressing data", e); } }