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