mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-13 01:22:41 +01:00
Use try-with-resources
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user