33import com .github .luben .zstd .Zstd ;
44import com .github .luben .zstd .ZstdInputStream ;
55import com .github .luben .zstd .ZstdOutputStream ;
6- import io .netty .buffer .ByteBuf ;
7- import io .netty .buffer .ByteBufInputStream ;
8- import io .netty .buffer .ByteBufOutputStream ;
96import java .io .IOException ;
107import java .io .InputStream ;
118import java .io .OutputStream ;
3027import org .xerial .snappy .SnappyFramedInputStream ;
3128import org .xerial .snappy .SnappyFramedOutputStream ;
3229
33- /**
34- * Implementation of {@link CompressionCodec}s.
35- */
30+ /** Implementation of {@link CompressionCodec}s. */
3631public final class CompressionUtils {
3732
3833 private CompressionUtils () {}
@@ -45,18 +40,18 @@ public int maxCompressedLength(int sourceLength) {
4540 }
4641
4742 @ Override
48- public OutputStream compress (ByteBuf byteBuf ) {
43+ public OutputStream compress (OutputStream outputStream ) {
4944 try {
50- return new GZIPOutputStream (new ByteBufOutputStream ( byteBuf ) );
45+ return new GZIPOutputStream (outputStream );
5146 } catch (IOException e ) {
5247 throw new CompressionException ("Error while creating GZIP compression output stream" , e );
5348 }
5449 }
5550
5651 @ Override
57- public InputStream decompress (ByteBuf byteBuf ) {
52+ public InputStream decompress (InputStream inputStream ) {
5853 try {
59- return new GZIPInputStream (new ByteBufInputStream ( byteBuf ) );
54+ return new GZIPInputStream (inputStream );
6055 } catch (IOException e ) {
6156 throw new CompressionException ("Error while creating GZIP compression input stream" , e );
6257 }
@@ -81,18 +76,18 @@ public int maxCompressedLength(int sourceLength) {
8176 }
8277
8378 @ Override
84- public OutputStream compress (ByteBuf byteBuf ) {
79+ public OutputStream compress (OutputStream outputStream ) {
8580 try {
86- return new ZstdOutputStream (new ByteBufOutputStream ( byteBuf ) );
81+ return new ZstdOutputStream (outputStream );
8782 } catch (IOException e ) {
8883 throw new CompressionException ("Error while creating Zstd compression output stream" , e );
8984 }
9085 }
9186
9287 @ Override
93- public InputStream decompress (ByteBuf byteBuf ) {
88+ public InputStream decompress (InputStream inputStream ) {
9489 try {
95- return new ZstdInputStream (new ByteBufInputStream ( byteBuf ) );
90+ return new ZstdInputStream (inputStream );
9691 } catch (IOException e ) {
9792 throw new CompressionException ("Error while creating Zstd compression input stream" , e );
9893 }
@@ -120,19 +115,18 @@ public int maxCompressedLength(int sourceLength) {
120115 }
121116
122117 @ Override
123- public OutputStream compress (ByteBuf byteBuf ) {
118+ public OutputStream compress (OutputStream outputStream ) {
124119 try {
125- return new LZ4FrameOutputStream (
126- new ByteBufOutputStream (byteBuf ), BLOCKSIZE .SIZE_64KB , DEFAULT_FEATURES );
120+ return new LZ4FrameOutputStream (outputStream , BLOCKSIZE .SIZE_64KB , DEFAULT_FEATURES );
127121 } catch (IOException e ) {
128122 throw new CompressionException ("Error while creating LZ4 compression output stream" , e );
129123 }
130124 }
131125
132126 @ Override
133- public InputStream decompress (ByteBuf byteBuf ) {
127+ public InputStream decompress (InputStream inputStream ) {
134128 try {
135- return new LZ4FrameInputStream (new ByteBufInputStream ( byteBuf ) );
129+ return new LZ4FrameInputStream (inputStream );
136130 } catch (IOException e ) {
137131 throw new CompressionException ("Error while creating LZ4 compression input stream" , e );
138132 }
@@ -157,18 +151,18 @@ public int maxCompressedLength(int sourceLength) {
157151 }
158152
159153 @ Override
160- public OutputStream compress (ByteBuf byteBuf ) {
154+ public OutputStream compress (OutputStream outputStream ) {
161155 try {
162- return new SnappyFramedOutputStream (new ByteBufOutputStream ( byteBuf ) );
156+ return new SnappyFramedOutputStream (outputStream );
163157 } catch (IOException e ) {
164158 throw new CompressionException ("Error while creating snappy compression output stream" , e );
165159 }
166160 }
167161
168162 @ Override
169- public InputStream decompress (ByteBuf byteBuf ) {
163+ public InputStream decompress (InputStream inputStream ) {
170164 try {
171- return new SnappyFramedInputStream (new ByteBufInputStream ( byteBuf ) );
165+ return new SnappyFramedInputStream (inputStream );
172166 } catch (IOException e ) {
173167 throw new CompressionException ("Error while creating snappy compression input stream" , e );
174168 }
@@ -193,18 +187,18 @@ public int maxCompressedLength(int sourceLength) {
193187 }
194188
195189 @ Override
196- public OutputStream compress (ByteBuf byteBuf ) {
190+ public OutputStream compress (OutputStream outputStream ) {
197191 try {
198- return new GzipCompressorOutputStream (new ByteBufOutputStream ( byteBuf ) );
192+ return new GzipCompressorOutputStream (outputStream );
199193 } catch (IOException e ) {
200194 throw new CompressionException ("Error while creating GZIP compression output stream" , e );
201195 }
202196 }
203197
204198 @ Override
205- public InputStream decompress (ByteBuf byteBuf ) {
199+ public InputStream decompress (InputStream inputStream ) {
206200 try {
207- return new GzipCompressorInputStream (new ByteBufInputStream ( byteBuf ) );
201+ return new GzipCompressorInputStream (inputStream );
208202 } catch (IOException e ) {
209203 throw new CompressionException ("Error while creating GZIP compression input stream" , e );
210204 }
@@ -230,21 +224,19 @@ public int maxCompressedLength(int sourceLength) {
230224 }
231225
232226 @ Override
233- public OutputStream compress (ByteBuf byteBuf ) {
227+ public OutputStream compress (OutputStream outputStream ) {
234228 try {
235- return new FramedSnappyCompressorOutputStream (new ByteBufOutputStream ( byteBuf ) );
229+ return new FramedSnappyCompressorOutputStream (outputStream );
236230 } catch (IOException e ) {
237231 throw new CompressionException ("Error while creating Snappy compression output stream" , e );
238232 }
239233 }
240234
241235 @ Override
242- public InputStream decompress (ByteBuf byteBuf ) {
236+ public InputStream decompress (InputStream inputStream ) {
243237 try {
244238 return new FramedSnappyCompressorInputStream (
245- new ByteBufInputStream (byteBuf ),
246- SnappyFramedOutputStream .DEFAULT_BLOCK_SIZE ,
247- FramedSnappyDialect .STANDARD );
239+ inputStream , SnappyFramedOutputStream .DEFAULT_BLOCK_SIZE , FramedSnappyDialect .STANDARD );
248240 } catch (IOException e ) {
249241 throw new CompressionException ("Error while creating Snappy compression input stream" , e );
250242 }
@@ -272,18 +264,18 @@ public int maxCompressedLength(int sourceLength) {
272264 }
273265
274266 @ Override
275- public OutputStream compress (ByteBuf byteBuf ) {
267+ public OutputStream compress (OutputStream outputStream ) {
276268 try {
277- return new FramedLZ4CompressorOutputStream (new ByteBufOutputStream ( byteBuf ) , DEFAULT );
269+ return new FramedLZ4CompressorOutputStream (outputStream , DEFAULT );
278270 } catch (IOException e ) {
279271 throw new CompressionException ("Error while creating LZ4 compression output stream" , e );
280272 }
281273 }
282274
283275 @ Override
284- public InputStream decompress (ByteBuf byteBuf ) {
276+ public InputStream decompress (InputStream inputStream ) {
285277 try {
286- return new FramedLZ4CompressorInputStream (new ByteBufInputStream ( byteBuf ) );
278+ return new FramedLZ4CompressorInputStream (inputStream );
287279 } catch (IOException e ) {
288280 throw new CompressionException ("Error while creating LZ4 compression input stream" , e );
289281 }
@@ -308,18 +300,18 @@ public int maxCompressedLength(int sourceLength) {
308300 }
309301
310302 @ Override
311- public OutputStream compress (ByteBuf byteBuf ) {
303+ public OutputStream compress (OutputStream outputStream ) {
312304 try {
313- return new ZstdCompressorOutputStream (new ByteBufOutputStream ( byteBuf ) );
305+ return new ZstdCompressorOutputStream (outputStream );
314306 } catch (IOException e ) {
315307 throw new CompressionException ("Error while creating Zstd compression output stream" , e );
316308 }
317309 }
318310
319311 @ Override
320- public InputStream decompress (ByteBuf byteBuf ) {
312+ public InputStream decompress (InputStream inputStream ) {
321313 try {
322- return new ZstdCompressorInputStream (new ByteBufInputStream ( byteBuf ) );
314+ return new ZstdCompressorInputStream (inputStream );
323315 } catch (IOException e ) {
324316 throw new CompressionException ("Error while creating Zstd compression input stream" , e );
325317 }
0 commit comments