/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION); deflater.setInput(originalBytes); DeflaterOutputStream dfos = new DeflaterOutputStream(baos, deflater); dfos.deflate(); dfos.close(); byte[] compressedBytes = baos.toByteArray(); } catch (IOException ex) { ex.printStrackTrace(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
/** * Compresses {@code byteCount} bytes of data from {@code buf} starting at * {@code offset} and writes it to the underlying stream. * @throws IOException * If an error occurs during writing. */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { if (done) { throw new IOException("attempt to write after finish"); } Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (!def.needsInput()) { throw new IOException(); } def.setInput(buffer, offset, byteCount); deflate(); }
def.finish(); while (!def.finished()) { deflate();