/** * Finishes compression without closing the underlying stream. * <p>No more data can be written to this stream after finishing.</p> * @throws IOException on error */ public void finish() throws IOException { out.finish(); }
/** * Writes any unwritten compressed data to the underlying stream, the closes * all underlying streams. This stream can no longer be used after close() * has been called. * * @throws IOException * If an error occurs while closing the data compression * process. */ @Override public void close() throws IOException { // everything closed here should also be closed in ZipOutputStream.close() if (!def.finished()) { finish(); } def.end(); out.close(); }
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; }
/** * 将普通数据流压缩成zlib到out中 * * @param in zlib数据流 * @param out 输出 * @param level 压缩级别,0~9 */ private static void deflater(InputStream in, OutputStream out, int level) { final DeflaterOutputStream ios = (out instanceof DeflaterOutputStream) ? (DeflaterOutputStream) out : new DeflaterOutputStream(out, new Deflater(level, true)); IoUtil.copy(in, ios); try { ios.finish(); } catch (IOException e) { throw new IORuntimeException(e); } } // ---------------------------------------------------------------------------------------------- Private method end
/** * 将普通数据流压缩成zlib到out中 * * @param in zlib数据流 * @param out 输出 * @param level 压缩级别,0~9 */ private static void deflater(InputStream in, OutputStream out, int level) { final DeflaterOutputStream ios = (out instanceof DeflaterOutputStream) ? (DeflaterOutputStream) out : new DeflaterOutputStream(out, new Deflater(level, true)); IoUtil.copy(in, ios); try { ios.finish(); } catch (IOException e) { throw new IORuntimeException(e); } } // ---------------------------------------------------------------------------------------------- Private method end
/** * Indicates to the stream that all data has been written out, and any GZIP * terminal data can now be written. * * @throws IOException * if an {@code IOException} occurs. */ @Override public void finish() throws IOException { super.finish(); writeLong(crc.getValue()); writeLong(crc.tbytes); }
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(); }
outputStream.finish(); long interval = System.currentTimeMillis() - start; if (interval > 50) {
deflaterOutput.finish(); buffer.endChunk(dataOutput);
deflaterOutput.finish(); buffer.endChunk(dataOutput);
super.finish();
private void addDataToMap(JarInputStream jarInputStream, JarEntry entry) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream); IOUtils.copy(jarInputStream, deflaterOutputStream); deflaterOutputStream.finish(); map.put(entry.getName(), byteArrayOutputStream.toByteArray()); }
public static byte[] deflate(byte[] input, int bufferSize) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(input.length); Deflater def = new Deflater(); DeflaterOutputStream dos = new DeflaterOutputStream(out, def, bufferSize); dos.write(input, 0, input.length); dos.finish(); dos.close(); byte[] ret = out.toByteArray(); out.close(); return ret; }
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 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; }
private byte[] zipCompress(byte[] in) { ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length); DeflaterOutputStream os = new DeflaterOutputStream(baos); try { os.write(in); os.finish(); try { os.close(); } catch (IOException e) { log.error("Close DeflaterOutputStream error", e); } } catch (IOException e) { throw new RuntimeException("IO exception compressing data", e); } finally { try { baos.close(); } catch (IOException e) { log.error("Close ByteArrayOutputStream error", e); } } return baos.toByteArray(); }
@Override public void finish() throws IOException { ensureHeaderIsWritten(); super.finish(); writeFooter(); }
private void writeWholeObjectDeflate(PackOutputStream out, final ObjectToPack otp) throws IOException { final Deflater deflater = deflater(); final ObjectLoader ldr = reader.open(otp, otp.getType()); crc32.reset(); otp.setOffset(out.length()); out.writeHeader(otp, ldr.getSize()); deflater.reset(); DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater); ldr.copyTo(dst); dst.finish(); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, byte[] data, int off, int len) throws IOException { ObjectId id = idFor(type, data, off, len); if (objectMap != null && objectMap.contains(id)) return id; // Ignore unreachable (garbage) objects here. if (checkExisting && db.has(id, true)) return id; long offset = beginObject(type, len); packOut.compress.write(data, off, len); packOut.compress.finish(); return endObject(id, offset); }
/** {@inheritDoc} */ @Override public ObjectId insert(int type, byte[] data, int off, int len) throws IOException { ObjectId id = idFor(type, data, off, len); if (objectMap != null && objectMap.contains(id)) { return id; } // Ignore loose objects, which are potentially unreachable. if (checkExisting && db.hasPackedObject(id)) { return id; } long offset = beginObject(type, len); packOut.compress.write(data, off, len); packOut.compress.finish(); return endObject(id, offset); }