1616package io .netty .handler .codec .compression ;
1717
1818import com .aayushatharva .brotli4j .encoder .Encoder ;
19+ import io .netty .util .internal .ObjectUtil ;
1920
2021/**
2122 * Standard Compression Options for {@link BrotliOptions},
@@ -40,11 +41,33 @@ public static BrotliOptions brotli() {
4041 *
4142 * @param parameters {@link Encoder.Parameters} Instance
4243 * @throws NullPointerException If {@link Encoder.Parameters} is {@code null}
44+ * @deprecated Use {@link #brotli(int, int, BrotliMode)}
4345 */
46+ @ Deprecated
4447 public static BrotliOptions brotli (Encoder .Parameters parameters ) {
4548 return new BrotliOptions (parameters );
4649 }
4750
51+ /**
52+ * Create a new {@link BrotliOptions}
53+ *
54+ * @param quality Specifies the compression level.
55+ * @param window Specifies the size of the sliding window when compressing.
56+ * @param mode optimizes the compression algorithm based on the type of input data.
57+ * @throws NullPointerException If {@link BrotliMode} is {@code null}
58+ */
59+ public static BrotliOptions brotli (int quality , int window , BrotliMode mode ) {
60+ ObjectUtil .checkInRange (quality , 0 , 11 , "quality" );
61+ ObjectUtil .checkInRange (window , 10 , 24 , "window" );
62+ ObjectUtil .checkNotNull (mode , "mode" );
63+
64+ Encoder .Parameters parameters = new Encoder .Parameters ()
65+ .setQuality (quality )
66+ .setWindow (window )
67+ .setMode (mode .adapt ());
68+ return new BrotliOptions (parameters );
69+ }
70+
4871 /**
4972 * Default implementation of {@link ZstdOptions} with{compressionLevel(int)} set to
5073 * {@link ZstdConstants#DEFAULT_COMPRESSION_LEVEL},{@link ZstdConstants#DEFAULT_BLOCK_SIZE},
@@ -57,26 +80,22 @@ public static ZstdOptions zstd() {
5780 /**
5881 * Create a new {@link ZstdOptions}
5982 *
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
83+ * @param blockSize is used to calculate the compressionLevel
84+ * @param maxEncodeSize specifies the size of the largest compressed object
85+ * @param compressionLevel specifies the level of the compression
6686 */
6787 public static ZstdOptions zstd (int compressionLevel , int blockSize , int maxEncodeSize ) {
6888 return new ZstdOptions (compressionLevel , blockSize , maxEncodeSize );
6989 }
7090
7191 /**
7292 * Create a new {@link SnappyOptions}
73- *
7493 */
7594 public static SnappyOptions snappy () {
7695 return new SnappyOptions ();
7796 }
7897
79- /**
98+ /**
8099 * Default implementation of {@link GzipOptions} with
81100 * {@code compressionLevel()} set to 6, {@code windowBits()} set to 15 and {@code memLevel()} set to 8.
82101 */
@@ -90,12 +109,10 @@ public static GzipOptions gzip() {
90109 * @param compressionLevel {@code 1} yields the fastest compression and {@code 9} yields the
91110 * best compression. {@code 0} means no compression. The default
92111 * compression level is {@code 6}.
93- *
94112 * @param windowBits The base two logarithm of the size of the history buffer. The
95113 * value should be in the range {@code 9} to {@code 15} inclusive.
96114 * Larger values result in better compression at the expense of
97115 * memory usage. The default value is {@code 15}.
98- *
99116 * @param memLevel How much memory should be allocated for the internal compression
100117 * state. {@code 1} uses minimum memory and {@code 9} uses maximum
101118 * memory. Larger values result in better and faster compression
@@ -119,12 +136,10 @@ public static DeflateOptions deflate() {
119136 * @param compressionLevel {@code 1} yields the fastest compression and {@code 9} yields the
120137 * best compression. {@code 0} means no compression. The default
121138 * compression level is {@code 6}.
122- *
123139 * @param windowBits The base two logarithm of the size of the history buffer. The
124140 * value should be in the range {@code 9} to {@code 15} inclusive.
125141 * Larger values result in better compression at the expense of
126142 * memory usage. The default value is {@code 15}.
127- *
128143 * @param memLevel How much memory should be allocated for the internal compression
129144 * state. {@code 1} uses minimum memory and {@code 9} uses maximum
130145 * memory. Larger values result in better and faster compression
0 commit comments