Skip to content

Commit

Permalink
Merge branch 'master' into feature/multiHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave authored Dec 1, 2024
2 parents b70f2ff + 2a64f26 commit 9fbefac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* OutputStream implementation that conditionally compresses the output based on configuration and
* request headers.
*/
public class CompressedOutputStream extends OutputStream {
public final class CompressedOutputStream extends OutputStream {

private final int minSizeForCompression;
private final CompressionConfig compression;
private final Context ctx;

private final OutputStream originStream;

private OutputStream compressedStream;
private boolean compressionDecided;

Expand All @@ -33,9 +33,7 @@ public CompressedOutputStream(
private void decideCompression(int length) throws IOException {
if (!compressionDecided) {
var encoding = ctx.responseHeader(Constants.CONTENT_ENCODING);

if (encoding != null) {

this.compressedStream =
findMatchingCompressor(encoding)
.orElseThrow(
Expand Down Expand Up @@ -81,9 +79,7 @@ public void close() throws IOException {
}

private Optional<Compressor> findMatchingCompressor(String acceptedEncoding) {

if (acceptedEncoding != null) {

return Arrays.stream(acceptedEncoding.split(",")).map(compression::forType).findFirst();
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public OutputStream compress(OutputStream out) throws IOException {
return new LeveledGzipStream(out, level);
}

static class LeveledGzipStream extends GZIPOutputStream {
private static final class LeveledGzipStream extends GZIPOutputStream {

public LeveledGzipStream(OutputStream out, int level) throws IOException {
private LeveledGzipStream(OutputStream out, int level) throws IOException {
super(out);
this.def.setLevel(level);
}
Expand Down

0 comments on commit 9fbefac

Please sign in to comment.