Skip to content

Commit

Permalink
improved reading InputStream to byte array, in case when we read not …
Browse files Browse the repository at this point in the history
…from file, but from a stream with unknown size
  • Loading branch information
bugy committed Apr 17, 2014
1 parent 2b79fa0 commit 8f3ed84
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/net/iryndin/jdbf/reader/DbfReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,14 @@ private DbfRecord createDbfRecord() {
}

private static byte[] toByteArray(InputStream input) throws IOException {
byte[] result = new byte[input.available()];
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int offset = 0;
int bufferLength;
while ((bufferLength = input.read(buffer)) > 0) {
System.arraycopy(buffer, 0, result, offset, bufferLength);

offset += bufferLength;
byte[] data = new byte[DEFAULT_BUFFER_SIZE];
int dataLength;
while ((dataLength = input.read(data)) > 0) {
buffer.write(data, 0, dataLength);
}

return result;
return buffer.toByteArray();
}
}

0 comments on commit 8f3ed84

Please sign in to comment.