Skip to content

Commit ccc92c3

Browse files
committed
Added a close method for closing all of the file handles. Removed some old comments and cleaned up some method signatures.
1 parent a5273a0 commit ccc92c3

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public Decoder(FileChannel in, long pointerBase) {
6060
this.DEBUG = System.getenv().get("MAXMIND_DB_DECODER_DEBUG") != null;
6161
}
6262

63-
// FIXME - Move most of this method to a switch statement
6463
public Result decode(long offset) throws MaxMindDbException, IOException {
6564
this.in.position(offset);
6665
if (this.DEBUG) {
@@ -125,7 +124,6 @@ public Result decode(long offset) throws MaxMindDbException, IOException {
125124
offset = sizeArray[1];
126125

127126
if (this.DEBUG) {
128-
// FIXME - cast or whatever
129127
Log.debug("Size", String.valueOf(size));
130128
}
131129

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.nio.channels.FileChannel;
99
import java.util.Arrays;
1010

11+
import com.fasterxml.jackson.databind.JsonNode;
12+
1113
public class Reader {
1214
private static final int DATA_SECTION_SEPARATOR_SIZE = 16;
1315
private static final byte[] METADATA_START_MARKER = { (byte) 0xAB,
@@ -63,8 +65,7 @@ public Reader(File database) throws MaxMindDbException, IOException {
6365
}
6466
}
6567

66-
// FIXME - figure out what we are returning
67-
public Object get(InetAddress address) throws MaxMindDbException,
68+
public JsonNode get(InetAddress address) throws MaxMindDbException,
6869
IOException {
6970

7071
long pointer = this.findAddressInTree(address);
@@ -136,7 +137,6 @@ long record = nodes[bit];
136137
nodeNum = record;
137138
}
138139

139-
// XXX - Can we get down here?
140140
throw new MaxMindDbException("Something bad happened");
141141
}
142142

@@ -184,8 +184,8 @@ private long[] splitNodeIntoRecords(ByteBuffer bytes)
184184
}
185185
}
186186

187-
private Object resolveDataPointer(long pointer) throws MaxMindDbException,
188-
IOException {
187+
private JsonNode resolveDataPointer(long pointer)
188+
throws MaxMindDbException, IOException {
189189
long resolved = (pointer - this.metadata.nodeCount)
190190
+ this.metadata.searchTreeSize;
191191

@@ -230,4 +230,13 @@ private long findMetadataStart() throws IOException {
230230
public Metadata getMetadata() {
231231
return this.metadata;
232232
}
233+
234+
public void close() throws IOException {
235+
if (this.fc != null) {
236+
this.fc.close();
237+
}
238+
if (this.raf != null) {
239+
this.raf.close();
240+
}
241+
}
233242
}

0 commit comments

Comments
 (0)