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 * 045 * @return The size of the buffer used to retrieve compressed data. 046 * @since 1.21 047 * @see #setBufferSize(int) 048 */ 049 public int getBufferSize() { 050 return this.bufferSize; 051 } 052 053 public String getComment() { 054 return comment; 055 } 056 057 public int getCompressionLevel() { 058 return compressionLevel; 059 } 060 061 /** 062 * Gets the deflater strategy. 063 * 064 * @return the deflater strategy, {@link Deflater#DEFAULT_STRATEGY} by default. 065 * @see #setDeflateStrategy(int) 066 * @see Deflater#setStrategy(int) 067 * @since 1.23 068 */ 069 public int getDeflateStrategy() { 070 return deflateStrategy; 071 } 072 073 /** 074 * Gets the file name. 075 * 076 * @return the file name. 077 * @deprecated Use {@link #getFileName()}. 078 */ 079 @Deprecated 080 public String getFilename() { 081 return fileName; 082 } 083 084 /** 085 * Gets the file name. 086 * 087 * @return the file name. 088 * @since 2.25.0 089 */ 090 public String getFileName() { 091 return fileName; 092 } 093 094 public long getModificationTime() { 095 return modificationTime; 096 } 097 098 public int getOperatingSystem() { 099 return operatingSystem; 100 } 101 102 /** 103 * Sets size of the buffer used to retrieve compressed data from {@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. The defined values are: 177 * <ul> 178 * <li>0: FAT file system (MS-DOS, OS/2, NT/Win32)</li> 179 * <li>1: Amiga</li> 180 * <li>2: VMS (or OpenVMS)</li> 181 * <li>3: Unix</li> 182 * <li>4: VM/CMS</li> 183 * <li>5: Atari TOS</li> 184 * <li>6: HPFS file system (OS/2, NT)</li> 185 * <li>7: Macintosh</li> 186 * <li>8: Z-System</li> 187 * <li>9: CP/M</li> 188 * <li>10: TOPS-20</li> 189 * <li>11: NTFS file system (NT)</li> 190 * <li>12: QDOS</li> 191 * <li>13: Acorn RISCOS</li> 192 * <li>255: Unknown</li> 193 * </ul> 194 * 195 * @param operatingSystem the code of the operating system 196 */ 197 public void setOperatingSystem(final int operatingSystem) { 198 this.operatingSystem = operatingSystem; 199 } 200}