Package com.cedarsoftware.util
Class AdjustableGZIPOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
java.util.zip.GZIPOutputStream
com.cedarsoftware.util.AdjustableGZIPOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
A customizable extension of
GZIPOutputStream
that allows users to specify the compression level.
AdjustableGZIPOutputStream
enhances the functionality of GZIPOutputStream
by providing
constructors that let users configure the compression level, enabling control over the trade-off between
compression speed and compression ratio.
Key Features
- Supports all compression levels defined by
Deflater
, including:Deflater.DEFAULT_COMPRESSION
Deflater.BEST_SPEED
Deflater.BEST_COMPRESSION
- Specific levels from 0 (no compression) to 9 (maximum compression).
- Provides constructors to set both the compression level and buffer size.
- Fully compatible with the standard
GZIPOutputStream
API.
Usage Example
try (OutputStream fileOut = Files.newOutputStream(Paths.get("compressed.gz"));
AdjustableGZIPOutputStream gzipOut = new AdjustableGZIPOutputStream(fileOut, Deflater.BEST_COMPRESSION)) {
gzipOut.write("Example data to compress".getBytes(StandardCharsets.UTF_8));
}
Additional Notes
- If the specified compression level is invalid, a
IllegalArgumentException
will be thrown. - The default compression level is
Deflater.DEFAULT_COMPRESSION
when not specified. - The
AdjustableGZIPOutputStream
inherits all thread-safety properties ofGZIPOutputStream
.
- Author:
- John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - See Also:
-
Field Summary
Fields inherited from class java.util.zip.GZIPOutputStream
crc
Fields inherited from class java.util.zip.DeflaterOutputStream
buf, def
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionAdjustableGZIPOutputStream
(OutputStream out, int level) AdjustableGZIPOutputStream
(OutputStream out, int size, int level) -
Method Summary
Methods inherited from class java.util.zip.GZIPOutputStream
finish, write
Methods inherited from class java.util.zip.DeflaterOutputStream
close, deflate, flush, write
Methods inherited from class java.io.FilterOutputStream
write
-
Constructor Details
-
AdjustableGZIPOutputStream
- Throws:
IOException
-
AdjustableGZIPOutputStream
- Throws:
IOException
-