@Override public synchronized void finish() throws IOException { try { flushLastByte(); } catch (IOException ignore) { // If our write failed, then trailer write in finish() will fail // with IOException as well, but it will leave Deflater in more // consistent state. } super.finish(); }
@Override public synchronized void close() throws IOException { try { flushLastByte(); } catch (IOException ignored) { // Ignore. As OutputStream#close() says, the contract of close() // is to close the stream. It does not matter much if the // stream is not writable any more. } super.close(); }
@Override public synchronized void finish() throws IOException { try { flushLastByte(); } catch (IOException ignore) { // If our write failed, then trailer write in finish() will fail // with IOException as well, but it will leave Deflater in more // consistent state. } super.finish(); }
@Override public synchronized void close() throws IOException { try { flushLastByte(); } catch (IOException ignored) { // Ignore. As OutputStream#close() says, the contract of close() // is to close the stream. It does not matter much if the // stream is not writable any more. } super.close(); }
@Override public synchronized void write(int i) throws IOException { flushLastByte(); rememberLastByte((byte) i); }
@Override public synchronized void write(byte[] bytes, int offset, int length) throws IOException { if (length > 0) { flushLastByte(); if (length > 1) { super.write(bytes, offset, length - 1); } rememberLastByte(bytes[offset + length - 1]); } }
@Override public synchronized void write(int i) throws IOException { flushLastByte(); rememberLastByte((byte) i); }
@Override public synchronized void flush() throws IOException { if (hasLastByte) { // - do not allow the gzip header to be flushed on its own // - do not do anything if there is no data to send // trick the deflater to flush /** * Now this is tricky: We force the Deflater to flush its data by * switching compression level. As yet, a perplexingly simple workaround * for * http://developer.java.sun.com/developer/bugParade/bugs/4255743.html */ if (!def.finished()) { def.setLevel(Deflater.NO_COMPRESSION); flushLastByte(); flagReenableCompression = true; } } out.flush(); }
@Override public synchronized void write(byte[] bytes, int offset, int length) throws IOException { if (length > 0) { flushLastByte(); if (length > 1) { reenableCompression(); super.write(bytes, offset, length - 1); } rememberLastByte(bytes[offset + length - 1]); } }
@Override public synchronized void flush() throws IOException { if (hasLastByte) { // - do not allow the gzip header to be flushed on its own // - do not do anything if there is no data to send // trick the deflater to flush /** * Now this is tricky: We force the Deflater to flush its data by * switching compression level. As yet, a perplexingly simple workaround * for * http://developer.java.sun.com/developer/bugParade/bugs/4255743.html */ if (!def.finished()) { def.setLevel(Deflater.NO_COMPRESSION); flushLastByte(); def.setLevel(Deflater.DEFAULT_COMPRESSION); } } out.flush(); }