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 fa7cf97 commit d3ea965
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.olegcherednik.zip4jvm.io.out.entry;

import ru.olegcherednik.zip4jvm.io.out.data.EncoderDataOutput;

import lombok.RequiredArgsConstructor;

import java.io.IOException;
import java.io.OutputStream;

/**
* This is an output stream decorator, that is responsible for data encryption.
*
* @author Oleg Cherednik
* @since 29.10.2024
*/
@RequiredArgsConstructor
public class EncryptedOutputStream extends OutputStream {

private final EncoderDataOutput encoderDataOutput;
private final OutputStream delegate;

@Override
public final void write(int b) throws IOException {
delegate.write(b);
}

@Override
public void write(byte[] buf, int offs, int len) throws IOException {
delegate.write(buf, offs, len);
}

@Override
public void close() throws IOException {
delegate.close();
}
}
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.io.out.data.EncoderDataOutput;
import ru.olegcherednik.zip4jvm.io.out.entry.EncryptedOutputStream;
import ru.olegcherednik.zip4jvm.io.out.entry.PayloadCalculationOutputStream;
import ru.olegcherednik.zip4jvm.io.out.entry.encrypted.EncryptedEntryOutputStream;
import ru.olegcherednik.zip4jvm.io.out.entry.xxx.DataDescriptorOut;
Expand Down Expand Up @@ -49,7 +50,8 @@ public final class ZipEntryWriter implements Writer {
@Override
public void write(DataOutput out) throws IOException {
EncoderDataOutput encoderDataOutput = new EncoderDataOutput(zipEntry.createEncoder(), out);
EncryptedEntryOutputStream eos = EncryptedEntryOutputStream.create(zipEntry, encoderDataOutput);
EncryptedEntryOutputStream eeos = EncryptedEntryOutputStream.create(zipEntry, encoderDataOutput);
EncryptedOutputStream eos = new EncryptedOutputStream(encoderDataOutput, eeos);

zipEntry.setDiskNo(out.getDiskNo());

Expand Down

0 comments on commit d3ea965

Please sign in to comment.