@@ -58,7 +58,8 @@ public Reader(File database) throws MaxMindDbException, IOException {
5858
5959 this .metadata = new Metadata (metadataDecoder .decode (start ).getNode ());
6060
61- this .decoder = new Decoder (this .mmap , this .metadata .searchTreeSize + DATA_SECTION_SEPARATOR_SIZE );
61+ this .decoder = new Decoder (this .mmap , this .metadata .searchTreeSize
62+ + DATA_SECTION_SEPARATOR_SIZE );
6263
6364 if (this .DEBUG ) {
6465 Log .debug (this .metadata .toString ());
@@ -74,7 +75,7 @@ public JsonNode get(InetAddress address) throws MaxMindDbException,
7475 return null ;
7576 }
7677
77- this .fc .position (pointer );
78+ this .mmap .position (( int ) pointer );
7879 return this .resolveDataPointer (pointer );
7980 }
8081
@@ -142,41 +143,33 @@ long record = nodes[bit];
142143
143144 private long [] readNode (long nodeNumber ) throws IOException ,
144145 MaxMindDbException {
145- ByteBuffer buffer = ByteBuffer
146- .wrap (new byte [this .metadata .nodeByteSize ]);
147- this .fc .position (nodeNumber * this .metadata .nodeByteSize );
146+ this .mmap .position ((int ) nodeNumber * this .metadata .nodeByteSize );
148147
149- this .fc .read (buffer );
148+ byte [] buffer = Util
149+ .getByteArray (this .mmap , this .metadata .nodeByteSize );
150150
151151 if (this .DEBUG ) {
152152 Log .debug ("Node bytes" , buffer );
153153 }
154154 return this .splitNodeIntoRecords (buffer );
155155 }
156156
157- private long [] splitNodeIntoRecords (ByteBuffer bytes )
158- throws MaxMindDbException {
157+ private long [] splitNodeIntoRecords (byte [] bytes ) throws MaxMindDbException {
159158 long [] nodes = new long [2 ];
160159 switch (this .metadata .recordSize ) {
161160 case 24 :
162- nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 0 ,
163- 3 ));
164- nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 3 ,
165- 6 ));
161+ nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 0 , 3 ));
162+ nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 3 , 6 ));
166163 return nodes ;
167164 case 28 :
168- nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 0 ,
169- 3 ));
170- nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 4 ,
171- 7 ));
172- nodes [0 ] = ((0xF0 & bytes .get (3 )) << 20 ) | nodes [0 ];
173- nodes [1 ] = ((0x0F & bytes .get (3 )) << 24 ) | nodes [1 ];
165+ nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 0 , 3 ));
166+ nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 4 , 7 ));
167+ nodes [0 ] = ((0xF0 & bytes [3 ]) << 20 ) | nodes [0 ];
168+ nodes [1 ] = ((0x0F & bytes [3 ]) << 24 ) | nodes [1 ];
174169 return nodes ;
175170 case 32 :
176- nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 0 ,
177- 4 ));
178- nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes .array (), 4 ,
179- 8 ));
171+ nodes [0 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 0 , 4 ));
172+ nodes [1 ] = Util .decodeLong (Arrays .copyOfRange (bytes , 4 , 8 ));
180173 return nodes ;
181174 default :
182175 throw new MaxMindDbException ("Unknown record size: "
0 commit comments