diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 018aef17..716e5575 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,7 +8,7 @@ jobs:
matrix:
distribution: ['zulu']
os: [ubuntu-latest, windows-latest, macos-latest]
- version: [ 8, 9, 10, 11, 12, 13, 14, 15 ]
+ version: [ 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
steps:
- uses: actions/checkout@v3
with:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc720e35..f1f31dbf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,18 @@
CHANGELOG
=========
+3.0.0
+------------------
+
+* Java 11 or greater is now required.
+* This library is now a Java module.
+
2.1.0 (2022-10-31)
------------------
* Messages for `DeserializationException` have been improved, and the cause
- is included, if any. Moreover, the message provides detail about the involved
- types, if the exception is caused by an `IllegalArgumentException`.
+ is included, if any. Moreover, the message provides detail about the involved
+ types, if the exception is caused by an `IllegalArgumentException`.
2.0.0 (2020-10-13)
------------------
@@ -101,7 +107,6 @@ CHANGELOG
* Several optimizations have been made to reduce allocations when decoding a
record. Pull requests by Viktor Szathmáry. GitHub #16 & #17.
-
1.0.0 (2014-09-29)
------------------
diff --git a/README.md b/README.md
index 8e0c8522..39c2d42e 100644
--- a/README.md
+++ b/README.md
@@ -185,7 +185,7 @@ specific to this reader, please [contact MaxMind support](https://www.maxmind.co
## Requirements ##
-This API requires Java 8 or greater.
+This API requires Java 11 or greater.
## Contributing ##
@@ -198,6 +198,6 @@ The MaxMind DB Reader API uses [Semantic Versioning](https://semver.org/).
## Copyright and License ##
-This software is Copyright (c) 2014-2020 by MaxMind, Inc.
+This software is Copyright (c) 2014-2022 by MaxMind, Inc.
This is free software, licensed under the Apache License, Version 2.0.
diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml
new file mode 100644
index 00000000..63d23ea3
--- /dev/null
+++ b/checkstyle-suppressions.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100644
index 00000000..e40ecfc1
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,382 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 2c8973cf..fcbb38dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
-
+
4.0.0
com.maxmind.db
maxmind-db
@@ -45,6 +46,33 @@
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.2.0
+
+ true
+ checkstyle.xml
+ checkstyle-suppressions.xml
+ warning
+
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 10.3
+
+
+
+
+ test
+ test
+
+ check
+
+
+
+
org.apache.maven.plugins
maven-gpg-plugin
@@ -78,8 +106,8 @@
maven-compiler-plugin
3.10.1
- 8
- 8
+ 11
+ 11
@@ -97,7 +125,7 @@
xml
256m
-
+
@@ -141,7 +169,7 @@
maven-compiler-plugin
- 8
+ 11
diff --git a/src/main/java/com/maxmind/db/BufferHolder.java b/src/main/java/com/maxmind/db/BufferHolder.java
index 856bebcd..dbbe8aa5 100644
--- a/src/main/java/com/maxmind/db/BufferHolder.java
+++ b/src/main/java/com/maxmind/db/BufferHolder.java
@@ -1,5 +1,6 @@
package com.maxmind.db;
+import com.maxmind.db.Reader.FileMode;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -9,23 +10,21 @@
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
-import com.maxmind.db.Reader.FileMode;
-
final class BufferHolder {
// DO NOT PASS OUTSIDE THIS CLASS. Doing so will remove thread safety.
private final ByteBuffer buffer;
BufferHolder(File database, FileMode mode) throws IOException {
try (
- final RandomAccessFile file = new RandomAccessFile(database, "r");
- final FileChannel channel = file.getChannel()
+ final RandomAccessFile file = new RandomAccessFile(database, "r");
+ final FileChannel channel = file.getChannel()
) {
if (mode == FileMode.MEMORY) {
final ByteBuffer buf = ByteBuffer.wrap(new byte[(int) channel.size()]);
if (channel.read(buf) != buf.capacity()) {
throw new IOException("Unable to read "
- + database.getName()
- + " into memory. Unexpected end of stream.");
+ + database.getName()
+ + " into memory. Unexpected end of stream.");
}
this.buffer = buf.asReadOnlyBuffer();
} else {
@@ -61,19 +60,21 @@ final class BufferHolder {
ByteBuffer get() {
// The Java API docs for buffer state:
//
- // Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than
- // one thread then access to the buffer should be controlled by appropriate synchronization.
+ // Buffers are not safe for use by multiple concurrent threads. If a buffer is to be
+ // used by more than one thread then access to the buffer should be controlled by
+ // appropriate synchronization.
//
- // As such, you may think that this should be synchronized. This used to be the case, but we had several
- // complaints about the synchronization causing contention, e.g.:
+ // As such, you may think that this should be synchronized. This used to be the case, but
+ // we had several complaints about the synchronization causing contention, e.g.:
//
// * https://github.com/maxmind/MaxMind-DB-Reader-java/issues/65
// * https://github.com/maxmind/MaxMind-DB-Reader-java/pull/69
//
- // Given that we are not modifying the original ByteBuffer in any way and all currently known and most
- // reasonably imaginable implementations of duplicate() only do read operations on the original buffer object,
- // the risk of not synchronizing this call seems relatively low and worth taking for the performance benefit
- // when lookups are being done from many threads.
+ // Given that we are not modifying the original ByteBuffer in any way and all currently
+ // known and most reasonably imaginable implementations of duplicate() only do read
+ // operations on the original buffer object, the risk of not synchronizing this call seems
+ // relatively low and worth taking for the performance benefit when lookups are being done
+ // from many threads.
return this.buffer.duplicate();
}
}
diff --git a/src/main/java/com/maxmind/db/CachedConstructor.java b/src/main/java/com/maxmind/db/CachedConstructor.java
index c6b4760e..2b5b3160 100644
--- a/src/main/java/com/maxmind/db/CachedConstructor.java
+++ b/src/main/java/com/maxmind/db/CachedConstructor.java
@@ -10,10 +10,10 @@ final class CachedConstructor {
private final Map parameterIndexes;
CachedConstructor(
- Constructor constructor,
- Class>[] parameterTypes,
- java.lang.reflect.Type[] parameterGenericTypes,
- Map parameterIndexes
+ Constructor constructor,
+ Class>[] parameterTypes,
+ java.lang.reflect.Type[] parameterGenericTypes,
+ Map parameterIndexes
) {
this.constructor = constructor;
this.parameterTypes = parameterTypes;
diff --git a/src/main/java/com/maxmind/db/DecodedValue.java b/src/main/java/com/maxmind/db/DecodedValue.java
index c116a59a..c7708183 100644
--- a/src/main/java/com/maxmind/db/DecodedValue.java
+++ b/src/main/java/com/maxmind/db/DecodedValue.java
@@ -1,7 +1,7 @@
package com.maxmind.db;
public final class DecodedValue {
- final Object value;
+ final Object value;
DecodedValue(Object value) {
this.value = value;
diff --git a/src/main/java/com/maxmind/db/Decoder.java b/src/main/java/com/maxmind/db/Decoder.java
index 5b4ba14d..84151204 100644
--- a/src/main/java/com/maxmind/db/Decoder.java
+++ b/src/main/java/com/maxmind/db/Decoder.java
@@ -12,10 +12,10 @@
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/*
* Decoder for MaxMind DB data.
@@ -26,11 +26,11 @@ final class Decoder {
private static final Charset UTF_8 = StandardCharsets.UTF_8;
- private static final int[] POINTER_VALUE_OFFSETS = {0, 0, 1 << 11, (1 << 19) + ((1) << 11), 0};
+ private static final int[] POINTER_VALUE_OFFSETS = {0, 0, 1 << 11, (1 << 19) + (1 << 11), 0};
// XXX - This is only for unit testings. We should possibly make a
// constructor to set this
- boolean POINTER_TEST_HACK = false;
+ boolean pointerTestHack = false;
private final NodeCache cache;
@@ -44,18 +44,18 @@ final class Decoder {
Decoder(NodeCache cache, ByteBuffer buffer, long pointerBase) {
this(
- cache,
- buffer,
- pointerBase,
- new ConcurrentHashMap<>()
+ cache,
+ buffer,
+ pointerBase,
+ new ConcurrentHashMap<>()
);
}
Decoder(
- NodeCache cache,
- ByteBuffer buffer,
- long pointerBase,
- ConcurrentHashMap constructors
+ NodeCache cache,
+ ByteBuffer buffer,
+ long pointerBase,
+ ConcurrentHashMap constructors
) {
this.cache = cache;
this.pointerBase = pointerBase;
@@ -68,8 +68,8 @@ final class Decoder {
public T decode(int offset, Class cls) throws IOException {
if (offset >= this.buffer.capacity()) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "pointer larger than the database.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "pointer larger than the database.");
}
this.buffer.position(offset);
@@ -80,8 +80,8 @@ private DecodedValue decode(CacheKey key) throws IOException {
int offset = key.getOffset();
if (offset >= this.buffer.capacity()) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "pointer larger than the database.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "pointer larger than the database.");
}
this.buffer.position(offset);
@@ -90,7 +90,7 @@ private DecodedValue decode(CacheKey key) throws IOException {
}
private DecodedValue decode(Class cls, java.lang.reflect.Type genericType)
- throws IOException {
+ throws IOException {
int ctrlByte = 0xFF & this.buffer.get();
Type type = Type.fromControlByte(ctrlByte);
@@ -105,7 +105,7 @@ private DecodedValue decode(Class cls, java.lang.reflect.Type genericType
long pointer = packed + this.pointerBase + POINTER_VALUE_OFFSETS[pointerSize];
// for unit testing
- if (this.POINTER_TEST_HACK) {
+ if (this.pointerTestHack) {
return new DecodedValue(pointer);
}
@@ -126,9 +126,9 @@ private DecodedValue decode(Class cls, java.lang.reflect.Type genericType
if (typeNum < 8) {
throw new InvalidDatabaseException(
- "Something went horribly wrong in the decoder. An extended type "
- + "resolved to a type number < 8 (" + typeNum
- + ")");
+ "Something went horribly wrong in the decoder. An extended type "
+ + "resolved to a type number < 8 (" + typeNum
+ + ")");
}
type = Type.get(typeNum);
@@ -152,10 +152,10 @@ private DecodedValue decode(Class cls, java.lang.reflect.Type genericType
}
private Object decodeByType(
- Type type,
- int size,
- Class cls,
- java.lang.reflect.Type genericType
+ Type type,
+ int size,
+ Class cls,
+ java.lang.reflect.Type genericType
) throws IOException {
switch (type) {
case MAP:
@@ -163,9 +163,8 @@ private Object decodeByType(
case ARRAY:
Class> elementClass = Object.class;
if (genericType instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) genericType;
- java.lang.reflect.Type[] actualTypes
- = pType.getActualTypeArguments();
+ ParameterizedType ptype = (ParameterizedType) genericType;
+ java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
if (actualTypes.length == 1) {
elementClass = (Class>) actualTypes[0];
}
@@ -192,7 +191,7 @@ private Object decodeByType(
return this.decodeBigInteger(size);
default:
throw new InvalidDatabaseException(
- "Unknown or unexpected type: " + type.name());
+ "Unknown or unexpected type: " + type.name());
}
}
@@ -248,8 +247,8 @@ private BigInteger decodeBigInteger(int size) {
private double decodeDouble(int size) throws InvalidDatabaseException {
if (size != 8) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "invalid size of double.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "invalid size of double.");
}
return this.buffer.getDouble();
}
@@ -257,14 +256,14 @@ private double decodeDouble(int size) throws InvalidDatabaseException {
private float decodeFloat(int size) throws InvalidDatabaseException {
if (size != 4) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "invalid size of float.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "invalid size of float.");
}
return this.buffer.getFloat();
}
private static boolean decodeBoolean(int size)
- throws InvalidDatabaseException {
+ throws InvalidDatabaseException {
switch (size) {
case 0:
return false;
@@ -272,15 +271,15 @@ private static boolean decodeBoolean(int size)
return true;
default:
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "invalid size of boolean.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "invalid size of boolean.");
}
}
private List decodeArray(
- int size,
- Class cls,
- Class elementClass
+ int size,
+ Class cls,
+ Class elementClass
) throws IOException {
if (!List.class.isAssignableFrom(cls) && !cls.equals(Object.class)) {
throw new DeserializationException("Unable to deserialize an array into an " + cls);
@@ -294,16 +293,17 @@ private List decodeArray(
try {
constructor = cls.getConstructor(Integer.TYPE);
} catch (NoSuchMethodException e) {
- throw new DeserializationException("No constructor found for the List: " + e.getMessage(), e);
+ throw new DeserializationException(
+ "No constructor found for the List: " + e.getMessage(), e);
}
Object[] parameters = {size};
try {
@SuppressWarnings("unchecked")
List array2 = (List) constructor.newInstance(parameters);
array = array2;
- } catch (InstantiationException |
- IllegalAccessException |
- InvocationTargetException e) {
+ } catch (InstantiationException
+ | IllegalAccessException
+ | InvocationTargetException e) {
throw new DeserializationException("Error creating list: " + e.getMessage(), e);
}
}
@@ -317,16 +317,15 @@ private List decodeArray(
}
private Object decodeMap(
- int size,
- Class cls,
- java.lang.reflect.Type genericType
+ int size,
+ Class cls,
+ java.lang.reflect.Type genericType
) throws IOException {
if (Map.class.isAssignableFrom(cls) || cls.equals(Object.class)) {
Class> valueClass = Object.class;
if (genericType instanceof ParameterizedType) {
- ParameterizedType pType = (ParameterizedType) genericType;
- java.lang.reflect.Type[] actualTypes
- = pType.getActualTypeArguments();
+ ParameterizedType ptype = (ParameterizedType) genericType;
+ java.lang.reflect.Type[] actualTypes = ptype.getActualTypeArguments();
if (actualTypes.length == 2) {
Class> keyClass = (Class>) actualTypes[0];
if (!keyClass.equals(String.class)) {
@@ -343,9 +342,9 @@ private Object decodeMap(
}
private Map decodeMapIntoMap(
- Class cls,
- int size,
- Class valueClass
+ Class cls,
+ int size,
+ Class valueClass
) throws IOException {
Map map;
if (cls.equals(Map.class) || cls.equals(Object.class)) {
@@ -355,16 +354,17 @@ private Map decodeMapIntoMap(
try {
constructor = cls.getConstructor(Integer.TYPE);
} catch (NoSuchMethodException e) {
- throw new DeserializationException("No constructor found for the Map: " + e.getMessage(), e);
+ throw new DeserializationException(
+ "No constructor found for the Map: " + e.getMessage(), e);
}
Object[] parameters = {size};
try {
@SuppressWarnings("unchecked")
Map map2 = (Map) constructor.newInstance(parameters);
map = map2;
- } catch (InstantiationException |
- IllegalAccessException |
- InvocationTargetException e) {
+ } catch (InstantiationException
+ | IllegalAccessException
+ | InvocationTargetException e) {
throw new DeserializationException("Error creating map: " + e.getMessage(), e);
}
}
@@ -379,14 +379,14 @@ private Map decodeMapIntoMap(
}
private Object decodeMapIntoObject(int size, Class cls)
- throws IOException {
+ throws IOException {
CachedConstructor cachedConstructor = this.constructors.get(cls);
Constructor constructor;
Class>[] parameterTypes;
java.lang.reflect.Type[] parameterGenericTypes;
Map parameterIndexes;
if (cachedConstructor == null) {
- constructor = this.findConstructor(cls);
+ constructor = findConstructor(cls);
parameterTypes = constructor.getParameterTypes();
@@ -395,18 +395,18 @@ private Object decodeMapIntoObject(int size, Class cls)
parameterIndexes = new HashMap<>();
Annotation[][] annotations = constructor.getParameterAnnotations();
for (int i = 0; i < constructor.getParameterCount(); i++) {
- String parameterName = this.getParameterName(cls, i, annotations[i]);
+ String parameterName = getParameterName(cls, i, annotations[i]);
parameterIndexes.put(parameterName, i);
}
this.constructors.put(
- cls,
- new CachedConstructor(
- constructor,
- parameterTypes,
- parameterGenericTypes,
- parameterIndexes
- )
+ cls,
+ new CachedConstructor(
+ constructor,
+ parameterTypes,
+ parameterGenericTypes,
+ parameterIndexes
+ )
);
} else {
constructor = cachedConstructor.getConstructor();
@@ -434,26 +434,27 @@ private Object decodeMapIntoObject(int size, Class cls)
try {
return constructor.newInstance(parameters);
- } catch (InstantiationException |
- IllegalAccessException |
- InvocationTargetException e) {
+ } catch (InstantiationException
+ | IllegalAccessException
+ | InvocationTargetException e) {
throw new DeserializationException("Error creating object: " + e.getMessage(), e);
- }
- catch (IllegalArgumentException e){
- StringBuilder sbErrors = new StringBuilder();
+ } catch (IllegalArgumentException e) {
+ StringBuilder sbErrors = new StringBuilder();
for (String key : parameterIndexes.keySet()) {
int index = parameterIndexes.get(key);
- if (!parameters[index].getClass().isAssignableFrom( parameterTypes[index])) {
- sbErrors.append(" argument type mismatch in " + key + " MMDB Type: " + parameters[index].getClass().getCanonicalName()
- + " Java Type: " +parameterTypes[index].getCanonicalName());
- }
+ if (!parameters[index].getClass().isAssignableFrom(parameterTypes[index])) {
+ sbErrors.append(" argument type mismatch in " + key + " MMDB Type: "
+ + parameters[index].getClass().getCanonicalName()
+ + " Java Type: " + parameterTypes[index].getCanonicalName());
+ }
}
- throw new DeserializationException("Error creating object of type: " + cls.getSimpleName() + " - " + sbErrors.toString(), e);
+ throw new DeserializationException(
+ "Error creating object of type: " + cls.getSimpleName() + " - " + sbErrors, e);
}
}
private static Constructor findConstructor(Class cls)
- throws ConstructorNotFoundException {
+ throws ConstructorNotFoundException {
Constructor>[] constructors = cls.getConstructors();
for (Constructor> constructor : constructors) {
if (constructor.getAnnotation(MaxMindDbConstructor.class) == null) {
@@ -464,13 +465,14 @@ private static Constructor findConstructor(Class cls)
return constructor2;
}
- throw new ConstructorNotFoundException("No constructor on class " + cls.getName() + " with the MaxMindDbConstructor annotation was found.");
+ throw new ConstructorNotFoundException("No constructor on class " + cls.getName()
+ + " with the MaxMindDbConstructor annotation was found.");
}
private static String getParameterName(
- Class cls,
- int index,
- Annotation[] annotations
+ Class cls,
+ int index,
+ Annotation[] annotations
) throws ParameterNotFoundException {
for (Annotation annotation : annotations) {
if (!annotation.annotationType().equals(MaxMindDbParameter.class)) {
@@ -479,7 +481,9 @@ private static String getParameterName(
MaxMindDbParameter paramAnnotation = (MaxMindDbParameter) annotation;
return paramAnnotation.name();
}
- throw new ParameterNotFoundException("Constructor parameter " + index + " on class " + cls.getName() + " is not annotated with MaxMindDbParameter.");
+ throw new ParameterNotFoundException(
+ "Constructor parameter " + index + " on class " + cls.getName()
+ + " is not annotated with MaxMindDbParameter.");
}
private int nextValueOffset(int offset, int numberToSkip)
@@ -495,21 +499,21 @@ private int nextValueOffset(int offset, int numberToSkip)
Type type = ctrlData.getType();
switch (type) {
- case POINTER:
- int pointerSize = ((ctrlByte >>> 3) & 0x3) + 1;
- offset += pointerSize;
- break;
- case MAP:
- numberToSkip += 2 * size;
- break;
- case ARRAY:
- numberToSkip += size;
- break;
- case BOOLEAN:
- break;
- default:
- offset += size;
- break;
+ case POINTER:
+ int pointerSize = ((ctrlByte >>> 3) & 0x3) + 1;
+ offset += pointerSize;
+ break;
+ case MAP:
+ numberToSkip += 2 * size;
+ break;
+ case ARRAY:
+ numberToSkip += size;
+ break;
+ case BOOLEAN:
+ break;
+ default:
+ offset += size;
+ break;
}
return nextValueOffset(offset, numberToSkip - 1);
@@ -519,8 +523,8 @@ private CtrlData getCtrlData(int offset)
throws InvalidDatabaseException {
if (offset >= this.buffer.capacity()) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's data section contains bad data: "
- + "pointer larger than the database.");
+ "The MaxMind DB file's data section contains bad data: "
+ + "pointer larger than the database.");
}
this.buffer.position(offset);
@@ -536,9 +540,9 @@ private CtrlData getCtrlData(int offset)
if (typeNum < 8) {
throw new InvalidDatabaseException(
- "Something went horribly wrong in the decoder. An extended type "
- + "resolved to a type number < 8 (" + typeNum
- + ")");
+ "Something went horribly wrong in the decoder. An extended type "
+ + "resolved to a type number < 8 (" + typeNum
+ + ")");
}
type = Type.get(typeNum);
diff --git a/src/main/java/com/maxmind/db/DeserializationException.java b/src/main/java/com/maxmind/db/DeserializationException.java
index 1a66aacf..c18b24ba 100644
--- a/src/main/java/com/maxmind/db/DeserializationException.java
+++ b/src/main/java/com/maxmind/db/DeserializationException.java
@@ -13,6 +13,7 @@ public class DeserializationException extends RuntimeException {
DeserializationException(String message) {
super(message);
}
+
DeserializationException(String message, Throwable cause) {
super(message, cause);
}
diff --git a/src/main/java/com/maxmind/db/MaxMindDbConstructor.java b/src/main/java/com/maxmind/db/MaxMindDbConstructor.java
index 3d51d7ff..def9da19 100644
--- a/src/main/java/com/maxmind/db/MaxMindDbConstructor.java
+++ b/src/main/java/com/maxmind/db/MaxMindDbConstructor.java
@@ -4,4 +4,5 @@
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
-public @interface MaxMindDbConstructor {}
+public @interface MaxMindDbConstructor {
+}
diff --git a/src/main/java/com/maxmind/db/Metadata.java b/src/main/java/com/maxmind/db/Metadata.java
index ff041706..46a6301c 100644
--- a/src/main/java/com/maxmind/db/Metadata.java
+++ b/src/main/java/com/maxmind/db/Metadata.java
@@ -29,24 +29,24 @@ public final class Metadata {
@MaxMindDbConstructor
public Metadata(
- @MaxMindDbParameter(name="binary_format_major_version")
- int binaryFormatMajorVersion,
- @MaxMindDbParameter(name="binary_format_minor_version")
- int binaryFormatMinorVersion,
- @MaxMindDbParameter(name="build_epoch")
- BigInteger buildEpoch,
- @MaxMindDbParameter(name="database_type")
- String databaseType,
- @MaxMindDbParameter(name="languages")
- List languages,
- @MaxMindDbParameter(name="description")
- Map description,
- @MaxMindDbParameter(name="ip_version")
- int ipVersion,
- @MaxMindDbParameter(name="node_count")
- long nodeCount,
- @MaxMindDbParameter(name="record_size")
- int recordSize
+ @MaxMindDbParameter(name = "binary_format_major_version")
+ int binaryFormatMajorVersion,
+ @MaxMindDbParameter(name = "binary_format_minor_version")
+ int binaryFormatMinorVersion,
+ @MaxMindDbParameter(name = "build_epoch")
+ BigInteger buildEpoch,
+ @MaxMindDbParameter(name = "database_type")
+ String databaseType,
+ @MaxMindDbParameter(name = "languages")
+ List languages,
+ @MaxMindDbParameter(name = "description")
+ Map description,
+ @MaxMindDbParameter(name = "ip_version")
+ int ipVersion,
+ @MaxMindDbParameter(name = "node_count")
+ long nodeCount,
+ @MaxMindDbParameter(name = "record_size")
+ int recordSize
) {
this.binaryFormatMajorVersion = binaryFormatMajorVersion;
this.binaryFormatMinorVersion = binaryFormatMinorVersion;
@@ -151,11 +151,11 @@ int getSearchTreeSize() {
@Override
public String toString() {
return "Metadata [binaryFormatMajorVersion="
- + this.binaryFormatMajorVersion + ", binaryFormatMinorVersion="
- + this.binaryFormatMinorVersion + ", buildEpoch="
- + this.buildEpoch + ", databaseType=" + this.databaseType
- + ", description=" + this.description + ", ipVersion="
- + this.ipVersion + ", nodeCount=" + this.nodeCount
- + ", recordSize=" + this.recordSize + "]";
+ + this.binaryFormatMajorVersion + ", binaryFormatMinorVersion="
+ + this.binaryFormatMinorVersion + ", buildEpoch="
+ + this.buildEpoch + ", databaseType=" + this.databaseType
+ + ", description=" + this.description + ", ipVersion="
+ + this.ipVersion + ", nodeCount=" + this.nodeCount
+ + ", recordSize=" + this.recordSize + "]";
}
}
diff --git a/src/main/java/com/maxmind/db/Network.java b/src/main/java/com/maxmind/db/Network.java
index cc78594b..aee5c84f 100644
--- a/src/main/java/com/maxmind/db/Network.java
+++ b/src/main/java/com/maxmind/db/Network.java
@@ -46,7 +46,8 @@ public InetAddress getNetworkAddress() {
try {
networkAddress = InetAddress.getByAddress(networkBytes);
} catch (UnknownHostException e) {
- throw new RuntimeException("Illegal network address byte length of " + networkBytes.length);
+ throw new RuntimeException(
+ "Illegal network address byte length of " + networkBytes.length);
}
return networkAddress;
}
@@ -66,4 +67,4 @@ public int getPrefixLength() {
public String toString() {
return getNetworkAddress().getHostAddress() + "/" + prefixLength;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/maxmind/db/NoCache.java b/src/main/java/com/maxmind/db/NoCache.java
index 7d968239..69e879c4 100644
--- a/src/main/java/com/maxmind/db/NoCache.java
+++ b/src/main/java/com/maxmind/db/NoCache.java
@@ -5,7 +5,7 @@
/**
* A no-op cache singleton.
*/
-public class NoCache implements NodeCache {
+public final class NoCache implements NodeCache {
private static final NoCache INSTANCE = new NoCache();
diff --git a/src/main/java/com/maxmind/db/Reader.java b/src/main/java/com/maxmind/db/Reader.java
index 2837d81d..aa3330f6 100644
--- a/src/main/java/com/maxmind/db/Reader.java
+++ b/src/main/java/com/maxmind/db/Reader.java
@@ -4,12 +4,10 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.Class;
import java.net.InetAddress;
import java.nio.ByteBuffer;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Instances of this class provide a reader for the MaxMind DB format. IP
@@ -18,8 +16,8 @@
public final class Reader implements Closeable {
private static final int DATA_SECTION_SEPARATOR_SIZE = 16;
private static final byte[] METADATA_START_MARKER = {(byte) 0xAB,
- (byte) 0xCD, (byte) 0xEF, 'M', 'a', 'x', 'M', 'i', 'n', 'd', '.',
- 'c', 'o', 'm'};
+ (byte) 0xCD, (byte) 0xEF, 'M', 'a', 'x', 'M', 'i', 'n', 'd', '.',
+ 'c', 'o', 'm'};
private final int ipV4Start;
private final Metadata metadata;
@@ -120,7 +118,7 @@ public Reader(File database, FileMode fileMode, NodeCache cache) throws IOExcept
private Reader(BufferHolder bufferHolder, String name, NodeCache cache) throws IOException {
this.bufferHolderReference = new AtomicReference<>(
- bufferHolder);
+ bufferHolder);
if (cache == null) {
throw new NullPointerException("Cache cannot be null");
@@ -141,9 +139,9 @@ private Reader(BufferHolder bufferHolder, String name, NodeCache cache) throws I
/**
* Looks up ipAddress in the MaxMind DB.
*
- * @param the type to populate.
+ * @param the type to populate.
* @param ipAddress the IP address to look up.
- * @param cls the class of object to populate.
+ * @param cls the class of object to populate.
* @return the object.
* @throws IOException if a file I/O error occurs.
*/
@@ -154,15 +152,15 @@ public T get(InetAddress ipAddress, Class cls) throws IOException {
/**
* Looks up ipAddress in the MaxMind DB.
*
- * @param the type to populate.
+ * @param the type to populate.
* @param ipAddress the IP address to look up.
- * @param cls the class of object to populate.
+ * @param cls the class of object to populate.
* @return the record for the IP address. If there is no data for the
* address, the non-null {@link DatabaseRecord} will still be returned.
* @throws IOException if a file I/O error occurs.
*/
public DatabaseRecord getRecord(InetAddress ipAddress, Class cls)
- throws IOException {
+ throws IOException {
ByteBuffer buffer = this.getBufferHolder().get();
byte[] rawAddress = ipAddress.getAddress();
@@ -184,8 +182,9 @@ record = this.readNode(buffer, record, bit);
try {
dataRecord = this.resolveDataPointer(buffer, record, cls);
} catch (DeserializationException exception) {
- String msgCause = Optional.ofNullable(exception).map(Exception::getMessage).orElse("");
- throw new DeserializationException("Error getting record for IP " + ipAddress.toString() + " - " + msgCause, exception);
+ throw new DeserializationException(
+ "Error getting record for IP " + ipAddress + " - " + exception.getMessage(),
+ exception);
}
}
return new DatabaseRecord<>(dataRecord, ipAddress, pl);
@@ -211,7 +210,7 @@ private int startNode(int bitLength) {
}
private int findIpV4StartNode(ByteBuffer buffer)
- throws InvalidDatabaseException {
+ throws InvalidDatabaseException {
if (this.metadata.getIpVersion() == 4) {
return 0;
}
@@ -224,7 +223,7 @@ private int findIpV4StartNode(ByteBuffer buffer)
}
private int readNode(ByteBuffer buffer, int nodeNumber, int index)
- throws InvalidDatabaseException {
+ throws InvalidDatabaseException {
int baseOffset = nodeNumber * this.metadata.getNodeByteSize();
switch (this.metadata.getRecordSize()) {
@@ -246,31 +245,31 @@ private int readNode(ByteBuffer buffer, int nodeNumber, int index)
return Decoder.decodeInteger(buffer, 0, 4);
default:
throw new InvalidDatabaseException("Unknown record size: "
- + this.metadata.getRecordSize());
+ + this.metadata.getRecordSize());
}
}
private T resolveDataPointer(
- ByteBuffer buffer,
- int pointer,
- Class cls
+ ByteBuffer buffer,
+ int pointer,
+ Class cls
) throws IOException {
int resolved = (pointer - this.metadata.getNodeCount())
- + this.metadata.getSearchTreeSize();
+ + this.metadata.getSearchTreeSize();
if (resolved >= buffer.capacity()) {
throw new InvalidDatabaseException(
- "The MaxMind DB file's search tree is corrupt: "
- + "contains pointer larger than the database.");
+ "The MaxMind DB file's search tree is corrupt: "
+ + "contains pointer larger than the database.");
}
// We only want the data from the decoder, not the offset where it was
// found.
Decoder decoder = new Decoder(
- this.cache,
- buffer,
- this.metadata.getSearchTreeSize() + DATA_SECTION_SEPARATOR_SIZE,
- this.constructors
+ this.cache,
+ buffer,
+ this.metadata.getSearchTreeSize() + DATA_SECTION_SEPARATOR_SIZE,
+ this.constructors
);
return decoder.decode(resolved, cls);
}
@@ -284,7 +283,7 @@ private T resolveDataPointer(
* an issue, but I suspect it won't be.
*/
private int findMetadataStart(ByteBuffer buffer, String databaseName)
- throws InvalidDatabaseException {
+ throws InvalidDatabaseException {
int fileSize = buffer.capacity();
FILE:
@@ -292,15 +291,15 @@ private int findMetadataStart(ByteBuffer buffer, String databaseName)
for (int j = 0; j < METADATA_START_MARKER.length; j++) {
byte b = buffer.get(fileSize - i - j - 1);
if (b != METADATA_START_MARKER[METADATA_START_MARKER.length - j
- - 1]) {
+ - 1]) {
continue FILE;
}
}
return fileSize - i;
}
throw new InvalidDatabaseException(
- "Could not find a MaxMind DB metadata marker in this file ("
- + databaseName + "). Is this a valid MaxMind DB file?");
+ "Could not find a MaxMind DB metadata marker in this file ("
+ + databaseName + "). Is this a valid MaxMind DB file?");
}
/**
diff --git a/src/main/java/com/maxmind/db/Type.java b/src/main/java/com/maxmind/db/Type.java
index 84f67f8c..a438a736 100644
--- a/src/main/java/com/maxmind/db/Type.java
+++ b/src/main/java/com/maxmind/db/Type.java
@@ -1,15 +1,17 @@
package com.maxmind.db;
enum Type {
- EXTENDED, POINTER, UTF8_STRING, DOUBLE, BYTES, UINT16, UINT32, MAP, INT32, UINT64, UINT128, ARRAY, CONTAINER, END_MARKER, BOOLEAN, FLOAT;
+ EXTENDED, POINTER, UTF8_STRING, DOUBLE, BYTES, UINT16, UINT32, MAP, INT32, UINT64, UINT128,
+ ARRAY, CONTAINER, END_MARKER, BOOLEAN, FLOAT;
// Java clones the array when you call values(). Caching it increased
// the speed by about 5000 requests per second on my machine.
- final static Type[] values = Type.values();
+ static final Type[] values = Type.values();
static Type get(int i) throws InvalidDatabaseException {
if (i >= Type.values.length) {
- throw new InvalidDatabaseException("The MaxMind DB file's data section contains bad data");
+ throw new InvalidDatabaseException(
+ "The MaxMind DB file's data section contains bad data");
}
return Type.values[i];
}
diff --git a/src/main/java/com/maxmind/db/package-info.java b/src/main/java/com/maxmind/db/package-info.java
index 73aed012..897b0615 100644
--- a/src/main/java/com/maxmind/db/package-info.java
+++ b/src/main/java/com/maxmind/db/package-info.java
@@ -1,4 +1,5 @@
/**
* @author greg
*/
-package com.maxmind.db;
\ No newline at end of file
+
+package com.maxmind.db;
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
new file mode 100644
index 00000000..3c5a6814
--- /dev/null
+++ b/src/main/java/module-info.java
@@ -0,0 +1,3 @@
+module com.maxmind.db {
+ exports com.maxmind.db;
+}
diff --git a/src/test/java/com/maxmind/db/DecoderTest.java b/src/test/java/com/maxmind/db/DecoderTest.java
index adf9d322..154baafd 100644
--- a/src/test/java/com/maxmind/db/DecoderTest.java
+++ b/src/test/java/com/maxmind/db/DecoderTest.java
@@ -1,5 +1,11 @@
package com.maxmind.db;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -14,13 +20,8 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
-
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.*;
-
@SuppressWarnings({"boxing", "static-method"})
public class DecoderTest {
@@ -28,28 +29,28 @@ private static Map int32() {
int max = (2 << 30) - 1;
HashMap int32 = new HashMap<>();
- int32.put(0, new byte[]{0x0, 0x1});
- int32.put(-1, new byte[]{0x4, 0x1, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff});
- int32.put((2 << 7) - 1, new byte[]{0x1, 0x1, (byte) 0xff});
- int32.put(1 - (2 << 7), new byte[]{0x4, 0x1, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, 0x1});
- int32.put(500, new byte[]{0x2, 0x1, 0x1, (byte) 0xf4});
-
- int32.put(-500, new byte[]{0x4, 0x1, (byte) 0xff, (byte) 0xff,
- (byte) 0xfe, 0xc});
-
- int32.put((2 << 15) - 1, new byte[]{0x2, 0x1, (byte) 0xff,
- (byte) 0xff});
- int32.put(1 - (2 << 15), new byte[]{0x4, 0x1, (byte) 0xff,
- (byte) 0xff, 0x0, 0x1});
- int32.put((2 << 23) - 1, new byte[]{0x3, 0x1, (byte) 0xff,
- (byte) 0xff, (byte) 0xff});
- int32.put(1 - (2 << 23), new byte[]{0x4, 0x1, (byte) 0xff, 0x0, 0x0,
- 0x1});
- int32.put(max, new byte[]{0x4, 0x1, 0x7f, (byte) 0xff, (byte) 0xff,
- (byte) 0xff});
- int32.put(-max, new byte[]{0x4, 0x1, (byte) 0x80, 0x0, 0x0, 0x1});
+ int32.put(0, new byte[] {0x0, 0x1});
+ int32.put(-1, new byte[] {0x4, 0x1, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff});
+ int32.put((2 << 7) - 1, new byte[] {0x1, 0x1, (byte) 0xff});
+ int32.put(1 - (2 << 7), new byte[] {0x4, 0x1, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, 0x1});
+ int32.put(500, new byte[] {0x2, 0x1, 0x1, (byte) 0xf4});
+
+ int32.put(-500, new byte[] {0x4, 0x1, (byte) 0xff, (byte) 0xff,
+ (byte) 0xfe, 0xc});
+
+ int32.put((2 << 15) - 1, new byte[] {0x2, 0x1, (byte) 0xff,
+ (byte) 0xff});
+ int32.put(1 - (2 << 15), new byte[] {0x4, 0x1, (byte) 0xff,
+ (byte) 0xff, 0x0, 0x1});
+ int32.put((2 << 23) - 1, new byte[] {0x3, 0x1, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff});
+ int32.put(1 - (2 << 23), new byte[] {0x4, 0x1, (byte) 0xff, 0x0, 0x0,
+ 0x1});
+ int32.put(max, new byte[] {0x4, 0x1, 0x7f, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff});
+ int32.put(-max, new byte[] {0x4, 0x1, (byte) 0x80, 0x0, 0x0, 0x1});
return int32;
}
@@ -57,17 +58,17 @@ private static Map uint32() {
long max = (((long) 1) << 32) - 1;
HashMap uint32s = new HashMap<>();
- uint32s.put((long) 0, new byte[]{(byte) 0xc0});
- uint32s.put((long) ((1 << 8) - 1), new byte[]{(byte) 0xc1,
- (byte) 0xff});
- uint32s.put((long) 500, new byte[]{(byte) 0xc2, 0x1, (byte) 0xf4});
- uint32s.put((long) 10872, new byte[]{(byte) 0xc2, 0x2a, 0x78});
- uint32s.put((long) ((1 << 16) - 1), new byte[]{(byte) 0xc2,
- (byte) 0xff, (byte) 0xff});
- uint32s.put((long) ((1 << 24) - 1), new byte[]{(byte) 0xc3,
- (byte) 0xff, (byte) 0xff, (byte) 0xff});
- uint32s.put(max, new byte[]{(byte) 0xc4, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff});
+ uint32s.put((long) 0, new byte[] {(byte) 0xc0});
+ uint32s.put((long) ((1 << 8) - 1), new byte[] {(byte) 0xc1,
+ (byte) 0xff});
+ uint32s.put((long) 500, new byte[] {(byte) 0xc2, 0x1, (byte) 0xf4});
+ uint32s.put((long) 10872, new byte[] {(byte) 0xc2, 0x2a, 0x78});
+ uint32s.put((long) ((1 << 16) - 1), new byte[] {(byte) 0xc2,
+ (byte) 0xff, (byte) 0xff});
+ uint32s.put((long) ((1 << 24) - 1), new byte[] {(byte) 0xc3,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff});
+ uint32s.put(max, new byte[] {(byte) 0xc4, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff});
return uint32s;
}
@@ -77,11 +78,11 @@ private static Map uint16() {
Map uint16s = new HashMap<>();
- uint16s.put(0, new byte[]{(byte) 0xa0});
- uint16s.put((1 << 8) - 1, new byte[]{(byte) 0xa1, (byte) 0xff});
- uint16s.put(500, new byte[]{(byte) 0xa2, 0x1, (byte) 0xf4});
- uint16s.put(10872, new byte[]{(byte) 0xa2, 0x2a, 0x78});
- uint16s.put(max, new byte[]{(byte) 0xa2, (byte) 0xff, (byte) 0xff});
+ uint16s.put(0, new byte[] {(byte) 0xa0});
+ uint16s.put((1 << 8) - 1, new byte[] {(byte) 0xa1, (byte) 0xff});
+ uint16s.put(500, new byte[] {(byte) 0xa2, 0x1, (byte) 0xf4});
+ uint16s.put(10872, new byte[] {(byte) 0xa2, 0x2a, 0x78});
+ uint16s.put(max, new byte[] {(byte) 0xa2, (byte) 0xff, (byte) 0xff});
return uint16s;
}
@@ -90,16 +91,16 @@ private static Map largeUint(int bits) {
byte ctrlByte = (byte) (bits == 64 ? 0x2 : 0x3);
- uints.put(BigInteger.valueOf(0), new byte[]{0x0, ctrlByte});
- uints.put(BigInteger.valueOf(500), new byte[]{0x2, ctrlByte, 0x1,
- (byte) 0xf4});
- uints.put(BigInteger.valueOf(10872), new byte[]{0x2, ctrlByte, 0x2a,
- 0x78});
+ uints.put(BigInteger.valueOf(0), new byte[] {0x0, ctrlByte});
+ uints.put(BigInteger.valueOf(500), new byte[] {0x2, ctrlByte, 0x1,
+ (byte) 0xf4});
+ uints.put(BigInteger.valueOf(10872), new byte[] {0x2, ctrlByte, 0x2a,
+ 0x78});
for (int power = 1; power <= bits / 8; power++) {
BigInteger key = BigInteger.valueOf(2).pow(8 * power)
- .subtract(BigInteger.valueOf(1));
+ .subtract(BigInteger.valueOf(1));
byte[] value = new byte[2 + power];
value[0] = (byte) power;
@@ -116,22 +117,22 @@ private static Map largeUint(int bits) {
private static Map pointers() {
Map pointers = new HashMap<>();
- pointers.put((long) 0, new byte[]{0x20, 0x0});
- pointers.put((long) 5, new byte[]{0x20, 0x5});
- pointers.put((long) 10, new byte[]{0x20, 0xa});
- pointers.put((long) ((1 << 10) - 1), new byte[]{0x23, (byte) 0xff,});
- pointers.put((long) 3017, new byte[]{0x28, 0x3, (byte) 0xc9});
- pointers.put((long) ((1 << 19) - 5), new byte[]{0x2f, (byte) 0xf7,
- (byte) 0xfb});
- pointers.put((long) ((1 << 19) + (1 << 11) - 1), new byte[]{0x2f,
- (byte) 0xff, (byte) 0xff});
- pointers.put((long) ((1 << 27) - 2), new byte[]{0x37, (byte) 0xf7,
- (byte) 0xf7, (byte) 0xfe});
+ pointers.put((long) 0, new byte[] {0x20, 0x0});
+ pointers.put((long) 5, new byte[] {0x20, 0x5});
+ pointers.put((long) 10, new byte[] {0x20, 0xa});
+ pointers.put((long) ((1 << 10) - 1), new byte[] {0x23, (byte) 0xff,});
+ pointers.put((long) 3017, new byte[] {0x28, 0x3, (byte) 0xc9});
+ pointers.put((long) ((1 << 19) - 5), new byte[] {0x2f, (byte) 0xf7,
+ (byte) 0xfb});
+ pointers.put((long) ((1 << 19) + (1 << 11) - 1), new byte[] {0x2f,
+ (byte) 0xff, (byte) 0xff});
+ pointers.put((long) ((1 << 27) - 2), new byte[] {0x37, (byte) 0xf7,
+ (byte) 0xf7, (byte) 0xfe});
pointers.put((((long) 1) << 27) + (1 << 19) + (1 << 11) - 1,
- new byte[]{0x37, (byte) 0xff, (byte) 0xff, (byte) 0xff});
+ new byte[] {0x37, (byte) 0xff, (byte) 0xff, (byte) 0xff});
- pointers.put((((long) 1) << 31) - 1, new byte[]{0x38, (byte) 0x7f,
- (byte) 0xff, (byte) 0xff, (byte) 0xff});
+ pointers.put((((long) 1) << 31) - 1, new byte[] {0x38, (byte) 0x7f,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff});
return pointers;
}
@@ -144,29 +145,29 @@ private static Map strings() {
DecoderTest.addTestString(strings, (byte) 0x43, "人");
DecoderTest.addTestString(strings, (byte) 0x43, "123");
DecoderTest.addTestString(strings, (byte) 0x5b,
- "123456789012345678901234567");
+ "123456789012345678901234567");
DecoderTest.addTestString(strings, (byte) 0x5c,
- "1234567890123456789012345678");
+ "1234567890123456789012345678");
DecoderTest.addTestString(strings, (byte) 0x5c,
- "1234567890123456789012345678");
- DecoderTest.addTestString(strings, new byte[]{0x5d, 0x0},
- "12345678901234567890123456789");
- DecoderTest.addTestString(strings, new byte[]{0x5d, (byte) 128},
- DecoderTest.xString(157));
+ "1234567890123456789012345678");
+ DecoderTest.addTestString(strings, new byte[] {0x5d, 0x0},
+ "12345678901234567890123456789");
+ DecoderTest.addTestString(strings, new byte[] {0x5d, (byte) 128},
+ "x".repeat(157));
DecoderTest
- .addTestString(strings, new byte[]{0x5d, 0x0, (byte) 0xd7},
- DecoderTest.xString(500));
+ .addTestString(strings, new byte[] {0x5d, 0x0, (byte) 0xd7},
+ "x".repeat(500));
DecoderTest
- .addTestString(strings, new byte[]{0x5e, 0x0, (byte) 0xd7},
- DecoderTest.xString(500));
+ .addTestString(strings, new byte[] {0x5e, 0x0, (byte) 0xd7},
+ "x".repeat(500));
DecoderTest.addTestString(strings,
- new byte[]{0x5e, 0x6, (byte) 0xb3},
- DecoderTest.xString(2000));
+ new byte[] {0x5e, 0x6, (byte) 0xb3},
+ "x".repeat(2000));
DecoderTest.addTestString(strings,
- new byte[]{0x5f, 0x0, 0x10, 0x53,},
- DecoderTest.xString(70000));
+ new byte[] {0x5f, 0x0, 0x10, 0x53,},
+ "x".repeat(70000));
return strings;
@@ -187,17 +188,9 @@ private static Map bytes() {
return bytes;
}
- private static String xString(int length) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < length; i++) {
- sb.append("x");
- }
- return sb.toString();
- }
-
private static void addTestString(Map tests, byte ctrl,
String str) {
- DecoderTest.addTestString(tests, new byte[]{ctrl}, str);
+ DecoderTest.addTestString(tests, new byte[] {ctrl}, str);
}
private static void addTestString(Map tests, byte[] ctrl,
@@ -213,45 +206,45 @@ private static void addTestString(Map tests, byte[] ctrl,
private static Map doubles() {
Map doubles = new HashMap<>();
- doubles.put(0.0, new byte[]{0x68, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
- 0x0});
- doubles.put(0.5, new byte[]{0x68, 0x3F, (byte) 0xE0, 0x0, 0x0, 0x0,
- 0x0, 0x0, 0x0});
- doubles.put(3.14159265359, new byte[]{0x68, 0x40, 0x9, 0x21,
- (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA});
- doubles.put(123.0, new byte[]{0x68, 0x40, 0x5E, (byte) 0xC0, 0x0,
- 0x0, 0x0, 0x0, 0x0});
- doubles.put(1073741824.12457, new byte[]{0x68, 0x41, (byte) 0xD0,
- 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4});
- doubles.put(-0.5, new byte[]{0x68, (byte) 0xBF, (byte) 0xE0, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x0});
- doubles.put(-3.14159265359, new byte[]{0x68, (byte) 0xC0, 0x9, 0x21,
- (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA});
- doubles.put(-1073741824.12457, new byte[]{0x68, (byte) 0xC1,
- (byte) 0xD0, 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4});
+ doubles.put(0.0, new byte[] {0x68, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0});
+ doubles.put(0.5, new byte[] {0x68, 0x3F, (byte) 0xE0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0});
+ doubles.put(3.14159265359, new byte[] {0x68, 0x40, 0x9, 0x21,
+ (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA});
+ doubles.put(123.0, new byte[] {0x68, 0x40, 0x5E, (byte) 0xC0, 0x0,
+ 0x0, 0x0, 0x0, 0x0});
+ doubles.put(1073741824.12457, new byte[] {0x68, 0x41, (byte) 0xD0,
+ 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4});
+ doubles.put(-0.5, new byte[] {0x68, (byte) 0xBF, (byte) 0xE0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0});
+ doubles.put(-3.14159265359, new byte[] {0x68, (byte) 0xC0, 0x9, 0x21,
+ (byte) 0xFB, 0x54, 0x44, 0x2E, (byte) 0xEA});
+ doubles.put(-1073741824.12457, new byte[] {0x68, (byte) 0xC1,
+ (byte) 0xD0, 0x0, 0x0, 0x0, 0x7, (byte) 0xF8, (byte) 0xF4});
return doubles;
}
private static Map floats() {
Map floats = new HashMap<>();
- floats.put((float) 0.0, new byte[]{0x4, 0x8, 0x0, 0x0, 0x0, 0x0});
- floats.put((float) 1.0, new byte[]{0x4, 0x8, 0x3F, (byte) 0x80, 0x0,
- 0x0});
- floats.put((float) 1.1, new byte[]{0x4, 0x8, 0x3F, (byte) 0x8C,
- (byte) 0xCC, (byte) 0xCD});
- floats.put((float) 3.14, new byte[]{0x4, 0x8, 0x40, 0x48,
- (byte) 0xF5, (byte) 0xC3});
- floats.put((float) 9999.99, new byte[]{0x4, 0x8, 0x46, 0x1C, 0x3F,
- (byte) 0xF6});
- floats.put((float) -1.0, new byte[]{0x4, 0x8, (byte) 0xBF,
- (byte) 0x80, 0x0, 0x0});
- floats.put((float) -1.1, new byte[]{0x4, 0x8, (byte) 0xBF,
- (byte) 0x8C, (byte) 0xCC, (byte) 0xCD});
- floats.put((float) -3.14, new byte[]{0x4, 0x8, (byte) 0xC0, 0x48,
- (byte) 0xF5, (byte) 0xC3});
- floats.put((float) -9999.99, new byte[]{0x4, 0x8, (byte) 0xC6, 0x1C,
- 0x3F, (byte) 0xF6});
+ floats.put((float) 0.0, new byte[] {0x4, 0x8, 0x0, 0x0, 0x0, 0x0});
+ floats.put((float) 1.0, new byte[] {0x4, 0x8, 0x3F, (byte) 0x80, 0x0,
+ 0x0});
+ floats.put((float) 1.1, new byte[] {0x4, 0x8, 0x3F, (byte) 0x8C,
+ (byte) 0xCC, (byte) 0xCD});
+ floats.put((float) 3.14, new byte[] {0x4, 0x8, 0x40, 0x48,
+ (byte) 0xF5, (byte) 0xC3});
+ floats.put((float) 9999.99, new byte[] {0x4, 0x8, 0x46, 0x1C, 0x3F,
+ (byte) 0xF6});
+ floats.put((float) -1.0, new byte[] {0x4, 0x8, (byte) 0xBF,
+ (byte) 0x80, 0x0, 0x0});
+ floats.put((float) -1.1, new byte[] {0x4, 0x8, (byte) 0xBF,
+ (byte) 0x8C, (byte) 0xCC, (byte) 0xCD});
+ floats.put((float) -3.14, new byte[] {0x4, 0x8, (byte) 0xC0, 0x48,
+ (byte) 0xF5, (byte) 0xC3});
+ floats.put((float) -9999.99, new byte[] {0x4, 0x8, (byte) 0xC6, 0x1C,
+ 0x3F, (byte) 0xF6});
return floats;
}
@@ -259,8 +252,8 @@ private static Map floats() {
private static Map booleans() {
Map booleans = new HashMap<>();
- booleans.put(Boolean.FALSE, new byte[]{0x0, 0x7});
- booleans.put(Boolean.TRUE, new byte[]{0x1, 0x7});
+ booleans.put(Boolean.FALSE, new byte[] {0x0, 0x7});
+ booleans.put(Boolean.TRUE, new byte[] {0x1, 0x7});
return booleans;
}
@@ -268,52 +261,52 @@ private static Map