1 /*
2 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
347 Reference.reachabilityFence(dictionary);
348 }
349 } else {
350 byte[] array = ZipUtils.getBufferArray(dictionary);
351 int offset = ZipUtils.getBufferOffset(dictionary);
352 setDictionary(zsRef.address(), array, offset + position, remaining);
353 }
354 dictionary.position(position + remaining);
355 }
356 }
357
358 /**
359 * Sets the compression strategy to the specified value.
360 *
361 * <p> If the compression strategy is changed, the next invocation
362 * of {@code deflate} will compress the input available so far with
363 * the old strategy (and may be flushed); the new strategy will take
364 * effect only after that invocation.
365 *
366 * @param strategy the new compression strategy
367 * @exception IllegalArgumentException if the compression strategy is
368 * invalid
369 */
370 public void setStrategy(int strategy) {
371 switch (strategy) {
372 case DEFAULT_STRATEGY:
373 case FILTERED:
374 case HUFFMAN_ONLY:
375 break;
376 default:
377 throw new IllegalArgumentException();
378 }
379 synchronized (zsRef) {
380 if (this.strategy != strategy) {
381 this.strategy = strategy;
382 setParams = true;
383 }
384 }
385 }
386
387 /**
388 * Sets the compression level to the specified value.
389 *
390 * <p> If the compression level is changed, the next invocation
391 * of {@code deflate} will compress the input available so far
392 * with the old level (and may be flushed); the new level will
393 * take effect only after that invocation.
394 *
395 * @param level the new compression level (0-9)
396 * @exception IllegalArgumentException if the compression level is invalid
397 */
398 public void setLevel(int level) {
399 if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) {
400 throw new IllegalArgumentException("invalid compression level");
401 }
402 synchronized (zsRef) {
403 if (this.level != level) {
404 this.level = level;
405 setParams = true;
406 }
407 }
408 }
409
410 /**
411 * Returns true if no data remains in the input buffer. This can
412 * be used to determine if one of the {@code setInput()} methods should be
413 * called in order to provide more input.
414 *
415 * @return true if the input data buffer is empty and setInput()
416 * should be called in order to provide more input
|
1 /*
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.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
347 Reference.reachabilityFence(dictionary);
348 }
349 } else {
350 byte[] array = ZipUtils.getBufferArray(dictionary);
351 int offset = ZipUtils.getBufferOffset(dictionary);
352 setDictionary(zsRef.address(), array, offset + position, remaining);
353 }
354 dictionary.position(position + remaining);
355 }
356 }
357
358 /**
359 * Sets the compression strategy to the specified value.
360 *
361 * <p> If the compression strategy is changed, the next invocation
362 * of {@code deflate} will compress the input available so far with
363 * the old strategy (and may be flushed); the new strategy will take
364 * effect only after that invocation.
365 *
366 * @param strategy the new compression strategy
367 * @throws IllegalArgumentException if the compression strategy is
368 * invalid
369 */
370 public void setStrategy(int strategy) {
371 switch (strategy) {
372 case DEFAULT_STRATEGY:
373 case FILTERED:
374 case HUFFMAN_ONLY:
375 break;
376 default:
377 throw new IllegalArgumentException();
378 }
379 synchronized (zsRef) {
380 if (this.strategy != strategy) {
381 this.strategy = strategy;
382 setParams = true;
383 }
384 }
385 }
386
387 /**
388 * Sets the compression level to the specified value.
389 *
390 * <p> If the compression level is changed, the next invocation
391 * of {@code deflate} will compress the input available so far
392 * with the old level (and may be flushed); the new level will
393 * take effect only after that invocation.
394 *
395 * @param level the new compression level (0-9)
396 * @throws IllegalArgumentException if the compression level is invalid
397 */
398 public void setLevel(int level) {
399 if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) {
400 throw new IllegalArgumentException("invalid compression level");
401 }
402 synchronized (zsRef) {
403 if (this.level != level) {
404 this.level = level;
405 setParams = true;
406 }
407 }
408 }
409
410 /**
411 * Returns true if no data remains in the input buffer. This can
412 * be used to determine if one of the {@code setInput()} methods should be
413 * called in order to provide more input.
414 *
415 * @return true if the input data buffer is empty and setInput()
416 * should be called in order to provide more input
|