1 /* |
1 /* |
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
74 * Creates a new input stream with the specified decompressor and |
74 * Creates a new input stream with the specified decompressor and |
75 * buffer size. |
75 * buffer size. |
76 * @param in the input stream |
76 * @param in the input stream |
77 * @param inf the decompressor ("inflater") |
77 * @param inf the decompressor ("inflater") |
78 * @param size the input buffer size |
78 * @param size the input buffer size |
79 * @exception IllegalArgumentException if {@code size <= 0} |
79 * @throws IllegalArgumentException if {@code size <= 0} |
80 */ |
80 */ |
81 public InflaterInputStream(InputStream in, Inflater inf, int size) { |
81 public InflaterInputStream(InputStream in, Inflater inf, int size) { |
82 super(in); |
82 super(in); |
83 if (in == null || inf == null) { |
83 if (in == null || inf == null) { |
84 throw new NullPointerException(); |
84 throw new NullPointerException(); |
114 |
114 |
115 /** |
115 /** |
116 * Reads a byte of uncompressed data. This method will block until |
116 * Reads a byte of uncompressed data. This method will block until |
117 * enough input is available for decompression. |
117 * enough input is available for decompression. |
118 * @return the byte read, or -1 if end of compressed input is reached |
118 * @return the byte read, or -1 if end of compressed input is reached |
119 * @exception IOException if an I/O error has occurred |
119 * @throws IOException if an I/O error has occurred |
120 */ |
120 */ |
121 public int read() throws IOException { |
121 public int read() throws IOException { |
122 ensureOpen(); |
122 ensureOpen(); |
123 return read(singleByteBuf, 0, 1) == -1 ? -1 : Byte.toUnsignedInt(singleByteBuf[0]); |
123 return read(singleByteBuf, 0, 1) == -1 ? -1 : Byte.toUnsignedInt(singleByteBuf[0]); |
124 } |
124 } |
125 |
125 |
126 /** |
126 /** |
127 * Reads uncompressed data into an array of bytes. If <code>len</code> is not |
127 * Reads uncompressed data into an array of bytes. If {@code len} is not |
128 * zero, the method will block until some input can be decompressed; otherwise, |
128 * zero, the method will block until some input can be decompressed; otherwise, |
129 * no bytes are read and <code>0</code> is returned. |
129 * no bytes are read and {@code 0} is returned. |
130 * @param b the buffer into which the data is read |
130 * @param b the buffer into which the data is read |
131 * @param off the start offset in the destination array <code>b</code> |
131 * @param off the start offset in the destination array {@code b} |
132 * @param len the maximum number of bytes read |
132 * @param len the maximum number of bytes read |
133 * @return the actual number of bytes read, or -1 if the end of the |
133 * @return the actual number of bytes read, or -1 if the end of the |
134 * compressed input is reached or a preset dictionary is needed |
134 * compressed input is reached or a preset dictionary is needed |
135 * @exception NullPointerException If <code>b</code> is <code>null</code>. |
135 * @throws NullPointerException If {@code b} is {@code null}. |
136 * @exception IndexOutOfBoundsException If <code>off</code> is negative, |
136 * @throws IndexOutOfBoundsException If {@code off} is negative, |
137 * <code>len</code> is negative, or <code>len</code> is greater than |
137 * {@code len} is negative, or {@code len} is greater than |
138 * <code>b.length - off</code> |
138 * {@code b.length - off} |
139 * @exception ZipException if a ZIP format error has occurred |
139 * @throws ZipException if a ZIP format error has occurred |
140 * @exception IOException if an I/O error has occurred |
140 * @throws IOException if an I/O error has occurred |
141 */ |
141 */ |
142 public int read(byte[] b, int off, int len) throws IOException { |
142 public int read(byte[] b, int off, int len) throws IOException { |
143 ensureOpen(); |
143 ensureOpen(); |
144 if (b == null) { |
144 if (b == null) { |
145 throw new NullPointerException(); |
145 throw new NullPointerException(); |
193 |
193 |
194 /** |
194 /** |
195 * Skips specified number of bytes of uncompressed data. |
195 * Skips specified number of bytes of uncompressed data. |
196 * @param n the number of bytes to skip |
196 * @param n the number of bytes to skip |
197 * @return the actual number of bytes skipped. |
197 * @return the actual number of bytes skipped. |
198 * @exception IOException if an I/O error has occurred |
198 * @throws IOException if an I/O error has occurred |
199 * @exception IllegalArgumentException if {@code n < 0} |
199 * @throws IllegalArgumentException if {@code n < 0} |
200 */ |
200 */ |
201 public long skip(long n) throws IOException { |
201 public long skip(long n) throws IOException { |
202 if (n < 0) { |
202 if (n < 0) { |
203 throw new IllegalArgumentException("negative skip length"); |
203 throw new IllegalArgumentException("negative skip length"); |
204 } |
204 } |
246 } |
246 } |
247 inf.setInput(buf, 0, len); |
247 inf.setInput(buf, 0, len); |
248 } |
248 } |
249 |
249 |
250 /** |
250 /** |
251 * Tests if this input stream supports the <code>mark</code> and |
251 * Tests if this input stream supports the {@code mark} and |
252 * <code>reset</code> methods. The <code>markSupported</code> |
252 * {@code reset} methods. The {@code markSupported} |
253 * method of <code>InflaterInputStream</code> returns |
253 * method of {@code InflaterInputStream} returns |
254 * <code>false</code>. |
254 * {@code false}. |
255 * |
255 * |
256 * @return a <code>boolean</code> indicating if this stream type supports |
256 * @return a {@code boolean} indicating if this stream type supports |
257 * the <code>mark</code> and <code>reset</code> methods. |
257 * the {@code mark} and {@code reset} methods. |
258 * @see java.io.InputStream#mark(int) |
258 * @see java.io.InputStream#mark(int) |
259 * @see java.io.InputStream#reset() |
259 * @see java.io.InputStream#reset() |
260 */ |
260 */ |
261 public boolean markSupported() { |
261 public boolean markSupported() { |
262 return false; |
262 return false; |
263 } |
263 } |
264 |
264 |
265 /** |
265 /** |
266 * Marks the current position in this input stream. |
266 * Marks the current position in this input stream. |
267 * |
267 * |
268 * <p> The <code>mark</code> method of <code>InflaterInputStream</code> |
268 * <p> The {@code mark} method of {@code InflaterInputStream} |
269 * does nothing. |
269 * does nothing. |
270 * |
270 * |
271 * @param readlimit the maximum limit of bytes that can be read before |
271 * @param readlimit the maximum limit of bytes that can be read before |
272 * the mark position becomes invalid. |
272 * the mark position becomes invalid. |
273 * @see java.io.InputStream#reset() |
273 * @see java.io.InputStream#reset() |
275 public synchronized void mark(int readlimit) { |
275 public synchronized void mark(int readlimit) { |
276 } |
276 } |
277 |
277 |
278 /** |
278 /** |
279 * Repositions this stream to the position at the time the |
279 * Repositions this stream to the position at the time the |
280 * <code>mark</code> method was last called on this input stream. |
280 * {@code mark} method was last called on this input stream. |
281 * |
281 * |
282 * <p> The method <code>reset</code> for class |
282 * <p> The method {@code reset} for class |
283 * <code>InflaterInputStream</code> does nothing except throw an |
283 * {@code InflaterInputStream} does nothing except throw an |
284 * <code>IOException</code>. |
284 * {@code IOException}. |
285 * |
285 * |
286 * @exception IOException if this method is invoked. |
286 * @throws IOException if this method is invoked. |
287 * @see java.io.InputStream#mark(int) |
287 * @see java.io.InputStream#mark(int) |
288 * @see java.io.IOException |
288 * @see java.io.IOException |
289 */ |
289 */ |
290 public synchronized void reset() throws IOException { |
290 public synchronized void reset() throws IOException { |
291 throw new IOException("mark/reset not supported"); |
291 throw new IOException("mark/reset not supported"); |