Skip to content

Commit 8f8f91e

Browse files
committed
Allow loading cache from InputStream
Closes #308
1 parent 1984e36 commit 8f8f91e

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/main/java/org/xbill/DNS/Cache.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package org.xbill.DNS;
55

66
import java.io.IOException;
7+
import java.io.InputStream;
78
import java.util.HashSet;
89
import java.util.LinkedHashMap;
910
import java.util.LinkedList;
@@ -170,9 +171,9 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
170171
}
171172

172173
private final CacheMap data;
174+
private final int dclass;
173175
private int maxncache = -1;
174176
private int maxcache = -1;
175-
private int dclass;
176177

177178
private static final int defaultMaxEntries = 50000;
178179

@@ -198,11 +199,24 @@ public Cache() {
198199

199200
/** Creates a Cache which initially contains all records in the specified file. */
200201
public Cache(String file) throws IOException {
201-
data = new CacheMap(defaultMaxEntries);
202-
try (Master m = new Master(file)) {
203-
Record record;
204-
while ((record = m.nextRecord()) != null) {
205-
addRecord(record, Credibility.HINT);
202+
this(new Master(file));
203+
}
204+
205+
/**
206+
* Creates a Cache which initially contains all records in the specified stream.
207+
*
208+
* @since 3.6.2
209+
*/
210+
public Cache(InputStream input) throws IOException {
211+
this(new Master(input));
212+
}
213+
214+
private <T> Cache(Master m) throws IOException {
215+
this();
216+
try (m) {
217+
Record r;
218+
while ((r = m.nextRecord()) != null) {
219+
addRecord(r, Credibility.HINT);
206220
}
207221
}
208222
}

0 commit comments

Comments
 (0)