Bzip2ArchiveContentIdentifier extends ArchiveContentIdentifier { public final void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final String newPath = "bzip2:" + slash1 + path + request.getFileName() + "!" + slash; slash1 = ""; final URI newUri = URI.create(BZip2Utils.getUncompressedFilename(uri.toString())); final RequestIdentifier identifier = new RequestIdentifier(newUri); final RequestMetaData metaData = new RequestMetaData(SIZE, TIME, uri.getPath()); final BZipIdentificationRequest bzRequest = new BZipIdentificationRequest( metaData, identifier, tmpDir); BZip2CompressorInputStream bzipIn = null; try { bzipIn = new BZip2CompressorInputStream(request.getSourceInputStream()); bzRequest.open(bzipIn); final IdentificationResultCollection bzResults = binarySignatureIdentifier.matchBinarySignatures(bzRequest); final ResultPrinter resultPrinter = new ResultPrinter(binarySignatureIdentifier, containerSignatureDefinitions, newPath, slash, slash1, super.getArchiveConfiguration()); resultPrinter.print(bzResults, bzRequest); } catch (IOException ioe) { System.err.println(ioe + START_PARENTHESIS + newPath + END_PARENTHESIS); } finally { if (bzipIn != null) { try { bzipIn.close(); } catch (IOException e) { System.err.println(e + START_PARENTHESIS + newPath + END_PARENTHESIS); } } if (bzRequest != null) { try { bzRequest.close(); } catch (IOException e) { System.err.println(e + START_PARENTHESIS + newPath + END_PARENTHESIS); } } } } Bzip2ArchiveContentIdentifier(final BinarySignatureIdentifier binarySignatureIdentifier,
                                         final ContainerSignatureDefinitions containerSignatureDefinitions,
                                         final String path, final String slash, final String slash1, final ArchiveConfiguration archiveConfiguration); final void identify(final URI uri, final IdentificationRequest request);  }
@Test public void identifyBzip2ArchiveTest() throws CommandExecutionException { String fileName; final Path file = Paths.get(gZipFile); if (!Files.exists(file)) { fail("Bzip2 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); bzip2ArchiveContentIdentifier.identify(uri, request); } catch (IOException e) { throw new CommandExecutionException(e); } }