Skip to content

Commit

Permalink
#190 Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed May 27, 2020
1 parent dcc9b83 commit b2f8fa6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/main/java/net/lingala/zip4j/headers/HeaderWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.io.outputstream.CountingOutputStream;
import net.lingala.zip4j.io.outputstream.OutputStreamWithSplitZipSupport;
import net.lingala.zip4j.io.outputstream.SplitOutputStream;
import net.lingala.zip4j.model.AESExtraDataRecord;
import net.lingala.zip4j.model.ExtraDataRecord;
Expand Down Expand Up @@ -348,10 +349,10 @@ private void writeZipHeaderBytes(ZipModel zipModel, OutputStream outputStream, b

private void processHeaderData(ZipModel zipModel, OutputStream outputStream) throws IOException {
int currentSplitFileCounter = 0;
if (outputStream instanceof CountingOutputStream) {
if (outputStream instanceof OutputStreamWithSplitZipSupport) {
zipModel.getEndOfCentralDirectoryRecord().setOffsetOfStartOfCentralDirectory(
((CountingOutputStream) outputStream).getFilePointer());
currentSplitFileCounter = ((CountingOutputStream) outputStream).getCurrentSplitFileCounter();
((OutputStreamWithSplitZipSupport) outputStream).getFilePointer());
currentSplitFileCounter = ((OutputStreamWithSplitZipSupport) outputStream).getCurrentSplitFileCounter();
}

if (zipModel.isZip64Format()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.IOException;
import java.io.OutputStream;

public class CountingOutputStream extends OutputStream {
public class CountingOutputStream extends OutputStream implements OutputStreamWithSplitZipSupport {

private OutputStream outputStream;
private long numberOfBytesWritten = 0;
Expand All @@ -30,6 +30,7 @@ public void write(byte[] b, int off, int len) throws IOException {
numberOfBytesWritten += len;
}

@Override
public int getCurrentSplitFileCounter() {
if (isSplitZipFile()) {
return ((SplitOutputStream) outputStream).getCurrentSplitFileCounter();
Expand Down Expand Up @@ -75,6 +76,7 @@ public boolean checkBuffSizeAndStartNextSplitFile(int bufferSize) throws ZipExce
return ((SplitOutputStream)outputStream).checkBufferSizeAndStartNextSplitFile(bufferSize);
}

@Override
public long getFilePointer() throws IOException {
if (outputStream instanceof SplitOutputStream) {
return ((SplitOutputStream) outputStream).getFilePointer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.lingala.zip4j.io.outputstream;

import java.io.IOException;

public interface OutputStreamWithSplitZipSupport {

long getFilePointer() throws IOException;

int getCurrentSplitFileCounter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static net.lingala.zip4j.util.FileUtils.getZipFileNameWithoutExtension;
import static net.lingala.zip4j.util.InternalZipConstants.MIN_SPLIT_LENGTH;

public class SplitOutputStream extends OutputStream {
public class SplitOutputStream extends OutputStream implements OutputStreamWithSplitZipSupport {

private RandomAccessFile raf;
private long splitLength;
Expand Down Expand Up @@ -192,6 +192,7 @@ public void close() throws IOException {
raf.close();
}

@Override
public long getFilePointer() throws IOException {
return raf.getFilePointer();
}
Expand All @@ -204,6 +205,7 @@ public long getSplitLength() {
return splitLength;
}

@Override
public int getCurrentSplitFileCounter() {
return currSplitFileCounter;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/lingala/zip4j/tasks/RenameFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.headers.HeaderUtil;
import net.lingala.zip4j.headers.HeaderWriter;
import net.lingala.zip4j.io.outputstream.CountingOutputStream;
import net.lingala.zip4j.io.outputstream.SplitOutputStream;
import net.lingala.zip4j.model.FileHeader;
import net.lingala.zip4j.model.ZipModel;
Expand Down Expand Up @@ -48,7 +47,7 @@ protected void executeTask(RenameFilesTaskParameters taskParameters, ProgressMon
File temporaryFile = getTemporaryFile(zipModel.getZipFile().getPath());
boolean successFlag = false;
try(RandomAccessFile inputStream = new RandomAccessFile(zipModel.getZipFile(), RandomAccessFileMode.WRITE.getValue());
CountingOutputStream outputStream = new CountingOutputStream(new SplitOutputStream(temporaryFile))) {
SplitOutputStream outputStream = new SplitOutputStream(temporaryFile)) {

long currentFileCopyPointer = 0;

Expand Down

0 comments on commit b2f8fa6

Please sign in to comment.