Use try-with-resources

This commit is contained in:
Peter Osterlund
2019-05-25 09:05:57 +02:00
parent 16e7c34337
commit 3363b1d9c0
21 changed files with 146 additions and 258 deletions

View File

@@ -54,8 +54,7 @@ public class Book {
rndGen = new SecureRandom();
rndGen.setSeed(System.currentTimeMillis());
numBookMoves = 0;
try {
InputStream inStream = getClass().getResourceAsStream("/book.bin");
try (InputStream inStream = getClass().getResourceAsStream("/book.bin")) {
List<Byte> buf = new ArrayList<>(8192);
byte[] tmpBuf = new byte[1024];
while (true) {
@@ -64,7 +63,6 @@ public class Book {
for (int i = 0; i < len; i++)
buf.add(tmpBuf[i]);
}
inStream.close();
Position startPos = TextIO.readFEN(TextIO.startPosFEN);
Position pos = new Position(startPos);
UndoInfo ui = new UndoInfo();

View File

@@ -236,8 +236,7 @@ public class Evaluate {
private byte[] readTable(String resource, int length) {
byte[] table = new byte[2*32*64*48/8];
InputStream inStream = getClass().getResourceAsStream(resource);
try {
try (InputStream inStream = getClass().getResourceAsStream(resource)) {
int off = 0;
while (off < table.length) {
int len = inStream.read(table, off, table.length - off);
@@ -245,10 +244,9 @@ public class Evaluate {
throw new RuntimeException();
off += len;
}
inStream.close();
return table;
} catch (IOException e) {
throw new RuntimeException();
throw new RuntimeException(e);
}
}