Package org.microproxy.warc
Class WarcReader
java.lang.Object
org.microproxy.warc.WarcReader
- All Implemented Interfaces:
Closeable,AutoCloseable
Reads WARC records (versions 1.0 and 1.1) one after another, as
WarcRecorder writes them
and as other archiving tools do: plain .warc files, or .warc.gz files with one
gzip member per record (or one for the whole file). ServerReplay
uses it to answer requests from recorded responses.
try (WarcReader reader = WarcReader.open(Path.of("warcs/microproxy-....warc.gz"))) {
for (WarcReader.Record r; (r = reader.next()) != null; ) {
if (r.type().equals("response")) System.out.println(r.field("WARC-Target-URI"));
}
}
Each record's block is read into memory whole.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne WARC record: its version line, named fields and block. -
Constructor Summary
ConstructorsConstructorDescriptionReads records fromin, which is decompressed if it starts with the gzip magic bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()next()Reads the next record.static WarcReaderOpens a WARC file.
-
Constructor Details
-
WarcReader
Reads records fromin, which is decompressed if it starts with the gzip magic bytes.- Parameters:
in- the WARC data- Throws:
IOException- if the stream cannot be read
-
-
Method Details
-
open
Opens a WARC file.- Parameters:
file- a.warcor.warc.gzfile- Returns:
- a reader positioned at the first record
- Throws:
IOException- if the file cannot be opened
-
next
Reads the next record.- Returns:
- the record, or null at the end of the input
- Throws:
IOException- if the input is not WARC or ends inside a record
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-