001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.commons.compress.compressors.deflate; 021 022import java.util.zip.Deflater; 023 024/** 025 * Parameters for the Deflate compressor. 026 * @since 1.9 027 */ 028public class DeflateParameters { 029 030 private boolean zlibHeader = true; 031 private int compressionLevel = Deflater.DEFAULT_COMPRESSION; 032 033 /** 034 * Whether or not the zlib header shall be written (when 035 * compressing) or expected (when decompressing). 036 */ 037 public boolean withZlibHeader() { 038 return zlibHeader; 039 } 040 041 /** 042 * Sets the zlib header presence parameter. 043 * 044 * <p>This affects whether or not the zlib header will be written 045 * (when compressing) or expected (when decompressing).</p> 046 * 047 * @param zlibHeader 048 */ 049 public void setWithZlibHeader(boolean zlibHeader) { 050 this.zlibHeader = zlibHeader; 051 } 052 053 /** 054 * The compression level. 055 * @see #setCompressionLevel 056 */ 057 public int getCompressionLevel() { 058 return compressionLevel; 059 } 060 061 /** 062 * Sets the compression level. 063 * 064 * @param compressionLevel the compression level (between 0 and 9) 065 * @see Deflater#NO_COMPRESSION 066 * @see Deflater#BEST_SPEED 067 * @see Deflater#DEFAULT_COMPRESSION 068 * @see Deflater#BEST_COMPRESSION 069 */ 070 public void setCompressionLevel(int compressionLevel) { 071 if (compressionLevel < -1 || compressionLevel > 9) { 072 throw new IllegalArgumentException("Invalid Deflate compression level: " + compressionLevel); 073 } 074 this.compressionLevel = compressionLevel; 075 } 076 077}