/** * Writes a byte to the decompressing output stream. {@code b} should be a byte of * compressed input. The corresponding uncompressed data will be written to the underlying * stream. * * @param b the byte * @throws IOException if an I/O error occurs, or the stream has been closed * @throws ZipException if a zip exception occurs. */ @Override public void write(int b) throws IOException, ZipException { write(new byte[] { (byte) b }, 0, 1); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
@Override public byte[] doDecompress(byte[] compressed) throws IOException { InflaterOutputStream inflaterOutputStream = null; ByteArrayOutputStream decompressedOutputStream = null; try { decompressedOutputStream = new ByteArrayOutputStream(); inflaterOutputStream = new InflaterOutputStream(decompressedOutputStream); inflaterOutputStream.write(compressed); inflaterOutputStream.flush(); return decompressedOutputStream.toByteArray(); } finally { Objects.nullSafeClose(decompressedOutputStream, inflaterOutputStream); } } }
/** * Writes to the decompressing output stream. The {@code bytes} array should contain * compressed input. The corresponding uncompressed data will be written to the underlying * stream. * * @throws IOException if an I/O error occurs, or the stream has been closed * @throws ZipException if a zip exception occurs. * @throws NullPointerException if {@code b == null}. * @throws IndexOutOfBoundsException if {@code off < 0 || len < 0 || off + len > b.length} */ @Override public void write(byte[] bytes, int offset, int byteCount) throws IOException, ZipException { checkClosed(); Arrays.checkOffsetAndCount(bytes.length, offset, byteCount); inf.setInput(bytes, offset, byteCount); write(); }
/** * Decodes, inflates and deserializes the specified base64-encoded message to an {@link XMLObject}. */ static XMLObject fromDeflatedBase64(String base64Encoded) { requireNonNull(base64Encoded, "base64Encoded"); final byte[] base64decoded; try { base64decoded = Base64.getMimeDecoder().decode(base64Encoded); } catch (IllegalArgumentException e) { throw new SamlException("failed to decode a deflated base64 string", e); } final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); try (InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(bytesOut, new Inflater(true))) { inflaterOutputStream.write(base64decoded); } catch (IOException e) { throw new SamlException("failed to inflate a SAML message", e); } return SamlMessageUtil.deserialize(bytesOut.toByteArray()); }
protected JSONObject handleBinary(byte[] binary) throws DataFormatException, UnsupportedEncodingException { //Thanks to ShadowLordAlpha and Shredder121 for code and debugging. //Get the compressed message and inflate it //We use the same buffer here to optimize gc use ByteArrayOutputStream decompressBuffer = getDecompressBuffer(); try (InflaterOutputStream decompressor = new InflaterOutputStream(decompressBuffer, zlibContext)) { if (readBuffer != null) readBuffer.writeTo(decompressor); else decompressor.write(binary); } catch (IOException e) { decompressBuffer.reset(); throw (DataFormatException) new DataFormatException("Malformed").initCause(e); } finally { readBuffer = null; } String jsonString = decompressBuffer.toString("UTF-8"); decompressBuffer.reset(); return new JSONObject(jsonString); }
super.write(buf, i, 1); if (inf.finished()) { isFinished = true;
/** * Writes a byte to the decompressing output stream. {@code b} should be a byte of * compressed input. The corresponding uncompressed data will be written to the underlying * stream. * * @param b the byte * @throws IOException if an I/O error occurs, or the stream has been closed * @throws ZipException if a zip exception occurs. */ @Override public void write(int b) throws IOException, ZipException { write(new byte[] { (byte) b }, 0, 1); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
/** * Finishes writing current uncompressed data into the InflaterOutputStream * without closing it. * * @throws IOException if an I/O error occurs, or the stream has been closed */ public void finish() throws IOException { checkClosed(); write(); }
static String inflate(byte[] b) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); InflaterOutputStream iout = new InflaterOutputStream(out, new Inflater(true)); iout.write(b); iout.finish(); return new String(out.toByteArray(), UTF_8); } catch (IOException e) { throw new SamlException("Unable to inflate string", e); } } }
protected void readCompressedData(byte[] readData) throws IOException { if (readData.length == originalLength) { this.tableData = readData; return; } ByteArrayOutputStream out = new ByteArrayOutputStream(); InflaterOutputStream compressStream = new InflaterOutputStream(out); compressStream.write(readData); compressStream.close(); tableData = out.toByteArray(); }
public static String decompressData(String encdata) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); InflaterOutputStream zos = new InflaterOutputStream(bos); zos.write(getdeBASE64inCodec(encdata)); zos.close(); return new String(bos.toByteArray()); } catch (Exception ex) { ex.printStackTrace(); return "UNZIP_ERR"; } }
public static String decompressData(String encdata, String charset) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); InflaterOutputStream zos = new InflaterOutputStream(bos); zos.write(getdeBASE64inCodec(encdata)); zos.close(); return new String(bos.toByteArray(), charset); } catch (Exception ex) { ex.printStackTrace(); return "UNZIP_ERR"; } }
private JsonNode receiveCompressedMessage() throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(bos); inflaterOutputStream.write(server.getReceivedData()); inflaterOutputStream.close(); return new ObjectMapper().readTree(bos.toByteArray()); }