Skip to content

Commit d389766

Browse files
committed
#9 - Added URI based stream factories to WarcRecordIteratorFactory.
1 parent 452fadc commit d389766

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

java-warc/src/main/java/com/github/bottomlessarchive/warc/service/WarcRecordIteratorFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.BufferedInputStream;
77
import java.io.IOException;
88
import java.io.InputStream;
9+
import java.net.MalformedURLException;
10+
import java.net.URI;
911
import java.net.URL;
1012
import java.nio.charset.Charset;
1113
import java.util.Iterator;
@@ -15,6 +17,14 @@ public class WarcRecordIteratorFactory {
1517

1618
private static final int ONE_MEGABYTE_IN_BYTE = 1048576;
1719

20+
public static <T extends WarcContentBlock> Iterator<WarcRecord<T>> iteratorOf(final URI uri) {
21+
try {
22+
return iteratorOf(uri.toURL());
23+
} catch (MalformedURLException e) {
24+
throw new WarcNetworkException("Unable to parse WARC location: " + uri + "!", e);
25+
}
26+
}
27+
1828
public static <T extends WarcContentBlock> Iterator<WarcRecord<T>> iteratorOf(final URL url) {
1929
try {
2030
return iteratorOf(new AvailableInputStream(new BufferedInputStream(url.openStream(), ONE_MEGABYTE_IN_BYTE)),
@@ -33,7 +43,7 @@ public static <T extends WarcContentBlock> Iterator<WarcRecord<T>> iteratorOf(fi
3343
}
3444

3545
public static <T extends WarcContentBlock> Iterator<WarcRecord<T>> iteratorOf(final InputStream inputStream, final Charset charset,
36-
final boolean compressed) {
46+
final boolean compressed) {
3747
final WarcReader warcReader = new WarcReader(inputStream, charset, compressed);
3848

3949
return (Iterator<WarcRecord<T>>) new WarcRecordIterator(warcReader);

0 commit comments

Comments
 (0)