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.gzip; 021 022import java.io.OutputStream; 023import java.util.zip.Deflater; 024 025/** 026 * Parameters for the GZIP compressor. 027 * 028 * @see GzipCompressorInputStream 029 * @see GzipCompressorOutputStream 030 * @since 1.7 031 */ 032public class GzipParameters { 033 034 private int compressionLevel = Deflater.DEFAULT_COMPRESSION; 035 private long modificationTime; 036 private String fileName; 037 private String comment; 038 private int operatingSystem = 255; // Unknown OS by default 039 private int bufferSize = 512; 040 private int deflateStrategy = Deflater.DEFAULT_STRATEGY; 041 042 /** 043 * Gets size of the buffer used to retrieve compressed data. 044 * @return The size of the buffer used to retrieve compressed data. 045 * @since 1.21 046 * @see #setBufferSize(int) 047 */ 048 public int getBufferSize() { 049 return this.bufferSize; 050 } 051 052 public String getComment() { 053 return comment; 054 } 055 056 public int getCompressionLevel() { 057 return compressionLevel; 058 } 059 060 /** 061 * Gets the deflater strategy. 062 * 063 * @return the deflater strategy, {@link Deflater#DEFAULT_STRATEGY} by default. 064 * @see #setDeflateStrategy(int) 065 * @see Deflater#setStrategy(int) 066 * @since 1.23 067 */ 068 public int getDeflateStrategy() { 069 return deflateStrategy; 070 } 071 072 /** 073 * Gets the file name. 074 * 075 * @return the file name. 076 * @deprecated Use {@link #getFileName()}. 077 */ 078 @Deprecated 079 public String getFilename() { 080 return fileName; 081 } 082 083 /** 084 * Gets the file name. 085 * 086 * @return the file name. 087 * @since 2.25.0 088 */ 089 public String getFileName() { 090 return fileName; 091 } 092 093 public long getModificationTime() { 094 return modificationTime; 095 } 096 097 public int getOperatingSystem() { 098 return operatingSystem; 099 } 100 101 /** 102 * Sets size of the buffer used to retrieve compressed data from 103 * {@link Deflater} and write to underlying {@link OutputStream}. 104 * 105 * @param bufferSize the bufferSize to set. Must be a positive value. 106 * @since 1.21 107 */ 108 public void setBufferSize(final int bufferSize) { 109 if (bufferSize <= 0) { 110 throw new IllegalArgumentException("invalid buffer size: " + bufferSize); 111 } 112 this.bufferSize = bufferSize; 113 } 114 115 public void setComment(final String comment) { 116 this.comment = comment; 117 } 118 119 /** 120 * Sets the compression level. 121 * 122 * @param compressionLevel the compression level (between 0 and 9) 123 * @see Deflater#NO_COMPRESSION 124 * @see Deflater#BEST_SPEED 125 * @see Deflater#DEFAULT_COMPRESSION 126 * @see Deflater#BEST_COMPRESSION 127 */ 128 public void setCompressionLevel(final int compressionLevel) { 129 if (compressionLevel < -1 || compressionLevel > 9) { 130 throw new IllegalArgumentException("Invalid gzip compression level: " + compressionLevel); 131 } 132 this.compressionLevel = compressionLevel; 133 } 134 135 /** 136 * Sets the deflater strategy. 137 * 138 * @param deflateStrategy the new compression strategy 139 * @see Deflater#setStrategy(int) 140 * @since 1.23 141 */ 142 public void setDeflateStrategy(final int deflateStrategy) { 143 this.deflateStrategy = deflateStrategy; 144 } 145 146 /** 147 * Sets the name of the compressed file. 148 * 149 * @param fileName the name of the file without the directory path 150 * @deprecated Use {@link #setFileName(String)}. 151 */ 152 @Deprecated 153 public void setFilename(final String fileName) { 154 this.fileName = fileName; 155 } 156 157 /** 158 * Sets the name of the compressed file. 159 * 160 * @param fileName the name of the file without the directory path 161 */ 162 public void setFileName(final String fileName) { 163 this.fileName = fileName; 164 } 165 166 /** 167 * Sets the modification time of the compressed file. 168 * 169 * @param modificationTime the modification time, in milliseconds 170 */ 171 public void setModificationTime(final long modificationTime) { 172 this.modificationTime = modificationTime; 173 } 174 175 /** 176 * Sets the operating system on which the compression took place. 177 * The defined values are: 178 * <ul> 179 * <li>0: FAT file system (MS-DOS, OS/2, NT/Win32)</li> 180 * <li>1: Amiga</li> 181 * <li>2: VMS (or OpenVMS)</li> 182 * <li>3: Unix</li> 183 * <li>4: VM/CMS</li> 184 * <li>5: Atari TOS</li> 185 * <li>6: HPFS file system (OS/2, NT)</li> 186 * <li>7: Macintosh</li> 187 * <li>8: Z-System</li> 188 * <li>9: CP/M</li> 189 * <li>10: TOPS-20</li> 190 * <li>11: NTFS file system (NT)</li> 191 * <li>12: QDOS</li> 192 * <li>13: Acorn RISCOS</li> 193 * <li>255: Unknown</li> 194 * </ul> 195 * 196 * @param operatingSystem the code of the operating system 197 */ 198 public void setOperatingSystem(final int operatingSystem) { 199 this.operatingSystem = operatingSystem; 200 } 201}