Skip to content

Commit

Permalink
#146: LengthOfInput closes Input
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 15, 2017
1 parent c952ae6 commit da2b7e3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/org/cactoos/io/LengthOfInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ public LengthOfInput(final Input input, final int max) {

@Override
public Long asValue() throws IOException {
final InputStream stream = this.source.stream();
final byte[] buf = new byte[this.size];
long length = 0L;
while (true) {
final int len = stream.read(buf);
if (len > 0) {
length += (long) len;
}
if (len != buf.length) {
break;
try (final InputStream stream = this.source.stream()) {
final byte[] buf = new byte[this.size];
long length = 0L;
while (true) {
final int len = stream.read(buf);
if (len > 0) {
length += (long) len;
}
if (len != buf.length) {
break;
}
}
return length;
}
return length;
}

}

0 comments on commit da2b7e3

Please sign in to comment.