ArcArchiveContentIdentifier extends ArchiveContentIdentifier { public void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final int httpACCEPTED = 200; final String newPath = makeContainerURI("arc", request.getFileName()); setSlash1(""); final IdentificationRequestFactory factory = new WebArchiveEntryRequestFactory(); InputStream arcIn = null; try { arcIn = request.getSourceInputStream(); Iterator<ArcRecordBase> iterator = ArcReaderFactory.getReader(arcIn).iterator(); ArcRecordBase base = null; try { while (iterator.hasNext()) { base = iterator.next(); if (base instanceof ArcRecord && base.getHttpHeader() != null && base.getHttpHeader().statusCode == httpACCEPTED) { String name = null; Uri baseUrl = base.getUrl(); if (baseUrl != null) { name = base.getUrl().toString(); } else { name = base.getUrlStr(); } if (name == null) { String errMsg = "Skipping record with invalid URL in ArcArchiveContentIdentifier: " + base.getHttpHeader().toString(); System.err.println(errMsg); } else { RequestMetaData metaData = new RequestMetaData( base.getArchiveLength(), base.getArchiveDate().getTime(), name); final RequestIdentifier identifier = new RequestIdentifier(uri); IdentificationRequest arcRequest = factory.newRequest(metaData, identifier); InputStream in = base.getPayloadContent(); expandContainer(arcRequest, in, newPath); } } } } catch (NullPointerException npe) { System.err.println("Skipping invalid record header in " + newPath + npe); } finally { if (arcIn != null) { arcIn.close(); } } } catch (IOException ioe) { System.err.println("Skipping invalid record in " + newPath + ioe); } } ArcArchiveContentIdentifier(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 identifyArcArchiveTest() throws CommandExecutionException { String fileName; final Path file = Paths.get(arcFile); if (!Files.exists(file)) { fail("ARC test file not found"); } 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); WebArchiveEntryIdentificationRequest request = new WebArchiveEntryIdentificationRequest(metaData, identifier, Paths.get(temporaryFolder.getRoot().getAbsolutePath())); try(final InputStream arcStream = Files.newInputStream(file)) { request.open(arcStream); arcArchiveContentIdentifier.identify(uri, request); } } catch (Exception e) { throw new CommandExecutionException(e); } }