|
26 | 26 | import java.util.concurrent.atomic.AtomicInteger; |
27 | 27 |
|
28 | 28 | public class ValidateWARC { |
29 | | - public static void main(String[] args) throws Exception { |
30 | | - if (args.length != 1) { |
31 | | - System.err.println("Usage: java ValidateWARC <file.gz>"); |
32 | | - System.exit(2); |
33 | | - } |
| 29 | + public static void main(String[] args) throws Exception { |
| 30 | + if (args.length != 1) { |
| 31 | + System.err.println("Usage: java ValidateWARC <file.gz>"); |
| 32 | + System.exit(2); |
| 33 | + } |
34 | 34 |
|
35 | | - Path requested = Path.of(args[0]).toAbsolutePath().normalize(); |
36 | | - if (!Files.isRegularFile(requested)) { |
37 | | - throw new SecurityException("Invalid WARC path"); |
38 | | - } |
| 35 | + Path requested = Path.of(args[0]).toAbsolutePath().normalize(); |
| 36 | + if (!Files.isRegularFile(requested)) { |
| 37 | + throw new SecurityException("Invalid WARC path"); |
| 38 | + } |
39 | 39 |
|
40 | | - int n = getWarcCompressionInformation(requested); |
41 | | - if (n <= 1) { |
42 | | - System.out.println("Single-member gzip (likely whole-file gzip). members=" + n); |
43 | | - } else { |
44 | | - System.out.println("Concatenated multi-member gzip (record-compressed). members=" + n); |
45 | | - } |
| 40 | + int n = getWarcCompressionInformation(requested); |
| 41 | + if (n <= 1) { |
| 42 | + System.out.println("Single-member gzip (likely whole-file gzip). members=" + n); |
| 43 | + } else { |
| 44 | + System.out.println("Concatenated multi-member gzip (record-compressed). members=" + n); |
| 45 | + } |
46 | 46 |
|
47 | | - } |
| 47 | + } |
48 | 48 |
|
49 | | - public static int getWarcCompressionInformation(Path inputWarc) throws IOException { |
50 | | - final AtomicInteger memberCount = new AtomicInteger(0); |
| 49 | + public static int getWarcCompressionInformation(Path inputWarc) throws IOException { |
| 50 | + final AtomicInteger memberCount = new AtomicInteger(0); |
51 | 51 |
|
52 | | - try ( |
53 | | - InputStream fis = Files.newInputStream(inputWarc); |
54 | | - BufferedInputStream bis = new BufferedInputStream(fis); |
55 | | - GzipCompressorInputStream gz = GzipCompressorInputStream.builder() |
56 | | - .setDecompressConcatenated(true) |
57 | | - .setOnMemberEnd(x -> memberCount.incrementAndGet()) |
58 | | - .setInputStream(bis).get() |
59 | | - ) { |
| 52 | + try (InputStream fis = Files.newInputStream(inputWarc); |
| 53 | + BufferedInputStream bis = new BufferedInputStream(fis); |
| 54 | + GzipCompressorInputStream gz = GzipCompressorInputStream.builder().setDecompressConcatenated(true) |
| 55 | + .setOnMemberEnd(x -> memberCount.incrementAndGet()).setInputStream(bis).get()) { |
60 | 56 |
|
61 | | - byte[] buf = new byte[64 * 1024]; |
62 | | - while (gz.read(buf) != -1) { |
63 | | - // Read the entire stream to trigger member processing |
64 | | - // We might not need to read the whole stream, just enough to get an idea |
65 | | - } |
66 | | - } catch (IOException e) { |
67 | | - throw new IllegalArgumentException("The file is either not a gzip file or is corrupted.", e); |
68 | | - } |
| 57 | + byte[] buf = new byte[64 * 1024]; |
| 58 | + while (gz.read(buf) != -1) { |
| 59 | + // Read the entire stream to trigger member processing |
| 60 | + // We might not need to read the whole stream, just enough to get an idea |
| 61 | + } |
| 62 | + } catch (IOException e) { |
| 63 | + throw new IllegalArgumentException("The file is either not a gzip file or is corrupted.", e); |
| 64 | + } |
69 | 65 |
|
70 | | - return memberCount.get(); |
71 | | - } |
| 66 | + return memberCount.get(); |
| 67 | + } |
72 | 68 |
|
73 | | - public static void validateRandomAccessWarcOrFail(Path inputWarc) throws IOException { |
74 | | - int n = getWarcCompressionInformation(inputWarc); |
| 69 | + public static void validateRandomAccessWarcOrFail(Path inputWarc) throws IOException { |
| 70 | + int n = getWarcCompressionInformation(inputWarc); |
75 | 71 |
|
76 | | - if (n <= 1) { |
77 | | - throw new IOException("Non-chunked gzip file detected, gzip block continues\n" + |
78 | | - " beyond single record. " + n); |
79 | | - } |
| 72 | + if (n <= 1) { |
| 73 | + throw new IOException( |
| 74 | + "Non-chunked gzip file detected, gzip block continues\n" + " beyond single record. " + n); |
| 75 | + } |
80 | 76 |
|
81 | | - } |
| 77 | + } |
82 | 78 | } |
0 commit comments