author | jjg |
Mon, 03 Dec 2018 16:14:15 -0800 | |
changeset 52807 | bbf85239e37c |
parent 52305 | 52a97e06a5e3 |
child 58242 | 94bb65cb37d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
2 |
* Copyright (c) 1996, 2018, 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 |
||
48337
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
28 |
import java.lang.ref.Cleaner.Cleanable; |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
29 |
import java.lang.ref.Reference; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
30 |
import java.nio.ByteBuffer; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
31 |
import java.nio.ReadOnlyBufferException; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
32 |
import java.util.Objects; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
33 |
|
48337
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
34 |
import jdk.internal.ref.CleanerFactory; |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
35 |
import sun.nio.ch.DirectBuffer; |
48337
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
36 |
|
2 | 37 |
/** |
38 |
* This class provides support for general purpose compression using the |
|
39 |
* popular ZLIB compression library. The ZLIB compression library was |
|
40 |
* initially developed as part of the PNG graphics standard and is not |
|
41 |
* protected by patents. It is fully described in the specifications at |
|
47004 | 42 |
* the <a href="package-summary.html#package.description">java.util.zip |
2 | 43 |
* package description</a>. |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
44 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
45 |
* This class deflates sequences of bytes into ZLIB compressed data format. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
46 |
* The input byte sequence is provided in either byte array or byte buffer, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
47 |
* via one of the {@code setInput()} methods. The output byte sequence is |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
48 |
* written to the output byte array or byte buffer passed to the |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
49 |
* {@code deflate()} methods. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
50 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
51 |
* The following code fragment demonstrates a trivial compression |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
52 |
* and decompression of a string using {@code Deflater} and |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
25859
diff
changeset
|
53 |
* {@code Inflater}. |
2 | 54 |
* |
55 |
* <blockquote><pre> |
|
56 |
* try { |
|
57 |
* // Encode a String into bytes |
|
5469 | 58 |
* String inputString = "blahblahblah"; |
2 | 59 |
* byte[] input = inputString.getBytes("UTF-8"); |
60 |
* |
|
61 |
* // Compress the bytes |
|
62 |
* byte[] output = new byte[100]; |
|
63 |
* Deflater compresser = new Deflater(); |
|
64 |
* compresser.setInput(input); |
|
65 |
* compresser.finish(); |
|
66 |
* int compressedDataLength = compresser.deflate(output); |
|
2940 | 67 |
* compresser.end(); |
2 | 68 |
* |
69 |
* // Decompress the bytes |
|
70 |
* Inflater decompresser = new Inflater(); |
|
71 |
* decompresser.setInput(output, 0, compressedDataLength); |
|
72 |
* byte[] result = new byte[100]; |
|
73 |
* int resultLength = decompresser.inflate(result); |
|
74 |
* decompresser.end(); |
|
75 |
* |
|
76 |
* // Decode the bytes into a String |
|
77 |
* String outputString = new String(result, 0, resultLength, "UTF-8"); |
|
50238
a9307f400f5a
8203328: Rename EFS in java.util.zip internals to something meaningful
martin
parents:
49834
diff
changeset
|
78 |
* } catch (java.io.UnsupportedEncodingException ex) { |
2 | 79 |
* // handle |
80 |
* } catch (java.util.zip.DataFormatException ex) { |
|
81 |
* // handle |
|
82 |
* } |
|
83 |
* </pre></blockquote> |
|
84 |
* |
|
48238
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
85 |
* @apiNote |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
86 |
* To release resources used by this {@code Deflater}, the {@link #end()} method |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
87 |
* should be called explicitly. Subclasses are responsible for the cleanup of resources |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
88 |
* acquired by the subclass. Subclasses that override {@link #finalize()} in order |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
89 |
* to perform cleanup should be modified to use alternative cleanup mechanisms such |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
90 |
* as {@link java.lang.ref.Cleaner} and remove the overriding {@code finalize} method. |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
91 |
* |
2 | 92 |
* @see Inflater |
93 |
* @author David Connelly |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
44534
diff
changeset
|
94 |
* @since 1.1 |
2 | 95 |
*/ |
48238
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
96 |
|
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
97 |
public class Deflater { |
5173 | 98 |
|
48337
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
99 |
private final DeflaterZStreamRef zsRef; |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
100 |
private ByteBuffer input = ZipUtils.defaultBuf; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
101 |
private byte[] inputArray; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
102 |
private int inputPos, inputLim; |
2 | 103 |
private int level, strategy; |
104 |
private boolean setParams; |
|
105 |
private boolean finish, finished; |
|
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
106 |
private long bytesRead; |
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
107 |
private long bytesWritten; |
2 | 108 |
|
109 |
/** |
|
110 |
* Compression method for the deflate algorithm (the only one currently |
|
111 |
* supported). |
|
112 |
*/ |
|
113 |
public static final int DEFLATED = 8; |
|
114 |
||
115 |
/** |
|
116 |
* Compression level for no compression. |
|
117 |
*/ |
|
118 |
public static final int NO_COMPRESSION = 0; |
|
119 |
||
120 |
/** |
|
121 |
* Compression level for fastest compression. |
|
122 |
*/ |
|
123 |
public static final int BEST_SPEED = 1; |
|
124 |
||
125 |
/** |
|
126 |
* Compression level for best compression. |
|
127 |
*/ |
|
128 |
public static final int BEST_COMPRESSION = 9; |
|
129 |
||
130 |
/** |
|
131 |
* Default compression level. |
|
132 |
*/ |
|
133 |
public static final int DEFAULT_COMPRESSION = -1; |
|
134 |
||
135 |
/** |
|
136 |
* Compression strategy best used for data consisting mostly of small |
|
137 |
* values with a somewhat random distribution. Forces more Huffman coding |
|
138 |
* and less string matching. |
|
139 |
*/ |
|
140 |
public static final int FILTERED = 1; |
|
141 |
||
142 |
/** |
|
143 |
* Compression strategy for Huffman coding only. |
|
144 |
*/ |
|
145 |
public static final int HUFFMAN_ONLY = 2; |
|
146 |
||
147 |
/** |
|
148 |
* Default compression strategy. |
|
149 |
*/ |
|
150 |
public static final int DEFAULT_STRATEGY = 0; |
|
151 |
||
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
152 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
153 |
* Compression flush mode used to achieve best compression result. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
154 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
155 |
* @see Deflater#deflate(byte[], int, int, int) |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
156 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
157 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
158 |
public static final int NO_FLUSH = 0; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
159 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
160 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
161 |
* Compression flush mode used to flush out all pending output; may |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
162 |
* degrade compression for some compression algorithms. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
163 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
164 |
* @see Deflater#deflate(byte[], int, int, int) |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
165 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
166 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
167 |
public static final int SYNC_FLUSH = 2; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
168 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
169 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
170 |
* Compression flush mode used to flush out all pending output and |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
171 |
* reset the deflater. Using this mode too often can seriously degrade |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
172 |
* compression. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
173 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
174 |
* @see Deflater#deflate(byte[], int, int, int) |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
175 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
176 |
*/ |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
177 |
public static final int FULL_FLUSH = 3; |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
178 |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
179 |
/** |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
180 |
* Flush mode to use at the end of output. Can only be provided by the |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
181 |
* user by way of {@link #finish()}. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
182 |
*/ |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
183 |
private static final int FINISH = 4; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
184 |
|
2 | 185 |
static { |
45924
8bbd04c0791e
8184917: System.initPhase1 does not need to pre-load libzip
alanb
parents:
45434
diff
changeset
|
186 |
ZipUtils.loadLibrary(); |
2 | 187 |
} |
188 |
||
189 |
/** |
|
190 |
* Creates a new compressor using the specified compression level. |
|
191 |
* If 'nowrap' is true then the ZLIB header and checksum fields will |
|
192 |
* not be used in order to support the compression format used in |
|
193 |
* both GZIP and PKZIP. |
|
194 |
* @param level the compression level (0-9) |
|
195 |
* @param nowrap if true then use GZIP compatible compression |
|
196 |
*/ |
|
197 |
public Deflater(int level, boolean nowrap) { |
|
198 |
this.level = level; |
|
199 |
this.strategy = DEFAULT_STRATEGY; |
|
52305
52a97e06a5e3
8212129: Remove finalize methods from java.util.zip.ZipFIle/Inflator/Deflator
lancea
parents:
50238
diff
changeset
|
200 |
this.zsRef = new DeflaterZStreamRef(this, |
52a97e06a5e3
8212129: Remove finalize methods from java.util.zip.ZipFIle/Inflator/Deflator
lancea
parents:
50238
diff
changeset
|
201 |
init(level, DEFAULT_STRATEGY, nowrap)); |
2 | 202 |
} |
203 |
||
204 |
/** |
|
205 |
* Creates a new compressor using the specified compression level. |
|
206 |
* Compressed data will be generated in ZLIB format. |
|
207 |
* @param level the compression level (0-9) |
|
208 |
*/ |
|
209 |
public Deflater(int level) { |
|
210 |
this(level, false); |
|
211 |
} |
|
212 |
||
213 |
/** |
|
214 |
* Creates a new compressor with the default compression level. |
|
215 |
* Compressed data will be generated in ZLIB format. |
|
216 |
*/ |
|
217 |
public Deflater() { |
|
218 |
this(DEFAULT_COMPRESSION, false); |
|
219 |
} |
|
220 |
||
221 |
/** |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
222 |
* Sets input data for compression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
223 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
224 |
* One of the {@code setInput()} methods should be called whenever |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
225 |
* {@code needsInput()} returns true indicating that more input data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
226 |
* is required. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
227 |
* @param input the input data bytes |
2 | 228 |
* @param off the start offset of the data |
229 |
* @param len the length of the data |
|
230 |
* @see Deflater#needsInput |
|
231 |
*/ |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
232 |
public void setInput(byte[] input, int off, int len) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
233 |
if (off < 0 || len < 0 || off > input.length - len) { |
2 | 234 |
throw new ArrayIndexOutOfBoundsException(); |
235 |
} |
|
5173 | 236 |
synchronized (zsRef) { |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
237 |
this.input = null; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
238 |
this.inputArray = input; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
239 |
this.inputPos = off; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
240 |
this.inputLim = off + len; |
5173 | 241 |
} |
2 | 242 |
} |
243 |
||
244 |
/** |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
245 |
* Sets input data for compression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
246 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
247 |
* One of the {@code setInput()} methods should be called whenever |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
248 |
* {@code needsInput()} returns true indicating that more input data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
249 |
* is required. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
250 |
* @param input the input data bytes |
2 | 251 |
* @see Deflater#needsInput |
252 |
*/ |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
253 |
public void setInput(byte[] input) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
254 |
setInput(input, 0, input.length); |
2 | 255 |
} |
256 |
||
257 |
/** |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
258 |
* Sets input data for compression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
259 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
260 |
* One of the {@code setInput()} methods should be called whenever |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
261 |
* {@code needsInput()} returns true indicating that more input data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
262 |
* is required. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
263 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
264 |
* The given buffer's position will be advanced as deflate |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
265 |
* operations are performed, up to the buffer's limit. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
266 |
* The input buffer may be modified (refilled) between deflate |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
267 |
* operations; doing so is equivalent to creating a new buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
268 |
* and setting it with this method. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
269 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
270 |
* Modifying the input buffer's contents, position, or limit |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
271 |
* concurrently with an deflate operation will result in |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
272 |
* undefined behavior, which may include incorrect operation |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
273 |
* results or operation failure. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
274 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
275 |
* @param input the input data bytes |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
276 |
* @see Deflater#needsInput |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
277 |
* @since 11 |
2 | 278 |
*/ |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
279 |
public void setInput(ByteBuffer input) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
280 |
Objects.requireNonNull(input); |
5173 | 281 |
synchronized (zsRef) { |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
282 |
this.input = input; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
283 |
this.inputArray = null; |
5173 | 284 |
} |
2 | 285 |
} |
286 |
||
287 |
/** |
|
288 |
* Sets preset dictionary for compression. A preset dictionary is used |
|
289 |
* when the history buffer can be predetermined. When the data is later |
|
290 |
* uncompressed with Inflater.inflate(), Inflater.getAdler() can be called |
|
291 |
* in order to get the Adler-32 value of the dictionary required for |
|
292 |
* decompression. |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
293 |
* @param dictionary the dictionary data bytes |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
294 |
* @param off the start offset of the data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
295 |
* @param len the length of the data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
296 |
* @see Inflater#inflate |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
297 |
* @see Inflater#getAdler |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
298 |
*/ |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
299 |
public void setDictionary(byte[] dictionary, int off, int len) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
300 |
if (off < 0 || len < 0 || off > dictionary.length - len) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
301 |
throw new ArrayIndexOutOfBoundsException(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
302 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
303 |
synchronized (zsRef) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
304 |
ensureOpen(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
305 |
setDictionary(zsRef.address(), dictionary, off, len); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
306 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
307 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
308 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
309 |
/** |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
310 |
* Sets preset dictionary for compression. A preset dictionary is used |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
311 |
* when the history buffer can be predetermined. When the data is later |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
312 |
* uncompressed with Inflater.inflate(), Inflater.getAdler() can be called |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
313 |
* in order to get the Adler-32 value of the dictionary required for |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
314 |
* decompression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
315 |
* @param dictionary the dictionary data bytes |
2 | 316 |
* @see Inflater#inflate |
317 |
* @see Inflater#getAdler |
|
318 |
*/ |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
319 |
public void setDictionary(byte[] dictionary) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
320 |
setDictionary(dictionary, 0, dictionary.length); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
321 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
322 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
323 |
/** |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
324 |
* Sets preset dictionary for compression. A preset dictionary is used |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
325 |
* when the history buffer can be predetermined. When the data is later |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
326 |
* uncompressed with Inflater.inflate(), Inflater.getAdler() can be called |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
327 |
* in order to get the Adler-32 value of the dictionary required for |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
328 |
* decompression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
329 |
* <p> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
330 |
* The bytes in given byte buffer will be fully consumed by this method. On |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
331 |
* return, its position will equal its limit. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
332 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
333 |
* @param dictionary the dictionary data bytes |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
334 |
* @see Inflater#inflate |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
335 |
* @see Inflater#getAdler |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
336 |
*/ |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
337 |
public void setDictionary(ByteBuffer dictionary) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
338 |
synchronized (zsRef) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
339 |
int position = dictionary.position(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
340 |
int remaining = Math.max(dictionary.limit() - position, 0); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
341 |
ensureOpen(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
342 |
if (dictionary.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
343 |
long address = ((DirectBuffer) dictionary).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
344 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
345 |
setDictionaryBuffer(zsRef.address(), address + position, remaining); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
346 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
347 |
Reference.reachabilityFence(dictionary); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
348 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
349 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
350 |
byte[] array = ZipUtils.getBufferArray(dictionary); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
351 |
int offset = ZipUtils.getBufferOffset(dictionary); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
352 |
setDictionary(zsRef.address(), array, offset + position, remaining); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
353 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
354 |
dictionary.position(position + remaining); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
355 |
} |
2 | 356 |
} |
357 |
||
358 |
/** |
|
359 |
* Sets the compression strategy to the specified value. |
|
19865
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
360 |
* |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
361 |
* <p> If the compression strategy is changed, the next invocation |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
362 |
* of {@code deflate} will compress the input available so far with |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
363 |
* the old strategy (and may be flushed); the new strategy will take |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
364 |
* effect only after that invocation. |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
365 |
* |
2 | 366 |
* @param strategy the new compression strategy |
367 |
* @exception IllegalArgumentException if the compression strategy is |
|
368 |
* invalid |
|
369 |
*/ |
|
5173 | 370 |
public void setStrategy(int strategy) { |
2 | 371 |
switch (strategy) { |
372 |
case DEFAULT_STRATEGY: |
|
373 |
case FILTERED: |
|
374 |
case HUFFMAN_ONLY: |
|
375 |
break; |
|
376 |
default: |
|
377 |
throw new IllegalArgumentException(); |
|
378 |
} |
|
5173 | 379 |
synchronized (zsRef) { |
380 |
if (this.strategy != strategy) { |
|
381 |
this.strategy = strategy; |
|
382 |
setParams = true; |
|
383 |
} |
|
2 | 384 |
} |
385 |
} |
|
386 |
||
387 |
/** |
|
19865
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
388 |
* Sets the compression level to the specified value. |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
389 |
* |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
390 |
* <p> If the compression level is changed, the next invocation |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
391 |
* of {@code deflate} will compress the input available so far |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
392 |
* with the old level (and may be flushed); the new level will |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
393 |
* take effect only after that invocation. |
b68185846a71
8020687: Deflater.setLevel does not work as expected
sherman
parents:
18560
diff
changeset
|
394 |
* |
2 | 395 |
* @param level the new compression level (0-9) |
396 |
* @exception IllegalArgumentException if the compression level is invalid |
|
397 |
*/ |
|
5173 | 398 |
public void setLevel(int level) { |
2 | 399 |
if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) { |
400 |
throw new IllegalArgumentException("invalid compression level"); |
|
401 |
} |
|
5173 | 402 |
synchronized (zsRef) { |
403 |
if (this.level != level) { |
|
404 |
this.level = level; |
|
405 |
setParams = true; |
|
406 |
} |
|
2 | 407 |
} |
408 |
} |
|
409 |
||
410 |
/** |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
411 |
* Returns true if no data remains in the input buffer. This can |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
412 |
* be used to determine if one of the {@code setInput()} methods should be |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
413 |
* called in order to provide more input. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
414 |
* |
2 | 415 |
* @return true if the input data buffer is empty and setInput() |
416 |
* should be called in order to provide more input |
|
417 |
*/ |
|
418 |
public boolean needsInput() { |
|
32995
a62c89adce3d
8038502: Deflater.needsInput() should use synchronization
coffeys
parents:
32649
diff
changeset
|
419 |
synchronized (zsRef) { |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
420 |
ByteBuffer input = this.input; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
421 |
return input == null ? inputLim == inputPos : ! input.hasRemaining(); |
32995
a62c89adce3d
8038502: Deflater.needsInput() should use synchronization
coffeys
parents:
32649
diff
changeset
|
422 |
} |
2 | 423 |
} |
424 |
||
425 |
/** |
|
426 |
* When called, indicates that compression should end with the current |
|
427 |
* contents of the input buffer. |
|
428 |
*/ |
|
5173 | 429 |
public void finish() { |
430 |
synchronized (zsRef) { |
|
431 |
finish = true; |
|
432 |
} |
|
2 | 433 |
} |
434 |
||
435 |
/** |
|
436 |
* Returns true if the end of the compressed data output stream has |
|
437 |
* been reached. |
|
438 |
* @return true if the end of the compressed data output stream has |
|
439 |
* been reached |
|
440 |
*/ |
|
5173 | 441 |
public boolean finished() { |
442 |
synchronized (zsRef) { |
|
443 |
return finished; |
|
444 |
} |
|
2 | 445 |
} |
446 |
||
447 |
/** |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
448 |
* Compresses the input data and fills specified buffer with compressed |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
449 |
* data. Returns actual number of bytes of compressed data. A return value |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4178
diff
changeset
|
450 |
* of 0 indicates that {@link #needsInput() needsInput} should be called |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
451 |
* in order to determine if more input data is required. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
452 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
453 |
* <p>This method uses {@link #NO_FLUSH} as its compression flush mode. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
454 |
* An invocation of this method of the form {@code deflater.deflate(b, off, len)} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
455 |
* yields the same result as the invocation of |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
456 |
* {@code deflater.deflate(b, off, len, Deflater.NO_FLUSH)}. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
457 |
* |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
458 |
* @param output the buffer for the compressed data |
2 | 459 |
* @param off the start offset of the data |
460 |
* @param len the maximum number of bytes of compressed data |
|
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
461 |
* @return the actual number of bytes of compressed data written to the |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
462 |
* output buffer |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
463 |
*/ |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
464 |
public int deflate(byte[] output, int off, int len) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
465 |
return deflate(output, off, len, NO_FLUSH); |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
466 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
467 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
468 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
469 |
* Compresses the input data and fills specified buffer with compressed |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
470 |
* data. Returns actual number of bytes of compressed data. A return value |
4354
3a70dde80b3b
6905029: Broken links in Deflater and DeflaterOutputStream javadoc
martin
parents:
4178
diff
changeset
|
471 |
* of 0 indicates that {@link #needsInput() needsInput} should be called |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
472 |
* in order to determine if more input data is required. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
473 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
474 |
* <p>This method uses {@link #NO_FLUSH} as its compression flush mode. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
475 |
* An invocation of this method of the form {@code deflater.deflate(b)} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
476 |
* yields the same result as the invocation of |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
477 |
* {@code deflater.deflate(b, 0, b.length, Deflater.NO_FLUSH)}. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
478 |
* |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
479 |
* @param output the buffer for the compressed data |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
480 |
* @return the actual number of bytes of compressed data written to the |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
481 |
* output buffer |
2 | 482 |
*/ |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
483 |
public int deflate(byte[] output) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
484 |
return deflate(output, 0, output.length, NO_FLUSH); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
485 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
486 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
487 |
/** |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
488 |
* Compresses the input data and fills specified buffer with compressed |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
489 |
* data. Returns actual number of bytes of compressed data. A return value |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
490 |
* of 0 indicates that {@link #needsInput() needsInput} should be called |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
491 |
* in order to determine if more input data is required. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
492 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
493 |
* <p>This method uses {@link #NO_FLUSH} as its compression flush mode. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
494 |
* An invocation of this method of the form {@code deflater.deflate(output)} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
495 |
* yields the same result as the invocation of |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
496 |
* {@code deflater.deflate(output, Deflater.NO_FLUSH)}. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
497 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
498 |
* @param output the buffer for the compressed data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
499 |
* @return the actual number of bytes of compressed data written to the |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
500 |
* output buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
501 |
* @since 11 |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
502 |
*/ |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
503 |
public int deflate(ByteBuffer output) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
504 |
return deflate(output, NO_FLUSH); |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
505 |
} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
506 |
|
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
507 |
/** |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
508 |
* Compresses the input data and fills the specified buffer with compressed |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
509 |
* data. Returns actual number of bytes of data compressed. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
510 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
511 |
* <p>Compression flush mode is one of the following three modes: |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
512 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
513 |
* <ul> |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
514 |
* <li>{@link #NO_FLUSH}: allows the deflater to decide how much data |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
515 |
* to accumulate, before producing output, in order to achieve the best |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
516 |
* compression (should be used in normal use scenario). A return value |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
517 |
* of 0 in this flush mode indicates that {@link #needsInput()} should |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
518 |
* be called in order to determine if more input data is required. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
519 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
520 |
* <li>{@link #SYNC_FLUSH}: all pending output in the deflater is flushed, |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
521 |
* to the specified output buffer, so that an inflater that works on |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
522 |
* compressed data can get all input data available so far (In particular |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
523 |
* the {@link #needsInput()} returns {@code true} after this invocation |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
524 |
* if enough output space is provided). Flushing with {@link #SYNC_FLUSH} |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
525 |
* may degrade compression for some compression algorithms and so it |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
526 |
* should be used only when necessary. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
527 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
528 |
* <li>{@link #FULL_FLUSH}: all pending output is flushed out as with |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
529 |
* {@link #SYNC_FLUSH}. The compression state is reset so that the inflater |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
530 |
* that works on the compressed output data can restart from this point |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
531 |
* if previous compressed data has been damaged or if random access is |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
532 |
* desired. Using {@link #FULL_FLUSH} too often can seriously degrade |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
533 |
* compression. |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
534 |
* </ul> |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
535 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
536 |
* <p>In the case of {@link #FULL_FLUSH} or {@link #SYNC_FLUSH}, if |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
537 |
* the return value is {@code len}, the space available in output |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
538 |
* buffer {@code b}, this method should be invoked again with the same |
39497
7701abdf2fb4
8133170: Deflater.deflate with small output buffers fails
sherman
parents:
32995
diff
changeset
|
539 |
* {@code flush} parameter and more output space. Make sure that |
7701abdf2fb4
8133170: Deflater.deflate with small output buffers fails
sherman
parents:
32995
diff
changeset
|
540 |
* {@code len} is greater than 6 to avoid flush marker (5 bytes) being |
7701abdf2fb4
8133170: Deflater.deflate with small output buffers fails
sherman
parents:
32995
diff
changeset
|
541 |
* repeatedly output to the output buffer every time this method is |
7701abdf2fb4
8133170: Deflater.deflate with small output buffers fails
sherman
parents:
32995
diff
changeset
|
542 |
* invoked. |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
543 |
* |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
544 |
* <p>If the {@link #setInput(ByteBuffer)} method was called to provide a buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
545 |
* for input, the input buffer's position will be advanced by the number of bytes |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
546 |
* consumed by this operation. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
547 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
548 |
* @param output the buffer for the compressed data |
4162
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
549 |
* @param off the start offset of the data |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
550 |
* @param len the maximum number of bytes of compressed data |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
551 |
* @param flush the compression flush mode |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
552 |
* @return the actual number of bytes of compressed data written to |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
553 |
* the output buffer |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
554 |
* |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
555 |
* @throws IllegalArgumentException if the flush mode is invalid |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
556 |
* @since 1.7 |
425328b81201
4206909: want java.util.zip to work for interactive use (Z_SYNC_FLUSH)
sherman
parents:
2940
diff
changeset
|
557 |
*/ |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
558 |
public int deflate(byte[] output, int off, int len, int flush) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
559 |
if (off < 0 || len < 0 || off > output.length - len) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
560 |
throw new ArrayIndexOutOfBoundsException(); |
2 | 561 |
} |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
562 |
if (flush != NO_FLUSH && flush != SYNC_FLUSH && flush != FULL_FLUSH) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
563 |
throw new IllegalArgumentException(); |
2 | 564 |
} |
5173 | 565 |
synchronized (zsRef) { |
566 |
ensureOpen(); |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
567 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
568 |
ByteBuffer input = this.input; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
569 |
if (finish) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
570 |
// disregard given flush mode in this case |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
571 |
flush = FINISH; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
572 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
573 |
int params; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
574 |
if (setParams) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
575 |
// bit 0: true to set params |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
576 |
// bit 1-2: strategy (0, 1, or 2) |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
577 |
// bit 3-31: level (0..9 or -1) |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
578 |
params = 1 | strategy << 1 | level << 3; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
579 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
580 |
params = 0; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
581 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
582 |
int inputPos; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
583 |
long result; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
584 |
if (input == null) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
585 |
inputPos = this.inputPos; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
586 |
result = deflateBytesBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
587 |
inputArray, inputPos, inputLim - inputPos, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
588 |
output, off, len, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
589 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
590 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
591 |
inputPos = input.position(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
592 |
int inputRem = Math.max(input.limit() - inputPos, 0); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
593 |
if (input.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
594 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
595 |
long inputAddress = ((DirectBuffer) input).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
596 |
result = deflateBufferBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
597 |
inputAddress + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
598 |
output, off, len, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
599 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
600 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
601 |
Reference.reachabilityFence(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
602 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
603 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
604 |
byte[] inputArray = ZipUtils.getBufferArray(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
605 |
int inputOffset = ZipUtils.getBufferOffset(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
606 |
result = deflateBytesBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
607 |
inputArray, inputOffset + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
608 |
output, off, len, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
609 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
610 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
611 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
612 |
int read = (int) (result & 0x7fff_ffffL); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
613 |
int written = (int) (result >>> 31 & 0x7fff_ffffL); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
614 |
if ((result >>> 62 & 1) != 0) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
615 |
finished = true; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
616 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
617 |
if (params != 0 && (result >>> 63 & 1) == 0) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
618 |
setParams = false; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
619 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
620 |
if (input != null) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
621 |
input.position(inputPos + read); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
622 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
623 |
this.inputPos = inputPos + read; |
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
624 |
} |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
625 |
bytesWritten += written; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
626 |
bytesRead += read; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
627 |
return written; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
628 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
629 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
630 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
631 |
/** |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
632 |
* Compresses the input data and fills the specified buffer with compressed |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
633 |
* data. Returns actual number of bytes of data compressed. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
634 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
635 |
* <p>Compression flush mode is one of the following three modes: |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
636 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
637 |
* <ul> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
638 |
* <li>{@link #NO_FLUSH}: allows the deflater to decide how much data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
639 |
* to accumulate, before producing output, in order to achieve the best |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
640 |
* compression (should be used in normal use scenario). A return value |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
641 |
* of 0 in this flush mode indicates that {@link #needsInput()} should |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
642 |
* be called in order to determine if more input data is required. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
643 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
644 |
* <li>{@link #SYNC_FLUSH}: all pending output in the deflater is flushed, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
645 |
* to the specified output buffer, so that an inflater that works on |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
646 |
* compressed data can get all input data available so far (In particular |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
647 |
* the {@link #needsInput()} returns {@code true} after this invocation |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
648 |
* if enough output space is provided). Flushing with {@link #SYNC_FLUSH} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
649 |
* may degrade compression for some compression algorithms and so it |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
650 |
* should be used only when necessary. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
651 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
652 |
* <li>{@link #FULL_FLUSH}: all pending output is flushed out as with |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
653 |
* {@link #SYNC_FLUSH}. The compression state is reset so that the inflater |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
654 |
* that works on the compressed output data can restart from this point |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
655 |
* if previous compressed data has been damaged or if random access is |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
656 |
* desired. Using {@link #FULL_FLUSH} too often can seriously degrade |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
657 |
* compression. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
658 |
* </ul> |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
659 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
660 |
* <p>In the case of {@link #FULL_FLUSH} or {@link #SYNC_FLUSH}, if |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
661 |
* the return value is equal to the {@linkplain ByteBuffer#remaining() remaining space} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
662 |
* of the buffer, this method should be invoked again with the same |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
663 |
* {@code flush} parameter and more output space. Make sure that |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
664 |
* the buffer has at least 6 bytes of remaining space to avoid the |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
665 |
* flush marker (5 bytes) being repeatedly output to the output buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
666 |
* every time this method is invoked. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
667 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
668 |
* <p>On success, the position of the given {@code output} byte buffer will be |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
669 |
* advanced by as many bytes as were produced by the operation, which is equal |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
670 |
* to the number returned by this method. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
671 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
672 |
* <p>If the {@link #setInput(ByteBuffer)} method was called to provide a buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
673 |
* for input, the input buffer's position will be advanced by the number of bytes |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
674 |
* consumed by this operation. |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
675 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
676 |
* @param output the buffer for the compressed data |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
677 |
* @param flush the compression flush mode |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
678 |
* @return the actual number of bytes of compressed data written to |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
679 |
* the output buffer |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
680 |
* |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
681 |
* @throws IllegalArgumentException if the flush mode is invalid |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
682 |
* @since 11 |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
683 |
*/ |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
684 |
public int deflate(ByteBuffer output, int flush) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
685 |
if (output.isReadOnly()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
686 |
throw new ReadOnlyBufferException(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
687 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
688 |
if (flush != NO_FLUSH && flush != SYNC_FLUSH && flush != FULL_FLUSH) { |
5173 | 689 |
throw new IllegalArgumentException(); |
690 |
} |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
691 |
synchronized (zsRef) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
692 |
ensureOpen(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
693 |
|
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
694 |
ByteBuffer input = this.input; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
695 |
if (finish) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
696 |
// disregard given flush mode in this case |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
697 |
flush = FINISH; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
698 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
699 |
int params; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
700 |
if (setParams) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
701 |
// bit 0: true to set params |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
702 |
// bit 1-2: strategy (0, 1, or 2) |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
703 |
// bit 3-31: level (0..9 or -1) |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
704 |
params = 1 | strategy << 1 | level << 3; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
705 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
706 |
params = 0; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
707 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
708 |
int outputPos = output.position(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
709 |
int outputRem = Math.max(output.limit() - outputPos, 0); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
710 |
int inputPos; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
711 |
long result; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
712 |
if (input == null) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
713 |
inputPos = this.inputPos; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
714 |
if (output.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
715 |
long outputAddress = ((DirectBuffer) output).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
716 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
717 |
result = deflateBytesBuffer(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
718 |
inputArray, inputPos, inputLim - inputPos, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
719 |
outputAddress + outputPos, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
720 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
721 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
722 |
Reference.reachabilityFence(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
723 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
724 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
725 |
byte[] outputArray = ZipUtils.getBufferArray(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
726 |
int outputOffset = ZipUtils.getBufferOffset(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
727 |
result = deflateBytesBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
728 |
inputArray, inputPos, inputLim - inputPos, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
729 |
outputArray, outputOffset + outputPos, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
730 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
731 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
732 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
733 |
inputPos = input.position(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
734 |
int inputRem = Math.max(input.limit() - inputPos, 0); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
735 |
if (input.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
736 |
long inputAddress = ((DirectBuffer) input).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
737 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
738 |
if (output.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
739 |
long outputAddress = outputPos + ((DirectBuffer) output).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
740 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
741 |
result = deflateBufferBuffer(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
742 |
inputAddress + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
743 |
outputAddress, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
744 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
745 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
746 |
Reference.reachabilityFence(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
747 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
748 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
749 |
byte[] outputArray = ZipUtils.getBufferArray(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
750 |
int outputOffset = ZipUtils.getBufferOffset(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
751 |
result = deflateBufferBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
752 |
inputAddress + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
753 |
outputArray, outputOffset + outputPos, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
754 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
755 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
756 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
757 |
Reference.reachabilityFence(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
758 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
759 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
760 |
byte[] inputArray = ZipUtils.getBufferArray(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
761 |
int inputOffset = ZipUtils.getBufferOffset(input); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
762 |
if (output.isDirect()) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
763 |
long outputAddress = ((DirectBuffer) output).address(); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
764 |
try { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
765 |
result = deflateBytesBuffer(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
766 |
inputArray, inputOffset + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
767 |
outputAddress + outputPos, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
768 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
769 |
} finally { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
770 |
Reference.reachabilityFence(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
771 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
772 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
773 |
byte[] outputArray = ZipUtils.getBufferArray(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
774 |
int outputOffset = ZipUtils.getBufferOffset(output); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
775 |
result = deflateBytesBytes(zsRef.address(), |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
776 |
inputArray, inputOffset + inputPos, inputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
777 |
outputArray, outputOffset + outputPos, outputRem, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
778 |
flush, params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
779 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
780 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
781 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
782 |
int read = (int) (result & 0x7fff_ffffL); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
783 |
int written = (int) (result >>> 31 & 0x7fff_ffffL); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
784 |
if ((result >>> 62 & 1) != 0) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
785 |
finished = true; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
786 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
787 |
if (params != 0 && (result >>> 63 & 1) == 0) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
788 |
setParams = false; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
789 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
790 |
if (input != null) { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
791 |
input.position(inputPos + read); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
792 |
} else { |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
793 |
this.inputPos = inputPos + read; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
794 |
} |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
795 |
output.position(outputPos + written); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
796 |
bytesWritten += written; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
797 |
bytesRead += read; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
798 |
return written; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
799 |
} |
2 | 800 |
} |
801 |
||
802 |
/** |
|
803 |
* Returns the ADLER-32 value of the uncompressed data. |
|
804 |
* @return the ADLER-32 value of the uncompressed data |
|
805 |
*/ |
|
5173 | 806 |
public int getAdler() { |
807 |
synchronized (zsRef) { |
|
808 |
ensureOpen(); |
|
809 |
return getAdler(zsRef.address()); |
|
810 |
} |
|
2 | 811 |
} |
812 |
||
813 |
/** |
|
814 |
* Returns the total number of uncompressed bytes input so far. |
|
815 |
* |
|
816 |
* <p>Since the number of bytes may be greater than |
|
817 |
* Integer.MAX_VALUE, the {@link #getBytesRead()} method is now |
|
818 |
* the preferred means of obtaining this information.</p> |
|
819 |
* |
|
820 |
* @return the total number of uncompressed bytes input so far |
|
821 |
*/ |
|
822 |
public int getTotalIn() { |
|
823 |
return (int) getBytesRead(); |
|
824 |
} |
|
825 |
||
826 |
/** |
|
18560 | 827 |
* Returns the total number of uncompressed bytes input so far. |
2 | 828 |
* |
829 |
* @return the total (non-negative) number of uncompressed bytes input so far |
|
830 |
* @since 1.5 |
|
831 |
*/ |
|
5173 | 832 |
public long getBytesRead() { |
833 |
synchronized (zsRef) { |
|
834 |
ensureOpen(); |
|
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
835 |
return bytesRead; |
5173 | 836 |
} |
2 | 837 |
} |
838 |
||
839 |
/** |
|
840 |
* Returns the total number of compressed bytes output so far. |
|
841 |
* |
|
842 |
* <p>Since the number of bytes may be greater than |
|
843 |
* Integer.MAX_VALUE, the {@link #getBytesWritten()} method is now |
|
844 |
* the preferred means of obtaining this information.</p> |
|
845 |
* |
|
846 |
* @return the total number of compressed bytes output so far |
|
847 |
*/ |
|
848 |
public int getTotalOut() { |
|
849 |
return (int) getBytesWritten(); |
|
850 |
} |
|
851 |
||
852 |
/** |
|
18560 | 853 |
* Returns the total number of compressed bytes output so far. |
2 | 854 |
* |
855 |
* @return the total (non-negative) number of compressed bytes output so far |
|
856 |
* @since 1.5 |
|
857 |
*/ |
|
5173 | 858 |
public long getBytesWritten() { |
859 |
synchronized (zsRef) { |
|
860 |
ensureOpen(); |
|
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
861 |
return bytesWritten; |
5173 | 862 |
} |
2 | 863 |
} |
864 |
||
865 |
/** |
|
866 |
* Resets deflater so that a new set of input data can be processed. |
|
867 |
* Keeps current compression level and strategy settings. |
|
868 |
*/ |
|
5173 | 869 |
public void reset() { |
870 |
synchronized (zsRef) { |
|
871 |
ensureOpen(); |
|
872 |
reset(zsRef.address()); |
|
873 |
finish = false; |
|
874 |
finished = false; |
|
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
875 |
input = ZipUtils.defaultBuf; |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
876 |
inputArray = null; |
13409
fe3ab27ef1a6
7188852: Move implementation of De/Inflater.getBytesRead/Writtten() to java from native
sherman
parents:
7668
diff
changeset
|
877 |
bytesRead = bytesWritten = 0; |
5173 | 878 |
} |
2 | 879 |
} |
880 |
||
881 |
/** |
|
882 |
* Closes the compressor and discards any unprocessed input. |
|
48238
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
883 |
* |
2 | 884 |
* This method should be called when the compressor is no longer |
48238
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
885 |
* being used. Once this method is called, the behavior of the |
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
886 |
* Deflater object is undefined. |
2 | 887 |
*/ |
5173 | 888 |
public void end() { |
889 |
synchronized (zsRef) { |
|
48238
9f225d4387e2
8185582: Update Zip implementation to use Cleaner, not finalizers
sherman
parents:
47216
diff
changeset
|
890 |
zsRef.clean(); |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
891 |
input = ZipUtils.defaultBuf; |
2 | 892 |
} |
893 |
} |
|
894 |
||
895 |
private void ensureOpen() { |
|
5173 | 896 |
assert Thread.holdsLock(zsRef); |
897 |
if (zsRef.address() == 0) |
|
898 |
throw new NullPointerException("Deflater has been closed"); |
|
2 | 899 |
} |
900 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32037
diff
changeset
|
901 |
private static native long init(int level, int strategy, boolean nowrap); |
49834
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
902 |
private static native void setDictionary(long addr, byte[] b, int off, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
903 |
int len); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
904 |
private static native void setDictionaryBuffer(long addr, long bufAddress, int len); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
905 |
private native long deflateBytesBytes(long addr, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
906 |
byte[] inputArray, int inputOff, int inputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
907 |
byte[] outputArray, int outputOff, int outputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
908 |
int flush, int params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
909 |
private native long deflateBytesBuffer(long addr, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
910 |
byte[] inputArray, int inputOff, int inputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
911 |
long outputAddress, int outputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
912 |
int flush, int params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
913 |
private native long deflateBufferBytes(long addr, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
914 |
long inputAddress, int inputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
915 |
byte[] outputArray, int outputOff, int outputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
916 |
int flush, int params); |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
917 |
private native long deflateBufferBuffer(long addr, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
918 |
long inputAddress, int inputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
919 |
long outputAddress, int outputLen, |
99644c75eaed
6341887: java.util.zip: Add ByteBuffer methods to Inflater/Deflater
sherman
parents:
48337
diff
changeset
|
920 |
int flush, int params); |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32037
diff
changeset
|
921 |
private static native int getAdler(long addr); |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32037
diff
changeset
|
922 |
private static native void reset(long addr); |
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
32037
diff
changeset
|
923 |
private static native void end(long addr); |
48337
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
924 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
925 |
/** |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
926 |
* A reference to the native zlib's z_stream structure. It also |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
927 |
* serves as the "cleaner" to clean up the native resource when |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
928 |
* the Deflater is ended, closed or cleaned. |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
929 |
*/ |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
930 |
static class DeflaterZStreamRef implements Runnable { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
931 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
932 |
private long address; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
933 |
private final Cleanable cleanable; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
934 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
935 |
private DeflaterZStreamRef(Deflater owner, long addr) { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
936 |
this.cleanable = (owner != null) ? CleanerFactory.cleaner().register(owner, this) : null; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
937 |
this.address = addr; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
938 |
} |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
939 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
940 |
long address() { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
941 |
return address; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
942 |
} |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
943 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
944 |
void clean() { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
945 |
cleanable.clean(); |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
946 |
} |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
947 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
948 |
public synchronized void run() { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
949 |
long addr = address; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
950 |
address = 0; |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
951 |
if (addr != 0) { |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
952 |
end(addr); |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
953 |
} |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
954 |
} |
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
955 |
|
0ee20aad71c4
8193507: [REDO] Startup regression due to JDK-8185582
redestad
parents:
48238
diff
changeset
|
956 |
} |
2 | 957 |
} |