author | avstepan |
Thu, 06 Aug 2015 19:07:35 +0300 | |
changeset 32037 | ab4526f4ac10 |
parent 25859 | 3317bb8137f4 |
child 45434 | 4582657c7260 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18156
diff
changeset
|
2 |
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.zip; |
|
27 |
||
28 |
import java.io.FilterOutputStream; |
|
29 |
import java.io.OutputStream; |
|
30 |
import java.io.InputStream; |
|
31 |
import java.io.IOException; |
|
32 |
||
33 |
/** |
|
34 |
* This class implements an output stream filter for compressing data in |
|
35 |
* the "deflate" compression format. It is also used as the basis for other |
|
36 |
* types of compression filters, such as GZIPOutputStream. |
|
37 |
* |
|
38 |
* @see Deflater |
|
39 |
* @author David Connelly |
|
40 |
*/ |
|
41 |
public |
|
42 |
class DeflaterOutputStream extends FilterOutputStream { |
|
43 |
/** |
|
44 |
* Compressor for this stream. |
|
45 |
*/ |
|
46 |
protected Deflater def; |
|
47 |
||
48 |
/** |
|
49 |
* Output buffer for writing compressed data. |
|
50 |
*/ |
|
51 |
protected byte[] buf; |
|
52 |
||
53 |
/** |
|
54 |
* Indicates that the stream has been closed. |
|
55 |
*/ |
|
56 |
||
57 |
private boolean closed = false; |
|
58 |
||
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
59 |
private final boolean syncFlush; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
60 |
|
2 | 61 |
/** |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
62 |
* Creates a new output stream with the specified compressor, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
63 |
* buffer size and flush mode. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
64 |
|
2 | 65 |
* @param out the output stream |
66 |
* @param def the compressor ("deflater") |
|
67 |
* @param size the output buffer size |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
68 |
* @param syncFlush |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
69 |
* if {@code true} the {@link #flush()} method of this |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
70 |
* instance flushes the compressor with flush mode |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
71 |
* {@link Deflater#SYNC_FLUSH} before flushing the output |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
72 |
* stream, otherwise only flushes the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
73 |
* |
18156 | 74 |
* @throws IllegalArgumentException if {@code size <= 0} |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
75 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
76 |
* @since 1.7 |
2 | 77 |
*/ |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
78 |
public DeflaterOutputStream(OutputStream out, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
79 |
Deflater def, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
80 |
int size, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
81 |
boolean syncFlush) { |
2 | 82 |
super(out); |
83 |
if (out == null || def == null) { |
|
84 |
throw new NullPointerException(); |
|
85 |
} else if (size <= 0) { |
|
86 |
throw new IllegalArgumentException("buffer size <= 0"); |
|
87 |
} |
|
88 |
this.def = def; |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
89 |
this.buf = new byte[size]; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
90 |
this.syncFlush = syncFlush; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
91 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
92 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
93 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
94 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
95 |
* Creates a new output stream with the specified compressor and |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
96 |
* buffer size. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
97 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
98 |
* <p>The new output stream instance is created as if by invoking |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
99 |
* the 4-argument constructor DeflaterOutputStream(out, def, size, false). |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
100 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
101 |
* @param out the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
102 |
* @param def the compressor ("deflater") |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
103 |
* @param size the output buffer size |
18156 | 104 |
* @exception IllegalArgumentException if {@code size <= 0} |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
105 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
106 |
public DeflaterOutputStream(OutputStream out, Deflater def, int size) { |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
107 |
this(out, def, size, false); |
2 | 108 |
} |
109 |
||
110 |
/** |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
111 |
* Creates a new output stream with the specified compressor, flush |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
112 |
* mode and a default buffer size. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
113 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
114 |
* @param out the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
115 |
* @param def the compressor ("deflater") |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
116 |
* @param syncFlush |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
117 |
* if {@code true} the {@link #flush()} method of this |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
118 |
* instance flushes the compressor with flush mode |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
119 |
* {@link Deflater#SYNC_FLUSH} before flushing the output |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
120 |
* stream, otherwise only flushes the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
121 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
122 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
123 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
124 |
public DeflaterOutputStream(OutputStream out, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
125 |
Deflater def, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
126 |
boolean syncFlush) { |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
127 |
this(out, def, 512, syncFlush); |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
128 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
129 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
130 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
131 |
/** |
2 | 132 |
* Creates a new output stream with the specified compressor and |
133 |
* a default buffer size. |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
134 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
135 |
* <p>The new output stream instance is created as if by invoking |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
136 |
* the 3-argument constructor DeflaterOutputStream(out, def, false). |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
137 |
* |
2 | 138 |
* @param out the output stream |
139 |
* @param def the compressor ("deflater") |
|
140 |
*/ |
|
141 |
public DeflaterOutputStream(OutputStream out, Deflater def) { |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
142 |
this(out, def, 512, false); |
2 | 143 |
} |
144 |
||
145 |
boolean usesDefaultDeflater = false; |
|
146 |
||
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
147 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
148 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
149 |
* Creates a new output stream with a default compressor, a default |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
150 |
* buffer size and the specified flush mode. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
151 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
152 |
* @param out the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
153 |
* @param syncFlush |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
154 |
* if {@code true} the {@link #flush()} method of this |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
155 |
* instance flushes the compressor with flush mode |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
156 |
* {@link Deflater#SYNC_FLUSH} before flushing the output |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
157 |
* stream, otherwise only flushes the output stream |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
158 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
159 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
160 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
161 |
public DeflaterOutputStream(OutputStream out, boolean syncFlush) { |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
162 |
this(out, new Deflater(), 512, syncFlush); |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
163 |
usesDefaultDeflater = true; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
164 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
165 |
|
2 | 166 |
/** |
167 |
* Creates a new output stream with a default compressor and buffer size. |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
168 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
169 |
* <p>The new output stream instance is created as if by invoking |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
170 |
* the 2-argument constructor DeflaterOutputStream(out, false). |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
171 |
* |
2 | 172 |
* @param out the output stream |
173 |
*/ |
|
174 |
public DeflaterOutputStream(OutputStream out) { |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
175 |
this(out, false); |
2 | 176 |
usesDefaultDeflater = true; |
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Writes a byte to the compressed output stream. This method will |
|
181 |
* block until the byte can be written. |
|
182 |
* @param b the byte to be written |
|
183 |
* @exception IOException if an I/O error has occurred |
|
184 |
*/ |
|
185 |
public void write(int b) throws IOException { |
|
186 |
byte[] buf = new byte[1]; |
|
187 |
buf[0] = (byte)(b & 0xff); |
|
188 |
write(buf, 0, 1); |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Writes an array of bytes to the compressed output stream. This |
|
193 |
* method will block until all the bytes are written. |
|
194 |
* @param b the data to be written |
|
195 |
* @param off the start offset of the data |
|
196 |
* @param len the length of the data |
|
197 |
* @exception IOException if an I/O error has occurred |
|
198 |
*/ |
|
199 |
public void write(byte[] b, int off, int len) throws IOException { |
|
200 |
if (def.finished()) { |
|
201 |
throw new IOException("write beyond end of stream"); |
|
202 |
} |
|
203 |
if ((off | len | (off + len) | (b.length - (off + len))) < 0) { |
|
204 |
throw new IndexOutOfBoundsException(); |
|
205 |
} else if (len == 0) { |
|
206 |
return; |
|
207 |
} |
|
208 |
if (!def.finished()) { |
|
9023 | 209 |
def.setInput(b, off, len); |
210 |
while (!def.needsInput()) { |
|
211 |
deflate(); |
|
2 | 212 |
} |
213 |
} |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Finishes writing compressed data to the output stream without closing |
|
218 |
* the underlying stream. Use this method when applying multiple filters |
|
219 |
* in succession to the same output stream. |
|
220 |
* @exception IOException if an I/O error has occurred |
|
221 |
*/ |
|
222 |
public void finish() throws IOException { |
|
223 |
if (!def.finished()) { |
|
224 |
def.finish(); |
|
225 |
while (!def.finished()) { |
|
226 |
deflate(); |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* Writes remaining compressed data to the output stream and closes the |
|
233 |
* underlying stream. |
|
234 |
* @exception IOException if an I/O error has occurred |
|
235 |
*/ |
|
236 |
public void close() throws IOException { |
|
237 |
if (!closed) { |
|
238 |
finish(); |
|
239 |
if (usesDefaultDeflater) |
|
240 |
def.end(); |
|
241 |
out.close(); |
|
242 |
closed = true; |
|
243 |
} |
|
244 |
} |
|
245 |
||
246 |
/** |
|
247 |
* Writes next block of compressed data to the output stream. |
|
248 |
* @throws IOException if an I/O error has occurred |
|
249 |
*/ |
|
250 |
protected void deflate() throws IOException { |
|
251 |
int len = def.deflate(buf, 0, buf.length); |
|
252 |
if (len > 0) { |
|
253 |
out.write(buf, 0, len); |
|
254 |
} |
|
255 |
} |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
256 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
257 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
258 |
* Flushes the compressed output stream. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
259 |
* |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
260 |
* If {@link #DeflaterOutputStream(OutputStream, Deflater, int, boolean) |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
261 |
* syncFlush} is {@code true} when this compressed output stream is |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
262 |
* constructed, this method first flushes the underlying {@code compressor} |
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4162
diff
changeset
|
263 |
* with the flush mode {@link Deflater#SYNC_FLUSH} to force |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
264 |
* all pending data to be flushed out to the output stream and then |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
265 |
* flushes the output stream. Otherwise this method only flushes the |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
266 |
* output stream without flushing the {@code compressor}. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
267 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
268 |
* @throws IOException if an I/O error has occurred |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
269 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
270 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
271 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
272 |
public void flush() throws IOException { |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
273 |
if (syncFlush && !def.finished()) { |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
274 |
int len = 0; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
275 |
while ((len = def.deflate(buf, 0, buf.length, Deflater.SYNC_FLUSH)) > 0) |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
276 |
{ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
277 |
out.write(buf, 0, len); |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
278 |
if (len < buf.length) |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
279 |
break; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
280 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
281 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
282 |
out.flush(); |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2
diff
changeset
|
283 |
} |
2 | 284 |
} |