RarArchiveContainerIdentifier extends ArchiveContentIdentifier { public void identify(final URI uri, final IdentificationRequest request) throws CommandExecutionException { final String newPath = makeContainerURI("rar", request.getFileName()); setSlash1(""); if (request.getClass().isAssignableFrom(FileSystemIdentificationRequest.class)) { FileSystemIdentificationRequest req = (FileSystemIdentificationRequest) request; FileVolumeManager fileVolumeManager = new FileVolumeManager(req.getFile().toFile()); try { try (Archive archive = new Archive(fileVolumeManager)) { if (archive.isEncrypted()) { log.info("encrypted rar"); } else { for (FileHeader entry : archive.getFileHeaders()) { processEntry(entry, archive, uri, newPath); } } } } catch (RarException | IOException e) { System.err.println(e + START_PARENTHESIS + newPath + END_PARENTHESIS); } } else { log.info("Identification request for RAR archive ignored due to limited support."); } } RarArchiveContainerIdentifier(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 identifyRarFile() throws CommandExecutionException { String fileName; final Path file = Paths.get(rarFile); 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); rarArchiveContainerIdentifier.identify(uri, request); } catch (IOException e) { throw new CommandExecutionException(e); } }