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 28, 2024
1 parent 953f2f3 commit 5042c28
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void write(byte[] buf, int offs, int len) throws IOException {
public void close() throws IOException {
zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA));
updateZip64();
writeDataDescriptor();
// writeDataDescriptor();
}

private void updateZip64() {
Expand All @@ -87,15 +87,15 @@ private void updateZip64() {
zipEntry.setZip64(true);
}

private void writeDataDescriptor() throws IOException {
if (!zipEntry.isDataDescriptorAvailable())
return;

DataDescriptor dataDescriptor = new DataDescriptor(zipEntry.getChecksum(),
zipEntry.getCompressedSize(),
zipEntry.getUncompressedSize());
DataDescriptorWriter.get(zipEntry.isZip64(), dataDescriptor).write(out);
}
// private void writeDataDescriptor() throws IOException {
// if (!zipEntry.isDataDescriptorAvailable())
// return;
//
// DataDescriptor dataDescriptor = new DataDescriptor(zipEntry.getChecksum(),
// zipEntry.getCompressedSize(),
// zipEntry.getUncompressedSize());
// DataDescriptorWriter.get(zipEntry.isZip64(), dataDescriptor).write(out);
// }

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ru.olegcherednik.zip4jvm.io.out.entry;

import lombok.RequiredArgsConstructor;
import org.apache.commons.io.IOUtils;

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

/**
Expand All @@ -28,6 +26,6 @@ public void write(byte[] buf, int offs, int len) throws IOException {

@Override
public void close() throws IOException {
//os.close();
os.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ru.olegcherednik.zip4jvm.io.out.entry.SequenceOutputStream;
import ru.olegcherednik.zip4jvm.io.out.entry.encrypted.EncryptedEntryOutputStream;
import ru.olegcherednik.zip4jvm.io.out.entry.xxx.LocalFileHeaderOut;
import ru.olegcherednik.zip4jvm.model.DataDescriptor;
import ru.olegcherednik.zip4jvm.model.entry.ZipEntry;
import ru.olegcherednik.zip4jvm.utils.function.Writer;

Expand Down Expand Up @@ -63,8 +64,6 @@ public void write(DataOutput out) throws IOException {

IOUtils.copyLarge(in, sos);

os.close();

// zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA));

// zipEntry.setCompressedSize(out.getWrittenBytesAmount(COMPRESSED_DATA));
Expand All @@ -75,9 +74,22 @@ public void write(DataOutput out) throws IOException {
a++;
}

writeDataDescriptor(zipEntry, out);


// ZipUtils.copyLarge(zipEntry.getInputStream(), sos);
}

private static void writeDataDescriptor(ZipEntry zipEntry, DataOutput out) throws IOException {
if (!zipEntry.isDataDescriptorAvailable())
return;

DataDescriptor dataDescriptor = new DataDescriptor(zipEntry.getChecksum(),
zipEntry.getCompressedSize(),
zipEntry.getUncompressedSize());
DataDescriptorWriter.get(zipEntry.isZip64(), dataDescriptor).write(out);
}

@Override
public String toString() {
return '+' + zipEntry.getFileName();
Expand Down

0 comments on commit 5042c28

Please sign in to comment.