Skip to content

Commit

Permalink
Fix bugs that the input stream is not closed when reading files in th…
Browse files Browse the repository at this point in the history
…e samples
  • Loading branch information
Yongwoo Lee committed Dec 21, 2018
1 parent 2b57405 commit 690e43a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ private byte[] readFile() throws IOException {
}

private byte[] readBytes(File file) throws IOException {
int length = (int) file.length();
long length = file.length();
if (length > Integer.MAX_VALUE) throw new OutOfMemoryError("File is too big!!");
byte[] result = new byte[length];
DataInputStream inputStream = new DataInputStream(new FileInputStream(file));
inputStream.readFully(result);
byte[] result = new byte[(int) length];
try (DataInputStream inputStream = new DataInputStream(new FileInputStream(file))) {
inputStream.readFully(result);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void sendTransaction() throws IOException {

SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet);
Bytes hash = iconService.sendTransaction(signedTransaction).execute();
System.out.println("txHash:"+hash);
System.out.println("txHash:" + hash);
}

private byte[] readFile() throws IOException {
Expand All @@ -90,11 +90,12 @@ private byte[] readFile() throws IOException {
}

private byte[] readBytes(File file) throws IOException {
int length = (int) file.length();
long length = file.length();
if (length > Integer.MAX_VALUE) throw new OutOfMemoryError("File is too big!!");
byte[] result = new byte[length];
DataInputStream inputStream = new DataInputStream(new FileInputStream(file));
inputStream.readFully(result);
byte[] result = new byte[(int) length];
try (DataInputStream inputStream = new DataInputStream(new FileInputStream(file))) {
inputStream.readFully(result);
}
return result;
}

Expand Down

0 comments on commit 690e43a

Please sign in to comment.