mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8026127: Deflater/Inflater documentation incomplete/misleading
Reviewed-by: lancea
This commit is contained in:
parent
6238bc8da2
commit
d8af58941b
3 changed files with 98 additions and 59 deletions
|
@ -56,35 +56,7 @@ import static java.util.zip.ZipUtils.NIO_ACCESS;
|
|||
* The following code fragment demonstrates a trivial compression
|
||||
* and decompression of a string using {@code Deflater} and
|
||||
* {@code Inflater}.
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* try {
|
||||
* // Encode a String into bytes
|
||||
* String inputString = "blahblahblah\u20AC\u20AC";
|
||||
* byte[] input = inputString.getBytes("UTF-8");
|
||||
*
|
||||
* // Compress the bytes
|
||||
* byte[] output = new byte[100];
|
||||
* Deflater compresser = new Deflater();
|
||||
* compresser.setInput(input);
|
||||
* compresser.finish();
|
||||
* int compressedDataLength = compresser.deflate(output);
|
||||
*
|
||||
* // Decompress the bytes
|
||||
* Inflater decompresser = new Inflater();
|
||||
* decompresser.setInput(output, 0, compressedDataLength);
|
||||
* byte[] result = new byte[100];
|
||||
* int resultLength = decompresser.inflate(result);
|
||||
* decompresser.end();
|
||||
*
|
||||
* // Decode the bytes into a String
|
||||
* String outputString = new String(result, 0, resultLength, "UTF-8");
|
||||
* } catch (java.io.UnsupportedEncodingException ex) {
|
||||
* // handle
|
||||
* } catch (java.util.zip.DataFormatException ex) {
|
||||
* // handle
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
* {@snippet id="compdecomp" lang="java" class="Snippets" region="DeflaterInflaterExample"}
|
||||
*
|
||||
* @apiNote
|
||||
* To release resources used by this {@code Inflater}, the {@link #end()} method
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue