WarcArchiveContentIdentifier extends ArchiveContentIdentifier { public void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final int httpACCEPTED = 200; final String newPath = makeContainerURI("warc", request.getFileName()); setSlash1(""); final IdentificationRequestFactory factory = new WebArchiveEntryRequestFactory(); try { InputStream warcIn = request.getSourceInputStream(); WarcReader warcReader = WarcReaderFactory.getReader(warcIn); Iterator<WarcRecord> iterator = warcReader.iterator(); try { WarcRecord record = null; while (iterator.hasNext()) { record = iterator.next(); if ("response".equals(record.header.warcTypeStr) && record.getHttpHeader() != null && httpACCEPTED == record.getHttpHeader().statusCode) { String name = record.header.warcTargetUriStr; Long time = record.header.warcDate == null ? null : record.header.warcDate.getTime(); RequestMetaData metaData = new RequestMetaData( record.header.contentLength, time, name); final RequestIdentifier identifier = new RequestIdentifier(uri); IdentificationRequest warcRequest = factory.newRequest(metaData, identifier); ByteCountingPushBackInputStream in = (ByteCountingPushBackInputStream) record.getPayloadContent(); expandContainer(warcRequest, in, newPath); } } } finally { if (warcIn != null) { warcIn.close(); } } } catch (IOException ioe) { System.err.println(ioe + ": " + newPath); } } WarcArchiveContentIdentifier(final BinarySignatureIdentifier binarySignatureIdentifier,
                                        final ContainerSignatureDefinitions containerSignatureDefinitions,
                                        final String path, final String slash, final String slash1, ArchiveConfiguration archiveConfiguration); void identify(final URI uri, final IdentificationRequest request);  }
@Test public void identifyWarcArchiveTest() throws CommandExecutionException { String fileName; final Path file = Paths.get(warcFile); if (!Files.exists(file)) { fail("WARC test file not found"); } final URI uri = file.toUri(); RequestIdentifier identifier = new RequestIdentifier(uri); identifier.setParentId(1L); try { fileName = file.toAbsolutePath().toString(); RequestMetaData metaData = new RequestMetaData( Files.size(file), Files.getLastModifiedTime(file).toMillis(), fileName); FileSystemIdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier); request.open(file); warcArchiveContentIdentifier.identify(uri, request); } catch (Exception e) { throw new CommandExecutionException(e); } }