public byte[] decompress(byte[] in) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(in); final InflaterInputStream gz = new InflaterInputStream(bais); int read; while ((read = gz.read()) != -1) { baos.write(read); } gz.close(); bais.close(); baos.close(); return baos.toByteArray(); }
private static byte[] inflate(byte[] input) throws IOException { InflaterInputStream gzis = new InflaterInputStream(new ByteArrayInputStream(input)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while(gzis.available() > 0) { int l = gzis.read(buffer); if(l > 0) out.write(buffer, 0, l); } return out.toByteArray(); }
private void processPAYLOAD(final byte b) { currBytes.write(b); switch (decodedFrameType) { case FRAME_WINDOWSIZE: //'W' if (currBytes.size() < 6) { logger.trace("Lumberjack currBytes contents are {}", currBytes.toString()); break; } else if (currBytes.size() == 6) { try { byte[] buf = java.util.Arrays.copyOfRange(currBytes.toByteArray(), 6, currBytes.size()); InputStream in = new InflaterInputStream(new ByteArrayInputStream(buf)); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); in.close(); out.close(); decompressedData = out.toByteArray();
HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); configureConnection(connection); if (domain == null || url.getHost().endsWith(domain)) { String path = cookie.getPath(); if (path == null || url.getPath().startsWith(path)) { cookies.put(cookie.getName(), cookie.getValue()); InputStream in = connection.getInputStream(); if ("gzip".equalsIgnoreCase(encoding)) { in = new GZIPInputStream(in); } else if ("deflate".equalsIgnoreCase(encoding)) { in = new InflaterInputStream(in); } else if (encoding != null) { receiver.onTransportFailure(new ServerFailure("Unknown server encoding " + encoding)); in.close(); String received = new String(bytes.toByteArray(), "UTF-8"); receiver.onTransportSuccess(received); } catch (IOException e) {
if ("file".equalsIgnoreCase(url.getProtocol())) { final File file; try { file = new File(url.toURI()); } catch (URISyntaxException ex) { final String msg = format("Download failed, unable to locate '%s'", url.toString()); throw new DownloadFailedException(msg); BufferedOutputStream writer = new BufferedOutputStream(out)) { if (encoding != null && "gzip".equalsIgnoreCase(encoding)) { reader = new GZIPInputStream(conn.getInputStream()); } else if (encoding != null && "deflate".equalsIgnoreCase(encoding)) { reader = new InflaterInputStream(conn.getInputStream()); } else { reader = conn.getInputStream(); while ((bytesRead = reader.read(buffer)) > 0) { writer.write(buffer, 0, bytesRead); if (reader != null) { try { reader.close(); } catch (IOException ex) { LOGGER.trace("Error closing the reader in Downloader.", ex);
enum StringCompressor { ; public static byte[] compress(String text) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { OutputStream out = new DeflaterOutputStream(baos); out.write(text.getBytes("UTF-8")); out.close(); } catch (IOException e) { throw new AssertionError(e); } return baos.toByteArray(); } public static String decompress(byte[] bytes) { InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { byte[] buffer = new byte[8192]; int len; while((len = in.read(buffer))>0) baos.write(buffer, 0, len); return new String(baos.toByteArray(), "UTF-8"); } catch (IOException e) { throw new AssertionError(e); } } }
private ByteBuffer decompress(ByteBuffer source) throws IOException { if (source.remaining() == 0) { return source; } ByteBufferInputStream sourceStream = new ByteBufferInputStream(source); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(source.remaining() * 2); InputStream decompressor = null; if (compressionType == CompressionType.GZIP) { decompressor = new GZIPInputStream(sourceStream); } if (compressionType == CompressionType.DEFLATE) { decompressor = new InflaterInputStream(sourceStream); } try { copy(decompressor, outputStream); } finally { decompressor.close(); } return ByteBuffer.wrap(outputStream.toByteArray()); }
public static byte[] compressBytes(final byte[] ori, final int offset, final int len, final boolean compress) { try { final ByteArrayInputStream inb = new ByteArrayInputStream(ori, offset, len); final InputStream in = compress ? inb : new InflaterInputStream(inb, getInflater()); final ByteArrayOutputStream outb = new ByteArrayOutputStream(); final OutputStream out = compress ? new DeflaterOutputStream(outb) : outb; shovelInToOut(in, out); in.close(); out.close(); return outb.toByteArray(); } catch (final Exception e) { throw new PngjException(e); } }
URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Cast shouldn't fail HttpURLConnection.setFollowRedirects(true); // allow both GZip and Deflate (ZLib) encodings conn.setRequestProperty("Accept-Encoding", "gzip, deflate"); String encoding = conn.getContentEncoding(); InputStream inStr = null; // create the appropriate stream wrapper based on // the encoding type if (encoding != null && encoding.equalsIgnoreCase("gzip")) { inStr = new GZIPInputStream(conn.getInputStream()); } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { inStr = new InflaterInputStream(conn.getInputStream(), new Inflater(true)); } else { inStr = conn.getInputStream(); }
byte[] bytes = Base64Coder.decode(data.getText()); if (compression == null) is = new ByteArrayInputStream(bytes); else if (compression.equals("gzip")) is = new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes), bytes.length)); else if (compression.equals("zlib")) is = new BufferedInputStream(new InflaterInputStream(new ByteArrayInputStream(bytes))); else throw new GdxRuntimeException("Unrecognised compression (" + compression + ") for TMX Layer Data"); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int read = is.read(temp); while (read < temp.length) { int curr = is.read(temp, read, temp.length - read); if (curr == -1) break; read += curr;
private String decodeContent(ByteSequence bodyAsBytes) throws JMSException { String text = null; if (bodyAsBytes != null) { InputStream is = null; try { is = new ByteArrayInputStream(bodyAsBytes); if (isCompressed()) { is = new InflaterInputStream(is); } DataInputStream dataIn = new DataInputStream(is); text = MarshallingSupport.readUTF8(dataIn); dataIn.close(); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // ignore } } } } return text; }
URL url = new URL(baseUrl); urlConn = (HttpURLConnection) url.openConnection(); inpStream = new GZIPInputStream(inpStream); } else if (encode != null && encode.indexOf("deflate") != -1) { inpStream = new InflaterInputStream(inpStream); try { outWrite.close(); inpStream.close(); reader.close(); urlConn.disconnect();
private DataInputStream getZlibInputStream(byte[] data) { return new DataInputStream(new BufferedInputStream(new InflaterInputStream( new ByteArrayInputStream(data), new Inflater(), 2048))); }
@Override public InputStream decode(String contentEncoding, InputStream encodedStream) throws IOException { // correct impl. should wrap deflate in zlib, but some don't do it - have to identify, which one we got InputStream markSupportingStream = encodedStream.markSupported() ? encodedStream : new BufferedInputStream(encodedStream); markSupportingStream.mark(1); // read the first byte int firstByte = markSupportingStream.read(); markSupportingStream.reset(); // if using zlib, first 3 bits should be 0, 4th should be 1 // that should never be the case if no zlib wrapper if ((firstByte & 15) == 8) { // ok, zlib wrapped stream return new InflaterInputStream(markSupportingStream); } else { // no zlib wrapper return new InflaterInputStream(markSupportingStream, new Inflater(true)); } }
planMode = "RPC"; byte[] planBytes = Base64.decodeBase64(planString); in = new ByteArrayInputStream(planBytes); in = new InflaterInputStream(in); } else { LOG.debug("Open file to read in plan: " + localPath); if (in != null) { try { in.close(); } catch (IOException cantBlameMeForTrying) { }
final ByteArrayInputStream bais = new ByteArrayInputStream(compressed); final ByteArrayInputStream bais2 = new ByteArrayInputStream(compressed2); InputStream inflaterStream; InputStream inflaterStream2; switch (compressionType) { case GZIP: inflaterStream = new GZIPInputStream(bais); inflaterStream2 = new GZIPInputStream(bais2); break; case ZLIB: inflaterStream = new InflaterInputStream(bais); inflaterStream2 = new InflaterInputStream(bais2); break; case OFF: inflaterStream.close(); inflaterStream2.close(); final String uncompressedString = new String(uncompressed, layout.getCharset()); final String uncompressedString2 = new String(uncompressed2, layout.getCharset());
private byte[] decompress(byte[] data) throws SessionValueEncoderException { if (!doCompress()) { return data; } ByteArrayInputStream bais = new ByteArrayInputStream(data); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); try { return StreamUtil.readBytes(iis, true).toByteArray(); } catch (Exception e) { throw new SessionValueEncoderException(e); } finally { inf.end(); } }
n8 = (byte) in.read(); stringBuf.append( HexDump.toHex( n8 ) ); stringBuf.append( getBlipType( n8 ) ); stringBuf.append( " btMacOS: " ); n8 = (byte) in.read(); stringBuf.append( HexDump.toHex( n8 ) ); stringBuf.append( getBlipType( n8 ) ); out.println( " Y: " + HexDump.toHex( LittleEndian.readInt( in ) ) ); out.println( " Cache of saved size: " + HexDump.toHex( LittleEndian.readInt( in ) ) ); out.println( " Compression Flag: " + HexDump.toHex( (byte) in.read() ) ); out.println( " Filter: " + HexDump.toHex( (byte) in.read() ) ); out.println( " Data (after decompression): " ); read += in.read( buf, read, buf.length ); ByteArrayInputStream bin = new ByteArrayInputStream( buf ); InputStream in1 = new InflaterInputStream( bin ); int bytesToDump = -1; HexDump.dump( in1, out, 0, bytesToDump );
InputStream inflInstream = new InflaterInputStream(new ByteArrayInputStream(inputData.getBytes()), new Inflater(true)); byte bytes[] = new byte[1024]; while (true) { int length = inflInstream.read(bytes, 0, 1024); if (length == -1) break; System.out.write(bytes, 0, length); }
public static InputStream getInputStream(URLConnection c) throws IOException { InputStream is = c.getInputStream(); String enc = c.getContentEncoding(); if ("gzip".equalsIgnoreCase(enc) || "x-gzip".equalsIgnoreCase(enc)) { is = new GZIPInputStream(is, TRANSFER_BUFFER); } else if ("deflate".equalsIgnoreCase(enc)) { is = new InflaterInputStream(is, new Inflater(), TRANSFER_BUFFER); } return new BufferedInputStream(is); }