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:aarddict.Volume.java
static String decompressZlib(byte[] bytes) throws IOException, DataFormatException { Inflater decompressor = new Inflater(); decompressor.setInput(bytes);//w ww . j a v a 2s.c o m ByteArrayOutputStream out = new ByteArrayOutputStream(); try { byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); out.write(buf, 0, count); } } finally { out.close(); } return utf8(out.toByteArray()); }
From source file:com.bigdata.dastor.utils.FBUtilities.java
public static byte[] decompress(byte[] compressedData, int off, int len) throws IOException, DataFormatException { // Create the decompressor and give it the data to compress Inflater decompressor = new Inflater(); decompressor.setInput(compressedData, off, len); // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count);//from w w w . ja v a 2 s . c o m } bos.close(); // Get the decompressed data return bos.toByteArray(); }
From source file:com.kactech.otj.Utils.java
public static byte[] zlibDecompress(byte[] data) throws IOException, DataFormatException { Inflater inflater = new Inflater(false); inflater.setInput(data);//from w w w . j a v a2 s . com ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); if (count == 0) throw new DataFormatException("probably bad, has infinite loop at encoded message"); outputStream.write(buffer, 0, count); } outputStream.close(); byte[] output = outputStream.toByteArray(); return output; }
From source file:org.wso2.carbon.identity.saml.inbound.util.SAMLSSOUtil.java
/** * Decoding and deflating the encoded AuthReq * * @param encodedStr encoded AuthReq//from w w w .j av a 2 s .com * @return decoded AuthReq */ public static String decode(String encodedStr) throws IdentityException { try { org.apache.commons.codec.binary.Base64 base64Decoder = new org.apache.commons.codec.binary.Base64(); byte[] xmlBytes = encodedStr.getBytes(StandardCharsets.UTF_8.name()); byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes); try { Inflater inflater = new Inflater(true); inflater.setInput(base64DecodedByteArray); byte[] xmlMessageBytes = new byte[5000]; int resultLength = inflater.inflate(xmlMessageBytes); if (!inflater.finished()) { throw new RuntimeException("End of the compressed data stream has NOT been reached"); } inflater.end(); String decodedString = new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8.name()); if (log.isDebugEnabled()) { log.debug("Request message " + decodedString); } return decodedString; } catch (DataFormatException e) { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(base64DecodedByteArray); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); InflaterInputStream iis = new InflaterInputStream(byteArrayInputStream); byte[] buf = new byte[1024]; int count = iis.read(buf); while (count != -1) { byteArrayOutputStream.write(buf, 0, count); count = iis.read(buf); } iis.close(); String decodedStr = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); if (log.isDebugEnabled()) { log.debug("Request message " + decodedStr, e); } return decodedStr; } } catch (IOException e) { throw IdentityException.error("Error when decoding the SAML Request.", e); } }
From source file:acp.sdk.SecureUtil.java
/** * ./*from www . ja va2s .c o m*/ * * @param inputByte * byte[]? * @return ?? * @throws IOException */ public static byte[] inflater(final byte[] inputByte) throws IOException { int compressedDataLength = 0; Inflater compresser = new Inflater(false); compresser.setInput(inputByte, 0, inputByte.length); ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length); byte[] result = new byte[1024]; try { while (!compresser.finished()) { compressedDataLength = compresser.inflate(result); if (compressedDataLength == 0) { break; } o.write(result, 0, compressedDataLength); } } catch (Exception ex) { System.err.println("Data format error!\n"); ex.printStackTrace(); } finally { o.close(); } compresser.end(); return o.toByteArray(); }
From source file:nl.nn.adapterframework.util.Misc.java
public static byte[] decompress(byte[] input) throws DataFormatException, IOException { // Create the decompressor and give it the data to compress Inflater decompressor = new Inflater(); decompressor.setInput(input);// w w w. j av a 2 s. c om // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } bos.close(); // Get the decompressed data return bos.toByteArray(); }
From source file:org.openteufel.file.mpq.MPQFileSector.java
public int getDecompressed(ByteBuffer out) throws DataFormatException, IOException { // If the file is encrypted, each sector (after compression/implosion, if applicable) is encrypted with the file's key. // Each sector is encrypted using the key + the 0-based index of the sector in the file. // NOTE compression type byte (if existing) is encrypted as well! ByteBuffer dataDecrypted;//from w w w .ja v a 2s. c o m if (this.encryptionSeed != null) dataDecrypted = MPQEncryptionUtils.decrypt(dataRaw, encryptionSeed); else dataDecrypted = dataRaw; dataDecrypted.rewind(); switch (compression) { case Uncompressed: { out.put(dataDecrypted); return dataDecrypted.capacity(); } case Imploded: { byte[] buf = new byte[sizeUncompressed]; int numDecompressed = Exploder.pkexplode(dataDecrypted.array(), buf); if (numDecompressed != this.sizeUncompressed) throw new IllegalStateException(); out.put(buf, 0, sizeUncompressed); return sizeUncompressed; } case ZLib: { int numDecompressed = 0; byte[] buf = new byte[1024]; Inflater inflater = new Inflater(); inflater.setInput(dataDecrypted.array()); while (!inflater.finished()) { int decompressedBytes = inflater.inflate(buf); numDecompressed += decompressedBytes; out.put(buf, 0, decompressedBytes); } inflater.end(); if (numDecompressed != this.sizeUncompressed) throw new IllegalStateException(); return numDecompressed; } case BZip2: { int numDecompressed = 0; byte[] buf = new byte[1024]; InputStream inputStream = new ByteArrayInputStream(dataDecrypted.array()); BZip2CompressorInputStream uncompressStream = new BZip2CompressorInputStream(inputStream); while (true) { int decompressedBytes = uncompressStream.read(buf); if (decompressedBytes < 0) break; numDecompressed += decompressedBytes; out.put(buf, 0, decompressedBytes); } uncompressStream.close(); inputStream.close(); if (numDecompressed != sizeUncompressed) throw new IllegalStateException(); return numDecompressed; } default: throw new IllegalStateException("Unknown Compression"); } }
From source file:org.hyperic.hq.livedata.agent.commands.LiveData_result.java
private String decompress(String s) throws IOException, DataFormatException { Inflater decompressor = new Inflater(); decompressor.setInput(Base64.decode(s)); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count);/*from w ww.j av a 2s. c o m*/ } bos.close(); byte[] decompressedData = bos.toByteArray(); return new String(decompressedData, 0, decompressedData.length, "UTF-8"); }
From source file:org.getspout.spoutapi.packet.PacketSendPrecache.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) { }/* www . j a v a 2 s.c o m*/ } try { bos.close(); } catch (IOException e) { } fileData = bos.toByteArray(); } }
From source file:org.getspout.spout.packet.PacketCustomMultiBlockOverride.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);/*ww w .ja v a 2s . 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) { } compressed = false; data = bos.toByteArray(); } }