TarArchiveContentIdentifier extends ArchiveContentIdentifier { public void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final String newPath = makeContainerURI("tar", request.getFileName()); setSlash1(""); InputStream tarIn = null; try { tarIn = request.getSourceInputStream(); final TarArchiveInputStream in = new TarArchiveInputStream(tarIn); try { TarArchiveEntry entry = null; while ((entry = (TarArchiveEntry) in.getNextTarEntry()) != null) { String name = entry.getName(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getSize(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); final TarEntryIdentificationRequest tarRequest = new TarEntryIdentificationRequest(metaData, identifier, getTmpDir()); expandContainer(tarRequest, in, newPath); } } } finally { if (in != null) { in.close(); } } } catch (IOException ioe) { System.err.println(ioe + " (" + newPath + ")"); } finally { if (tarIn != null) { try { tarIn.close(); } catch (IOException ioe) { throw new CommandExecutionException(ioe.getMessage(), ioe); } } } } TarArchiveContentIdentifier(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 identifyGZipArchiveTest() throws CommandExecutionException { String fileName; final Path file = Paths.get(tarFile); if (!Files.exists(file)) { fail("TAR 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); FileSystemIdentificationRequest request = new FileSystemIdentificationRequest(metaData, identifier); request.open(file); tarArchiveContentIdentifier.identify(uri, request); } catch (IOException e) { throw new CommandExecutionException(e); } }