GZipArchiveContentIdentifier extends ArchiveContentIdentifier { public final void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final String newPath = "gzip:" + slash1 + path + request.getFileName() + "!" + slash; slash1 = ""; final URI newUri = URI.create(GzipUtils.getUncompressedFilename(uri.toString())); final RequestIdentifier identifier = new RequestIdentifier(newUri); final RequestMetaData metaData = new RequestMetaData(SIZE, TIME, uri.getPath()); final GZipIdentificationRequest gzRequest = new GZipIdentificationRequest( metaData, identifier, tmpDir); GZIPInputStream gzin = null; try { gzin = new GZIPInputStream(request.getSourceInputStream()); gzRequest.open(gzin); final IdentificationResultCollection gzResults = binarySignatureIdentifier.matchBinarySignatures(gzRequest); final ResultPrinter resultPrinter = new ResultPrinter(binarySignatureIdentifier, containerSignatureDefinitions, newPath, slash, slash1, super.getArchiveConfiguration()); resultPrinter.print(gzResults, gzRequest); } catch (IOException ioe) { System.err.println(ioe + " (" + newPath + ")"); } finally { if (gzin != null) { try { gzin.close(); } catch (IOException ioe) { throw new CommandExecutionException(ioe.getMessage(), ioe); } } if (gzRequest != null) { try { gzRequest.close(); } catch (IOException ioe) { throw new CommandExecutionException(ioe.getMessage(), ioe); } } } } GZipArchiveContentIdentifier(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 identifyGZipArchiveTest() throws CommandExecutionException { String fileName; final Path file = Paths.get(gZipFile); if (!Files.exists(file)) { fail("GZIP 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); gZipArchiveContentIdentifier.identify(uri, request); } catch (IOException e) { throw new CommandExecutionException(e); } }