Skip to content

Commit

Permalink
Encoder refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-cherednik committed Nov 5, 2024
1 parent f1f18df commit 8d70953
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public EncryptedDataOutput(Encoder encoder, DataOutput out) {
this.encoder = encoder;
}

public void writeEncryptionHeader() throws IOException {
encoder.writeEncryptionHeader(delegate);
public void writeEncryptionHeader(DataOutput out) throws IOException {
encoder.writeEncryptionHeader(out);
}

public void encodingAccomplished() throws IOException {
encoder.close(delegate);
public void encodingAccomplished(DataOutput out) throws IOException {
encoder.close(out);
}

// ---------- OutputStream ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ByteOrderDataOutput extends BaseDataOutput {

private final ByteOrderConverter byteOrderConverter;

protected ByteOrderDataOutput(DataOutput delegate) {
public ByteOrderDataOutput(DataOutput delegate) {
super(delegate);
byteOrderConverter = new ByteOrderConverter(delegate.getByteOrder());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public void write(DataOutput out) throws IOException {
private void foo(DataOutput out) throws IOException {
out.mark(COMPRESSED_DATA);

EncryptedDataOutput encryptedDataOutput = EncryptedDataOutput.create(zipEntry, out);
DataOutput cos = CompressedEntryDataOutput.create(zipEntry, encryptedDataOutput);
EncryptedDataOutput edo = EncryptedDataOutput.create(zipEntry, out);
DataOutput cos = CompressedEntryDataOutput.create(zipEntry, edo);

encryptedDataOutput.writeEncryptionHeader();
edo.writeEncryptionHeader(out);

try (InputStream in = zipEntry.getInputStream();
PayloadCalculationOutputStream os = new PayloadCalculationOutputStream(zipEntry, cos)) {
Expand All @@ -104,7 +104,7 @@ private void foo(DataOutput out) throws IOException {
}

// TODO Why out is closed and not exception
encryptedDataOutput.encodingAccomplished();
edo.encodingAccomplished(out);
zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ private void foo(DataOutput out) throws IOException {
EncryptedDataOutput encryptedDataOutput = EncryptedDataOutput.create(zipEntry, out);
DataOutput cos = CompressedEntryDataOutput.create(zipEntry, encryptedDataOutput);

encryptedDataOutput.writeEncryptionHeader();
encryptedDataOutput.writeEncryptionHeader(out);

try (InputStream in = zipEntry.getInputStream();
PayloadCalculationOutputStream os = new PayloadCalculationOutputStream(zipEntry, cos)) {
IOUtils.copyLarge(in, os);
}

encryptedDataOutput.encodingAccomplished();
encryptedDataOutput.encodingAccomplished(out);
zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA));
}

Expand Down

0 comments on commit 8d70953

Please sign in to comment.