Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Report actual read count instead of buffer size during transfer #82

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
jdk: openjdk8

services:
- docker
Expand All @@ -7,4 +8,7 @@ before_install:
- docker pull maven

script:
- mvn clean install -Dgpg.skip=true
# As noted at https://docs.travis-ci.com/user/languages/java/#projects-using-maven
# Travis always runs mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
# The following line runs if that succeeds
- mvn clean install
Original file line number Diff line number Diff line change
Expand Up @@ -24,71 +24,47 @@
public final class TransferProgressFileInputStream extends FileInputStream {

private final TransferProgress transferProgress;
private long byteLeft;




public TransferProgressFileInputStream(File file, TransferProgress transferProgress) throws IOException{
super(file);
this.transferProgress = transferProgress;
resetByteLeft();
}

private void resetByteLeft() throws IOException {
byteLeft = this.getChannel().size();
}

@Override
public synchronized void reset() throws IOException {
super.reset();
resetByteLeft();
}

@Override
public int read() throws IOException {
int b = super.read();
if(b != -1){
this.transferProgress.progress(new byte[]{(byte) b}, 1);
byteLeft--;
}//else we try to read but it was the end of the stream so nothing to report
return b;
}

@Override
public int read(byte b[]) throws IOException {
int count = super.read(b);
if (count != -1) {
this.transferProgress.progress(b, b.length);
byteLeft -= b.length;
}else{//end of the stream
this.transferProgress.progress(b, Math.toIntExact(byteLeft));
if (count < 1) {
return count;
}

this.transferProgress.progress(b, count);
return count;
}

@Override
public int read(byte b[], int off, int len) throws IOException {
int count = super.read(b, off, len);
if (off == 0) {
if (count != -1) {
this.transferProgress.progress(b, count);
byteLeft -= count;
}else{//end of the stream
this.transferProgress.progress(b, Math.toIntExact(byteLeft));
}
if (count < 1) {
return count;
}

if(off == 0) {
this.transferProgress.progress(b, count);
} else {
if (count != -1) {
byte[] bytes = new byte[count];
System.arraycopy(b, off, bytes, 0, count);
this.transferProgress.progress(bytes, len);
byteLeft -= count;
}else{//end of the stream
byte[] bytes = new byte[Math.toIntExact(byteLeft)];
System.arraycopy(b, off, bytes, 0, Math.toIntExact(byteLeft));
this.transferProgress.progress(b, Math.toIntExact(byteLeft));
}
byte[] bytes = new byte[count];
System.arraycopy(b, off, bytes, 0, count);
this.transferProgress.progress(bytes, count);
}

return count;
}
}
1 change: 1 addition & 0 deletions S3StorageWagon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!-- Tests that require an S3 setup with creadentials-->
<excludes>
Expand Down
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -84,6 +85,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -100,7 +105,7 @@
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
</goals>
Expand All @@ -117,6 +122,11 @@
<releaseProfiles>releases</releaseProfiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</build>

Expand Down