@@ -18,8 +18,6 @@ public final class MaxMindDbReader implements Closeable {
1818 (byte ) 0xCD , (byte ) 0xEF , 'M' , 'a' , 'x' , 'M' , 'i' , 'n' , 'd' , '.' ,
1919 'c' , 'o' , 'm' };
2020
21- private final static boolean DEBUG = System .getenv ().get (
22- "MAXMIND_DB_READER_DEBUG" ) != null ;
2321 private final Decoder decoder ;
2422 private final Metadata metadata ;
2523 private final ThreadBuffer threadBuffer ;
@@ -43,7 +41,7 @@ public enum FileMode {
4341 /**
4442 * Constructs a Reader for the MaxMind DB format. The file passed to it must
4543 * be a valid MaxMind DB file such as a GeoIP2 database file.
46- *
44+ *
4745 * @param database
4846 * the MaxMind DB file to use.
4947 * @throws IOException
@@ -56,7 +54,7 @@ public MaxMindDbReader(File database) throws IOException {
5654 /**
5755 * Constructs a Reader for the MaxMind DB format. The file passed to it must
5856 * be a valid MaxMind DB file such as a GeoIP2 database file.
59- *
57+ *
6058 * @param database
6159 * the MaxMind DB file to use.
6260 * @param fileMode
@@ -72,15 +70,11 @@ public MaxMindDbReader(File database, FileMode fileMode) throws IOException {
7270 this .metadata = new Metadata (metadataDecoder .decode (start ).getNode ());
7371 this .decoder = new Decoder (this .threadBuffer ,
7472 this .metadata .searchTreeSize + DATA_SECTION_SEPARATOR_SIZE );
75-
76- if (MaxMindDbReader .DEBUG ) {
77- Log .debug (this .metadata .toString ());
78- }
7973 }
8074
8175 /**
8276 * Looks up the <code>address</code> in the MaxMind DB.
83- *
77+ *
8478 * @param ipAddress
8579 * the IP address to look up.
8680 * @return the record for the IP address.
@@ -99,13 +93,6 @@ private int findAddressInTree(InetAddress address)
9993 throws InvalidDatabaseException {
10094 byte [] rawAddress = address .getAddress ();
10195
102- if (MaxMindDbReader .DEBUG ) {
103- Log .debugNewLine ();
104- Log .debug ("IP address" , address );
105- Log .debug ("IP address" , rawAddress );
106- Log .debugNewLine ();
107- }
108-
10996 boolean isIp4AddressInIp6Db = rawAddress .length == 4
11097 && this .metadata .ipVersion == 6 ;
11198 int ipStartBit = isIp4AddressInIp6Db ? 96 : 0 ;
@@ -122,29 +109,14 @@ private int findAddressInTree(InetAddress address)
122109 }
123110 int record = this .readNode (nodeNum , bit );
124111
125- if (MaxMindDbReader .DEBUG ) {
126- Log .debug ("Bit #" , i );
127- Log .debug ("Bit value" , bit );
128- Log .debug ("Record" , bit == 1 ? "right" : "left" );
129- Log .debug ("Record value" , record );
130- }
131-
132112 if (record == this .metadata .nodeCount ) {
133- if (MaxMindDbReader .DEBUG ) {
134- Log .debug ("Record is empty" );
135- }
113+ // record is empty
136114 return 0 ;
137115 } else if (record > this .metadata .nodeCount ) {
138- if (MaxMindDbReader .DEBUG ) {
139- Log .debug ("Record is a data pointer" );
140- }
116+ // record is a data pointer
141117 return record ;
142118 }
143119
144- if (MaxMindDbReader .DEBUG ) {
145- Log .debug ("Record is a node number" );
146- }
147-
148120 nodeNum = record ;
149121 }
150122 throw new InvalidDatabaseException ("Something bad happened" );
@@ -182,13 +154,6 @@ private JsonNode resolveDataPointer(int pointer) throws IOException {
182154 int resolved = (pointer - this .metadata .nodeCount )
183155 + this .metadata .searchTreeSize ;
184156
185- if (MaxMindDbReader .DEBUG ) {
186- int treeSize = this .metadata .searchTreeSize ;
187- Log .debug ("Resolved data pointer" , "( " + pointer + " - "
188- + this .metadata .nodeCount + " ) + " + treeSize + " = "
189- + resolved );
190- }
191-
192157 // We only want the data from the decoder, not the offset where it was
193158 // found.
194159 return this .decoder .decode (resolved ).getNode ();
@@ -197,12 +162,13 @@ private JsonNode resolveDataPointer(int pointer) throws IOException {
197162 /*
198163 * Apparently searching a file for a sequence is not a solved problem in
199164 * Java. This searches from the end of the file for metadata start.
200- *
165+ *
201166 * This is an extremely naive but reasonably readable implementation. There
202167 * are much faster algorithms (e.g., Boyer-Moore) for this if speed is ever
203168 * an issue, but I suspect it won't be.
204169 */
205- private int findMetadataStart (String databaseName ) throws InvalidDatabaseException {
170+ private int findMetadataStart (String databaseName )
171+ throws InvalidDatabaseException {
206172 ByteBuffer buffer = this .threadBuffer .get ();
207173 int fileSize = buffer .capacity ();
208174
@@ -217,9 +183,8 @@ private int findMetadataStart(String databaseName) throws InvalidDatabaseExcepti
217183 return fileSize - i ;
218184 }
219185 throw new InvalidDatabaseException (
220- "Could not find a MaxMind DB metadata marker in this file ("
221- + databaseName
222- + "). Is this a valid MaxMind DB file?" );
186+ "Could not find a MaxMind DB metadata marker in this file ("
187+ + databaseName + "). Is this a valid MaxMind DB file?" );
223188 }
224189
225190 Metadata getMetadata () {
@@ -228,7 +193,7 @@ Metadata getMetadata() {
228193
229194 /**
230195 * Closes the MaxMind DB and returns resources to the system.
231- *
196+ *
232197 * @throws IOException
233198 * if an I/O error occurs.
234199 */
0 commit comments