Skip to content

Commit 5ae56a6

Browse files
committed
Make reader implement Closeable
1 parent 8c50de1 commit 5ae56a6

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/main/java/com/maxmind/maxminddb/Reader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.maxmind.maxminddb;
22

3+
import java.io.Closeable;
34
import java.io.File;
45
import java.io.IOException;
56
import java.net.InetAddress;
@@ -11,7 +12,7 @@
1112
* Instances of this class provide a reader for the MaxMind DB format. IP
1213
* addresses can be looked up using the <code>get</code> method.
1314
*/
14-
public final class Reader {
15+
public final class Reader implements Closeable {
1516
private static final int DATA_SECTION_SEPARATOR_SIZE = 16;
1617
private static final byte[] METADATA_START_MARKER = { (byte) 0xAB,
1718
(byte) 0xCD, (byte) 0xEF, 'M', 'a', 'x', 'M', 'i', 'n', 'd', '.',
@@ -262,6 +263,7 @@ Metadata getMetadata() {
262263
* @throws IOException
263264
* if an I/O error occurs.
264265
*/
266+
@Override
265267
public void close() throws IOException {
266268
this.threadBuffer.close();
267269
}

src/main/java/com/maxmind/maxminddb/ThreadBuffer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.maxmind.maxminddb;
22

3+
import java.io.Closeable;
34
import java.io.File;
45
import java.io.IOException;
56
import java.io.RandomAccessFile;
@@ -9,7 +10,7 @@
910

1011
import com.maxmind.maxminddb.Reader.FileMode;
1112

12-
final class ThreadBuffer extends ThreadLocal<ByteBuffer> {
13+
final class ThreadBuffer extends ThreadLocal<ByteBuffer> implements Closeable {
1314
// XXX - DO NOT PASS THIS OUTSIDE THIS CLASS.
1415
private final ByteBuffer buffer;
1516
private final RandomAccessFile raf;
@@ -38,6 +39,7 @@ protected synchronized ByteBuffer initialValue() {
3839
return this.buffer.duplicate();
3940
}
4041

42+
@Override
4143
public void close() throws IOException {
4244
if (this.fc != null) {
4345
this.fc.close();

0 commit comments

Comments
 (0)