/** * Flushes the encoder and calls <code>outputStream.flush()</code>. * All buffered pending data will then be decompressible from * the output stream. Calling this function very often may increase * the compressed file size a lot. */ @Override public void flush() throws IOException { out.flush(); }
@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); } }
@Override public void flush() throws IOException { if (!supported) { super.flush(); return; } try { int count; while ((count = (Integer) method.invoke(def, buf, 0, buf.length, flushMethodInt)) != 0) { out.write(buf, 0, count); } } catch (IllegalArgumentException e) { throw new IOException("Can't flush"); } catch (IllegalAccessException e) { throw new IOException("Can't flush"); } catch (InvocationTargetException e) { throw new IOException("Can't flush"); } super.flush(); } };
for (int i = 0; i < bytes.length - size; i += size, count++) { dos.write(bytes, i, size); dos.flush();
try { encodingStream.write(data.array(), data.offset(), data.length()); encodingStream.flush(); return HttpData.of(encodedStream.toByteArray()); } catch (IOException e) {
public static void main(String[] args) throws Exception { FileOutputStream fos = new FileOutputStream("C:\\Users\\vebrpav\\archive.zip"); ZipOutputStream zos = new ZipOutputStream(fos); addDirToZipArchive(zos, new File("C:\\Users\\vebrpav\\Downloads\\"), null); zos.flush(); fos.flush(); zos.close(); fos.close(); }
JAXBElement jaxbElement1 = objectFactory.createRoot(rootType); JAXBElement jaxbElement2 = objectFactory.createRoot(rootType); ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream("xml-file.zip")); // add zip-entry descriptor ZipEntry ze1 = new ZipEntry("xml-file-1.xml"); zos.putNextEntry(ze1); // add zip-entry data marshaller.marshal(jaxbElement1, zos); ZipEntry ze2 = new ZipEntry("xml-file-2.xml"); zos.putNextEntry(ze2); marshaller.marshal(jaxbElement2, zos); zos.flush(); } finally { if (zos != null) { zos.close(); } }
zip.flush(); zip.close();
zip.flush(); zip.close();
gzipStream.flush();
public InputStream toInputStream() { try { os.flush(); return new InflaterInputStream(new ByteArrayInputStream(baos.toByteArray())); } catch (IOException e) { throw new RuntimeException(e); } }
ZipOutputStream zos = new ZipOutputStream(bos); zos.putNextEntry(ze); OutputStreamWriter writer = new OutputStreamWriter(zos, "UTF-8"); XMLWriter.writeXMLToWriter(rs,writer); writer.close(); zos.closeEntry(); zos.flush();
public void writeTo(OutputStream out, Charset charset) { try { os.flush(); // We need to decompress when writing back baos.writeTo(new InflaterOutputStream(out)); } catch (IOException e) { throw new RuntimeException(e); } }
ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream zos = new GZIPOutputStream(baos); zos.write(someText.getBytes()); zos.finish(); zos.flush(); byte[] udpBuffer = baos.toByteArray();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(baos, true); for (char ch = 'a'; ch <= 'z'; ch++) { dos.write(("Hello world").getBytes()); baos2.write(("Hello world").getBytes()); dos.flush(); System.out.println("compressed size = " + baos.toByteArray().length); } dos.close(); System.out.println("After close, compressed size = " + baos.toByteArray().length); System.out.println("uncompressed size = " + baos2.toByteArray().length);
@Override public void finish() throws IOException { deflateOut.finish(); deflateOut.flush(); IOUtils.finishStream(out); } };
@Override public void finish() throws IOException { deflateOut.finish(); deflateOut.flush(); IOUtils.finishStream(out); } };
private byte[] compressData(String jsonData) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(baos, new Deflater(Deflater.BEST_COMPRESSION), true); try { dos.write(jsonData.getBytes()); } finally { dos.flush(); dos.close(); } return baos.toByteArray(); }
public static byte[] toCompressedBytes(@Nonnull final Object obj) throws IOException { FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos); try { toStream(obj, dos); dos.finish(); dos.flush(); return bos.toByteArray_clear(); } finally { IOUtils.closeQuietly(dos); } }
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj) throws IOException { FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(bos); try { toStream(obj, dos); dos.finish(); dos.flush(); return bos.toByteArray_clear(); } finally { IOUtils.closeQuietly(dos); } }