@Override public void write(byte[] buffer, int offset, int length) throws IOException { _deflateOut.write(buffer, offset, length); }
@Override public void write(int ch) throws IOException { _deflateOut.write(ch); }
@Override public void write(final int b) throws IOException { out.write(b); }
@Override public void write(final byte[] b) throws IOException { deflaterOutputStream.write(b); }
@Override public void write(final int b) throws IOException { deflaterOutputStream.write(b); }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { deflaterOutputStream.write(b, off, len); }
@Override public void write(final byte[] buf, final int off, final int len) throws IOException { out.write(buf, off, len); }
/** * Write up to nbytes of data from the given buffer, starting at offset off, * to the underlying stream in GZIP format. */ @Override public void write(byte[] buffer, int off, int nbytes) throws IOException { super.write(buffer, off, nbytes); crc.update(buffer, off, nbytes); }
@Override public byte[] doCompress(byte[] payload) throws IOException { Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION); ByteArrayOutputStream outputStream = null; DeflaterOutputStream deflaterOutputStream = null; try { outputStream = new ByteArrayOutputStream(); deflaterOutputStream = new DeflaterOutputStream(outputStream, deflater, true); deflaterOutputStream.write(payload, 0, payload.length); deflaterOutputStream.flush(); return outputStream.toByteArray(); } finally { Objects.nullSafeClose(outputStream, deflaterOutputStream); } }
public static byte[] compress(final byte[] src, final int level) throws IOException { byte[] result = src; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length); java.util.zip.Deflater defeater = new java.util.zip.Deflater(level); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater); try { deflaterOutputStream.write(src); deflaterOutputStream.finish(); deflaterOutputStream.close(); result = byteArrayOutputStream.toByteArray(); } catch (IOException e) { defeater.end(); throw e; } finally { try { byteArrayOutputStream.close(); } catch (IOException ignored) { } defeater.end(); } return result; }
public byte[] compress(byte[] in) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Deflater deflater = new Deflater(Deflater.HUFFMAN_ONLY); deflater.setLevel(9); final DeflaterOutputStream gz = new DeflaterOutputStream(baos, deflater); try { gz.write(in); gz.close(); baos.close(); return baos.toByteArray(); } catch (IOException e) { throw new IllegalStateException(e.toString()); } }
public static byte[] compress(byte[] input) throws IOException { // Destination where compressed data will be stored. ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Create a compressor. Deflater deflater = createDeflater(); DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater); // Compress the data. // // Some other implementations such as Jetty and Tyrus use // Deflater.deflate(byte[], int, int, int) with Deflate.SYNC_FLUSH, // but this implementation does not do it intentionally because the // method and the constant value are not available before Java 7. dos.write(input, 0, input.length); dos.close(); // Release the resources held by the compressor. deflater.end(); // Retrieve the compressed data. return baos.toByteArray(); }
outputStream.write(convertIntToByteArray(buffer.length)); outputStream.write(buffer); outputStream.write(convertIntToByteArray(topicNumber)); outputStream.write(convertIntToByteArray(buffer.length)); outputStream.write(buffer); outputStream.write(convertIntToByteArray(buffer.length)); outputStream.write(buffer);
/** * Encodes the specified {@code message} into a deflated base64 string. */ static String toDeflatedBase64(SAMLObject message) { requireNonNull(message, "message"); final String messageStr; try { messageStr = nodeToString(XMLObjectSupport.marshall(message)); } catch (MarshallingException e) { throw new SamlException("failed to serialize a SAML message", e); } final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); try (DeflaterOutputStream deflaterStream = new DeflaterOutputStream(Base64.getEncoder().wrap(bytesOut), new Deflater(Deflater.DEFLATED, true))) { deflaterStream.write(messageStr.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { throw new SamlException("failed to deflate a SAML message", e); } return bytesOut.toString(); }
/** * Writes data for the current entry to the underlying stream. * * @exception IOException * If an error occurs writing to the stream */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (currentEntry == null) { throw new ZipException("No active entry"); } if (currentEntry.getMethod() == STORED) { out.write(buffer, offset, byteCount); } else { super.write(buffer, offset, byteCount); } crc.update(buffer, offset, byteCount); }
public static byte[] compress(byte[] data) { Profiler.enter("time cost on [compress]"); ByteArrayOutputStream out = new ByteArrayOutputStream(data.length / 4); DeflaterOutputStream zipOut = new DeflaterOutputStream(out); try { zipOut.write(data); zipOut.finish(); zipOut.close(); } catch (IOException e) { LOGGER.error("compress ex", e); return Constants.EMPTY_BYTES; } finally { close(zipOut); Profiler.release(); } return out.toByteArray(); }
int size = 5 * 1024; for (int i = 0; i < bytes.length - size; i += size, count++) { dos.write(bytes, i, size); dos.flush();
@Override public void setPictureData(byte[] pictureData) { super.setPictureData(pictureData); setUncompressedSize(pictureData.length); // info of chicago project: // "... LZ compression algorithm in the format used by GNU Zip deflate/inflate with a 32k window ..." // not sure what to do, when lookup tables exceed 32k ... try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos); dos.write(pictureData); dos.close(); raw_pictureData = bos.toByteArray(); } catch (IOException e) { throw new RuntimeException("Can't compress metafile picture data", e); } setCompressedSize(raw_pictureData.length); setCompressed(true); }