1 /* 2 * Copyright 2021 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty.handler.codec.compression; 17 18 import com.aayushatharva.brotli4j.encoder.Encoder; 19 20 /** 21 * Standard Compression Options for {@link BrotliOptions}, 22 * {@link GzipOptions} and {@link DeflateOptions} 23 */ 24 public final class StandardCompressionOptions { 25 26 private StandardCompressionOptions() { 27 // Prevent outside initialization 28 } 29 30 /** 31 * Default implementation of {@link BrotliOptions} with {@link Encoder.Parameters#setQuality(int)} set to 4 32 * and {@link Encoder.Parameters#setMode(Encoder.Mode)} set to {@link Encoder.Mode#TEXT} 33 */ 34 public static BrotliOptions brotli() { 35 return BrotliOptions.DEFAULT; 36 } 37 38 /** 39 * Create a new {@link BrotliOptions} 40 * 41 * @param parameters {@link Encoder.Parameters} Instance 42 * @throws NullPointerException If {@link Encoder.Parameters} is {@code null} 43 */ 44 public static BrotliOptions brotli(Encoder.Parameters parameters) { 45 return new BrotliOptions(parameters); 46 } 47 48 /** 49 * Default implementation of {@link ZstdOptions} with{compressionLevel(int)} set to 50 * {@link ZstdConstants#DEFAULT_COMPRESSION_LEVEL},{@link ZstdConstants#DEFAULT_BLOCK_SIZE}, 51 * {@link ZstdConstants#MAX_BLOCK_SIZE} 52 */ 53 public static ZstdOptions zstd() { 54 return ZstdOptions.DEFAULT; 55 } 56 57 /** 58 * Create a new {@link ZstdOptions} 59 * 60 * @param blockSize 61 * is used to calculate the compressionLevel 62 * @param maxEncodeSize 63 * specifies the size of the largest compressed object 64 * @param compressionLevel 65 * specifies the level of the compression 66 */ 67 public static ZstdOptions zstd(int compressionLevel, int blockSize, int maxEncodeSize) { 68 return new ZstdOptions(compressionLevel, blockSize, maxEncodeSize); 69 } 70 71 /** 72 * Create a new {@link SnappyOptions} 73 * 74 */ 75 public static SnappyOptions snappy() { 76 return new SnappyOptions(); 77 } 78 79 /** 80 * Default implementation of {@link GzipOptions} with 81 * {@code compressionLevel()} set to 6, {@code windowBits()} set to 15 and {@code memLevel()} set to 8. 82 */ 83 public static GzipOptions gzip() { 84 return GzipOptions.DEFAULT; 85 } 86 87 /** 88 * Create a new {@link GzipOptions} Instance 89 * 90 * @param compressionLevel {@code 1} yields the fastest compression and {@code 9} yields the 91 * best compression. {@code 0} means no compression. The default 92 * compression level is {@code 6}. 93 * 94 * @param windowBits The base two logarithm of the size of the history buffer. The 95 * value should be in the range {@code 9} to {@code 15} inclusive. 96 * Larger values result in better compression at the expense of 97 * memory usage. The default value is {@code 15}. 98 * 99 * @param memLevel How much memory should be allocated for the internal compression 100 * state. {@code 1} uses minimum memory and {@code 9} uses maximum 101 * memory. Larger values result in better and faster compression 102 * at the expense of memory usage. The default value is {@code 8} 103 */ 104 public static GzipOptions gzip(int compressionLevel, int windowBits, int memLevel) { 105 return new GzipOptions(compressionLevel, windowBits, memLevel); 106 } 107 108 /** 109 * Default implementation of {@link DeflateOptions} with 110 * {@code compressionLevel} set to 6, {@code windowBits} set to 15 and {@code memLevel} set to 8. 111 */ 112 public static DeflateOptions deflate() { 113 return DeflateOptions.DEFAULT; 114 } 115 116 /** 117 * Create a new {@link DeflateOptions} Instance 118 * 119 * @param compressionLevel {@code 1} yields the fastest compression and {@code 9} yields the 120 * best compression. {@code 0} means no compression. The default 121 * compression level is {@code 6}. 122 * 123 * @param windowBits The base two logarithm of the size of the history buffer. The 124 * value should be in the range {@code 9} to {@code 15} inclusive. 125 * Larger values result in better compression at the expense of 126 * memory usage. The default value is {@code 15}. 127 * 128 * @param memLevel How much memory should be allocated for the internal compression 129 * state. {@code 1} uses minimum memory and {@code 9} uses maximum 130 * memory. Larger values result in better and faster compression 131 * at the expense of memory usage. The default value is {@code 8} 132 */ 133 public static DeflateOptions deflate(int compressionLevel, int windowBits, int memLevel) { 134 return new DeflateOptions(compressionLevel, windowBits, memLevel); 135 } 136 }