src/share/classes/java/util/zip/Deflater.java

Print this page




 244             setDictionary(zsRef.address(), b, off, len);
 245         }
 246     }
 247 
 248     /**
 249      * Sets preset dictionary for compression. A preset dictionary is used
 250      * when the history buffer can be predetermined. When the data is later
 251      * uncompressed with Inflater.inflate(), Inflater.getAdler() can be called
 252      * in order to get the Adler-32 value of the dictionary required for
 253      * decompression.
 254      * @param b the dictionary data bytes
 255      * @see Inflater#inflate
 256      * @see Inflater#getAdler
 257      */
 258     public void setDictionary(byte[] b) {
 259         setDictionary(b, 0, b.length);
 260     }
 261 
 262     /**
 263      * Sets the compression strategy to the specified value.






 264      * @param strategy the new compression strategy
 265      * @exception IllegalArgumentException if the compression strategy is
 266      *                                     invalid
 267      */
 268     public void setStrategy(int strategy) {
 269         switch (strategy) {
 270           case DEFAULT_STRATEGY:
 271           case FILTERED:
 272           case HUFFMAN_ONLY:
 273             break;
 274           default:
 275             throw new IllegalArgumentException();
 276         }
 277         synchronized (zsRef) {
 278             if (this.strategy != strategy) {
 279                 this.strategy = strategy;
 280                 setParams = true;
 281             }
 282         }
 283     }
 284 
 285     /**
 286      * Sets the current compression level to the specified value.






 287      * @param level the new compression level (0-9)
 288      * @exception IllegalArgumentException if the compression level is invalid
 289      */
 290     public void setLevel(int level) {
 291         if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) {
 292             throw new IllegalArgumentException("invalid compression level");
 293         }
 294         synchronized (zsRef) {
 295             if (this.level != level) {
 296                 this.level = level;
 297                 setParams = true;
 298             }
 299         }
 300     }
 301 
 302     /**
 303      * Returns true if the input data buffer is empty and setInput()
 304      * should be called in order to provide more input.
 305      * @return true if the input data buffer is empty and setInput()
 306      * should be called in order to provide more input




 244             setDictionary(zsRef.address(), b, off, len);
 245         }
 246     }
 247 
 248     /**
 249      * Sets preset dictionary for compression. A preset dictionary is used
 250      * when the history buffer can be predetermined. When the data is later
 251      * uncompressed with Inflater.inflate(), Inflater.getAdler() can be called
 252      * in order to get the Adler-32 value of the dictionary required for
 253      * decompression.
 254      * @param b the dictionary data bytes
 255      * @see Inflater#inflate
 256      * @see Inflater#getAdler
 257      */
 258     public void setDictionary(byte[] b) {
 259         setDictionary(b, 0, b.length);
 260     }
 261 
 262     /**
 263      * Sets the compression strategy to the specified value.
 264      *
 265      * <p> If the compression strategy is changed, the next invocation
 266      * of {@code deflate} will compress the input available so far with
 267      * the old strategy (and may be flushed); the new strategy will take
 268      * effect only after that invocation.
 269      *
 270      * @param strategy the new compression strategy
 271      * @exception IllegalArgumentException if the compression strategy is
 272      *                                     invalid
 273      */
 274     public void setStrategy(int strategy) {
 275         switch (strategy) {
 276           case DEFAULT_STRATEGY:
 277           case FILTERED:
 278           case HUFFMAN_ONLY:
 279             break;
 280           default:
 281             throw new IllegalArgumentException();
 282         }
 283         synchronized (zsRef) {
 284             if (this.strategy != strategy) {
 285                 this.strategy = strategy;
 286                 setParams = true;
 287             }
 288         }
 289     }
 290 
 291     /**
 292      * Sets the compression level to the specified value.
 293      *
 294      * <p> If the compression level is changed, the next invocation
 295      * of {@code deflate} will compress the input available so far
 296      * with the old level (and may be flushed); the new level will
 297      * take effect only after that invocation.
 298      *
 299      * @param level the new compression level (0-9)
 300      * @exception IllegalArgumentException if the compression level is invalid
 301      */
 302     public void setLevel(int level) {
 303         if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) {
 304             throw new IllegalArgumentException("invalid compression level");
 305         }
 306         synchronized (zsRef) {
 307             if (this.level != level) {
 308                 this.level = level;
 309                 setParams = true;
 310             }
 311         }
 312     }
 313 
 314     /**
 315      * Returns true if the input data buffer is empty and setInput()
 316      * should be called in order to provide more input.
 317      * @return true if the input data buffer is empty and setInput()
 318      * should be called in order to provide more input