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 * 027 * @since 1.9 028 */ 029public class DeflateParameters { 030 031 static final int MAX_LEVEL = 9; 032 static final int MIN_LEVEL = 0; 033 034 private boolean zlibHeader = true; 035 private int compressionLevel = Deflater.DEFAULT_COMPRESSION; 036 037 /** 038 * The compression level. 039 * 040 * @see #setCompressionLevel 041 * @return the compression level 042 */ 043 public int getCompressionLevel() { 044 return compressionLevel; 045 } 046 047 /** 048 * Sets the compression level. 049 * 050 * @param compressionLevel the compression level (between 0 and 9) 051 * @see Deflater#NO_COMPRESSION 052 * @see Deflater#BEST_SPEED 053 * @see Deflater#DEFAULT_COMPRESSION 054 * @see Deflater#BEST_COMPRESSION 055 */ 056 public void setCompressionLevel(final int compressionLevel) { 057 if (compressionLevel < MIN_LEVEL || compressionLevel > MAX_LEVEL) { 058 throw new IllegalArgumentException("Invalid Deflate compression level: " + compressionLevel); 059 } 060 this.compressionLevel = compressionLevel; 061 } 062 063 /** 064 * Sets the zlib header presence parameter. 065 * 066 * <p> 067 * This affects whether or not the zlib header will be written (when compressing) or expected (when decompressing). 068 * </p> 069 * 070 * @param zlibHeader true if zlib header shall be written 071 */ 072 public void setWithZlibHeader(final boolean zlibHeader) { 073 this.zlibHeader = zlibHeader; 074 } 075 076 /** 077 * Whether or not the zlib header shall be written (when compressing) or expected (when decompressing). 078 * 079 * @return true if zlib header shall be written 080 */ 081 public boolean withZlibHeader() { 082 return zlibHeader; 083 } 084 085}