File tree Expand file tree Collapse file tree 1 file changed +4
-17
lines changed
src/main/java/com/maxmind/db Expand file tree Collapse file tree 1 file changed +4
-17
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,10 @@ final class BufferHolder {
1616 private final ByteBuffer buffer ;
1717
1818 BufferHolder (File database , FileMode mode ) throws IOException {
19- final RandomAccessFile file = new RandomAccessFile ( database , "r" );
20- boolean threw = true ;
21- try {
22- final FileChannel channel = file . getChannel ();
19+ try (
20+ final RandomAccessFile file = new RandomAccessFile ( database , "r" ) ;
21+ final FileChannel channel = file . getChannel ();
22+ ) {
2323 if (mode == FileMode .MEMORY ) {
2424 this .buffer = ByteBuffer .wrap (new byte [(int ) channel .size ()]);
2525 if (channel .read (this .buffer ) != this .buffer .capacity ()) {
@@ -30,19 +30,6 @@ final class BufferHolder {
3030 } else {
3131 this .buffer = channel .map (MapMode .READ_ONLY , 0 , channel .size ());
3232 }
33- threw = false ;
34- } finally {
35- try {
36- // Also closes the underlying channel.
37- file .close ();
38- } catch (final IOException e ) {
39- // If an exception was underway when we entered the finally
40- // block, don't stomp over it due to an error closing the file
41- // and channel.
42- if (!threw ) {
43- throw e ;
44- }
45- }
4633 }
4734 }
4835
You can’t perform that action at this time.
0 commit comments