Skip to content

Commit

Permalink
#3 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik committed Oct 29, 2024
1 parent ff02615 commit dede5f8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ru.olegcherednik.zip4jvm.io.bzip2.Bzip2OutputStream;
import ru.olegcherednik.zip4jvm.io.out.data.DataOutput;
import ru.olegcherednik.zip4jvm.model.CompressionLevel;
import ru.olegcherednik.zip4jvm.utils.quitely.Quietly;

import java.io.IOException;

Expand All @@ -32,8 +33,8 @@ final class Bzip2EntryOutputStream extends CompressedEntryOutputStream {

private final Bzip2OutputStream bzip2;

Bzip2EntryOutputStream(DataOutput out, CompressionLevel compressionLevel) throws IOException {
bzip2 = new Bzip2OutputStream(out, compressionLevel);
Bzip2EntryOutputStream(DataOutput out, CompressionLevel compressionLevel) {
bzip2 = Quietly.doQuietly(() -> new Bzip2OutputStream(out, compressionLevel));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class CompressedEntryOutputStream extends OutputStream {

public static CompressedEntryOutputStream create(ZipEntry entry, DataOutput out) throws IOException {
public static CompressedEntryOutputStream create(ZipEntry entry, DataOutput out) {
CompressionMethod compressionMethod = entry.getCompressionMethod();
CompressionLevel compressionLevel = entry.getCompressionLevel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ru.olegcherednik.zip4jvm.io.lzma.LzmaOutputStream;
import ru.olegcherednik.zip4jvm.io.out.data.DataOutput;
import ru.olegcherednik.zip4jvm.model.CompressionLevel;
import ru.olegcherednik.zip4jvm.utils.quitely.Quietly;

import java.io.IOException;

Expand All @@ -35,18 +36,19 @@ final class LzmaEntryOutputStream extends CompressedEntryOutputStream {
private final LzmaOutputStream lzma;
private boolean writeHeader = true;

LzmaEntryOutputStream(DataOutput out, CompressionLevel compressionLevel, boolean eosMarker, long uncompressedSize)
throws IOException {
LzmaEntryOutputStream(DataOutput out, CompressionLevel compressionLevel, boolean eosMarker, long uncompressedSize) {
this.out = out;
lzma = createOutputStream(out, compressionLevel, eosMarker, uncompressedSize);
}

private static LzmaOutputStream createOutputStream(DataOutput out,
CompressionLevel compressionLevel,
boolean eosMarker,
long uncompressedSize) throws IOException {
LzmaInputStream.Properties properties = new LzmaInputStream.Properties(compressionLevel);
return new LzmaOutputStream(out, properties, eosMarker ? -1 : uncompressedSize);
long uncompressedSize) {
return Quietly.doQuietly(() -> {
LzmaInputStream.Properties properties = new LzmaInputStream.Properties(compressionLevel);
return new LzmaOutputStream(out, properties, eosMarker ? -1 : uncompressedSize);
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class ZstdEntryOutputStream extends CompressedEntryOutputStream {
private final DataOutput out;
private final ZstdOutputStream zstd;

ZstdEntryOutputStream(DataOutput out, CompressionLevel compressionLevel) throws IOException {
ZstdEntryOutputStream(DataOutput out, CompressionLevel compressionLevel) {
this.out = out;
zstd = new ZstdOutputStream(out, compressionLevel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ru.olegcherednik.zip4jvm.io.out.data.DataOutput;
import ru.olegcherednik.zip4jvm.model.CompressionLevel;
import ru.olegcherednik.zip4jvm.utils.quitely.Quietly;

import lombok.RequiredArgsConstructor;

Expand All @@ -34,8 +35,12 @@ public class ZstdOutputStream extends OutputStream {

private final com.github.luben.zstd.ZstdOutputStream out;

public ZstdOutputStream(DataOutput out, CompressionLevel compressionLevel) throws IOException {
this.out = new com.github.luben.zstd.ZstdOutputStream(new Decorator(out), compressionLevel(compressionLevel));
public ZstdOutputStream(DataOutput out, CompressionLevel compressionLevel) {
this.out = Quietly.doQuietly(() -> {
OutputStream outStream = new Decorator(out);
int level = compressionLevel(compressionLevel);
return new com.github.luben.zstd.ZstdOutputStream(outStream, level);
});
}

private static int compressionLevel(CompressionLevel compressionLevel) {
Expand Down

0 comments on commit dede5f8

Please sign in to comment.