Skip to content

Commit fd1bf1e

Browse files
committed
Parametrize all Reader tests
1 parent 181f754 commit fd1bf1e

File tree

3 files changed

+124
-78
lines changed

3 files changed

+124
-78
lines changed

src/main/java/com/maxmind/db/BufferHolder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ final class BufferHolder {
1515
private final Buffer buffer;
1616

1717
BufferHolder(File database, FileMode mode) throws IOException {
18+
this(database, mode, MultiBuffer.DEFAULT_CHUNK_SIZE);
19+
}
20+
21+
BufferHolder(File database, FileMode mode, int chunkSize) throws IOException {
1822
try (RandomAccessFile file = new RandomAccessFile(database, "r");
1923
FileChannel channel = file.getChannel()) {
2024
long size = channel.size();
2125
if (mode == FileMode.MEMORY) {
2226
Buffer buf;
23-
if (size <= MultiBuffer.DEFAULT_CHUNK_SIZE) {
27+
if (size <= chunkSize) {
2428
buf = new SingleBuffer(size);
2529
} else {
2630
buf = new MultiBuffer(size);
@@ -32,7 +36,7 @@ final class BufferHolder {
3236
}
3337
this.buffer = buf;
3438
} else {
35-
if (size <= MultiBuffer.DEFAULT_CHUNK_SIZE) {
39+
if (size <= chunkSize) {
3640
this.buffer = SingleBuffer.mapFromChannel(channel);
3741
} else {
3842
this.buffer = MultiBuffer.mapFromChannel(channel);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public Reader(File database) throws IOException {
5656
this(database, NoCache.getInstance());
5757
}
5858

59+
Reader(File database, int chunkSize) throws IOException {
60+
this(
61+
new BufferHolder(database, FileMode.MEMORY_MAPPED, chunkSize),
62+
database.getName(),
63+
NoCache.getInstance()
64+
);
65+
}
66+
5967
/**
6068
* Constructs a Reader for the MaxMind DB format, with the specified backing
6169
* cache. The file passed to it must be a valid MaxMind DB file such as a
@@ -69,6 +77,14 @@ public Reader(File database, NodeCache cache) throws IOException {
6977
this(database, FileMode.MEMORY_MAPPED, cache);
7078
}
7179

80+
Reader(File database, NodeCache cache, int chunkSize) throws IOException {
81+
this(
82+
new BufferHolder(database, FileMode.MEMORY_MAPPED, chunkSize),
83+
database.getName(),
84+
cache
85+
);
86+
}
87+
7288
/**
7389
* Constructs a Reader with no caching, as if in mode
7490
* {@link FileMode#MEMORY}, without using a <code>File</code> instance.

0 commit comments

Comments
 (0)