equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
99 * the 4-argument constructor DeflaterOutputStream(out, def, size, false). |
99 * the 4-argument constructor DeflaterOutputStream(out, def, size, false). |
100 * |
100 * |
101 * @param out the output stream |
101 * @param out the output stream |
102 * @param def the compressor ("deflater") |
102 * @param def the compressor ("deflater") |
103 * @param size the output buffer size |
103 * @param size the output buffer size |
104 * @exception IllegalArgumentException if {@code size <= 0} |
104 * @throws IllegalArgumentException if {@code size <= 0} |
105 */ |
105 */ |
106 public DeflaterOutputStream(OutputStream out, Deflater def, int size) { |
106 public DeflaterOutputStream(OutputStream out, Deflater def, int size) { |
107 this(out, def, size, false); |
107 this(out, def, size, false); |
108 } |
108 } |
109 |
109 |
178 |
178 |
179 /** |
179 /** |
180 * Writes a byte to the compressed output stream. This method will |
180 * Writes a byte to the compressed output stream. This method will |
181 * block until the byte can be written. |
181 * block until the byte can be written. |
182 * @param b the byte to be written |
182 * @param b the byte to be written |
183 * @exception IOException if an I/O error has occurred |
183 * @throws IOException if an I/O error has occurred |
184 */ |
184 */ |
185 public void write(int b) throws IOException { |
185 public void write(int b) throws IOException { |
186 byte[] buf = new byte[1]; |
186 byte[] buf = new byte[1]; |
187 buf[0] = (byte)(b & 0xff); |
187 buf[0] = (byte)(b & 0xff); |
188 write(buf, 0, 1); |
188 write(buf, 0, 1); |
192 * Writes an array of bytes to the compressed output stream. This |
192 * Writes an array of bytes to the compressed output stream. This |
193 * method will block until all the bytes are written. |
193 * method will block until all the bytes are written. |
194 * @param b the data to be written |
194 * @param b the data to be written |
195 * @param off the start offset of the data |
195 * @param off the start offset of the data |
196 * @param len the length of the data |
196 * @param len the length of the data |
197 * @exception IOException if an I/O error has occurred |
197 * @throws IOException if an I/O error has occurred |
198 */ |
198 */ |
199 public void write(byte[] b, int off, int len) throws IOException { |
199 public void write(byte[] b, int off, int len) throws IOException { |
200 if (def.finished()) { |
200 if (def.finished()) { |
201 throw new IOException("write beyond end of stream"); |
201 throw new IOException("write beyond end of stream"); |
202 } |
202 } |
215 |
215 |
216 /** |
216 /** |
217 * Finishes writing compressed data to the output stream without closing |
217 * Finishes writing compressed data to the output stream without closing |
218 * the underlying stream. Use this method when applying multiple filters |
218 * the underlying stream. Use this method when applying multiple filters |
219 * in succession to the same output stream. |
219 * in succession to the same output stream. |
220 * @exception IOException if an I/O error has occurred |
220 * @throws IOException if an I/O error has occurred |
221 */ |
221 */ |
222 public void finish() throws IOException { |
222 public void finish() throws IOException { |
223 if (!def.finished()) { |
223 if (!def.finished()) { |
224 def.finish(); |
224 def.finish(); |
225 while (!def.finished()) { |
225 while (!def.finished()) { |
229 } |
229 } |
230 |
230 |
231 /** |
231 /** |
232 * Writes remaining compressed data to the output stream and closes the |
232 * Writes remaining compressed data to the output stream and closes the |
233 * underlying stream. |
233 * underlying stream. |
234 * @exception IOException if an I/O error has occurred |
234 * @throws IOException if an I/O error has occurred |
235 */ |
235 */ |
236 public void close() throws IOException { |
236 public void close() throws IOException { |
237 if (!closed) { |
237 if (!closed) { |
238 finish(); |
238 finish(); |
239 if (usesDefaultDeflater) |
239 if (usesDefaultDeflater) |