/** * Helper method to open an identification request. */ private void openIdentificationRequest(File file) { try { URI resourceUri = file.toURI(); RequestMetaData metadata = new RequestMetaData(file.length(), file.lastModified(), file.getName()); RequestIdentifier requestIdentifier = new RequestIdentifier(resourceUri); identificationRequest = new FileSystemIdentificationRequest(metadata, requestIdentifier); FileInputStream inputStream = new FileInputStream(file); identificationRequest.open(inputStream); } catch (Exception e) { log.error("Could not open identification request.", e); } }
/** * Submits a request to droid. * @param entry the arc entry to submit * @param entryName the name of the entry * @param parentName the name of the parent file * @param in the archive input stream * @param correlationId the correlation Id for the request * @param originatorNodeId the Id of the originator node * @throws IOException if the input stream could not be read */ final void submit(WarcRecord entry, String entryName, URI parentName, InputStream in, ResourceId correlationId, long originatorNodeId) throws IOException { WarcHeader header = entry.header; long size = header.contentLength; Date time = header.warcDate; RequestMetaData metaData = new RequestMetaData( size == -1 ? null : size, time == null ? null : time.getTime(), entryName); super.submit(WEB_ARCHIVE_TYPE, metaData, parentName, entry.getPayloadContent(), correlationId, originatorNodeId); }
private ResourceId submitDirectory(String path, long lastModifiedTime) throws URISyntaxException, UnsupportedEncodingException { String parentPath = FilenameUtils.getPath(path.substring(0, path.length() - 1)); String name = FilenameUtils.getName(path.substring(0, path.length() - 1)); log.debug("processing path: " + path + " name: " + name); ResourceId resourceId = directories.get(name); if (resourceId == null) { ResourceId parentID = directories.get(parentPath); if (parentID == null) { parentID = submitDirectory(parentPath, lastModifiedTime); } RequestMetaData metaData = new RequestMetaData(null, lastModifiedTime, name); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toIsoImageUri(isoFileUri, path)); IdentificationResultImpl result = new IdentificationResultImpl(); result.setRequestMetaData(metaData); result.setIdentifier(identifier); resourceId = resultHandler.handleDirectory(result, parentID, false); this.directories.put(path, resourceId); } return resourceId; }
private ResourceId submitDirectory(String path, long lastModifiedTime) throws URISyntaxException, UnsupportedEncodingException { String parentPath = FilenameUtils.getPath(path.substring(0, path.length() - 1)); String name = FilenameUtils.getName(path.substring(0, path.length() - 1)); log.debug("processing path: " + path + " name: " + name); ResourceId resourceId = directories.get(name); if (resourceId == null) { ResourceId parentID = directories.get(parentPath); if (parentID == null) { parentID = submitDirectory(parentPath, lastModifiedTime); } RequestMetaData metaData = new RequestMetaData(null, lastModifiedTime, name); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toIsoImageUri(isoFileUri, path)); IdentificationResultImpl result = new IdentificationResultImpl(); result.setRequestMetaData(metaData); result.setIdentifier(identifier); resourceId = resultHandler.handleDirectory(result, parentID, false); this.directories.put(path, resourceId); } return resourceId; }
/** * Handles a directory. * @param dir the directory to handle * @param parentId the directory's parent id * @param depth the depth of the directory in the tree * @param restricted true if access to the directory was restricted, false otherwise * @return the id of the directory */ public ResourceId onEvent(final Path dir, ResourceId parentId, int depth, boolean restricted) { IdentificationResultImpl result = new IdentificationResultImpl(); result.setMethod(IdentificationMethod.NULL); final FileTime lastModified = FileUtil.lastModifiedQuietly(dir); RequestMetaData metaData = new RequestMetaData( FileUtil.sizeQuietly(dir), lastModified == null ? new Date(0).getTime() : new Date(lastModified.toMillis()).getTime(), depth == 0 ? dir.toAbsolutePath().toString() : FileUtil.fileName(dir)); RequestIdentifier identifier = new RequestIdentifier(SubmitterUtils.toURI(dir.toFile(), uriStringBuilder)); identifier.setParentResourceId(parentId); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, parentId, restricted); }
/** * Submits a request to droid. * @param entry the arc entry to submit * @param entryName the name of the entry * @param parentName the name of the parent file * @param in the archive input stream * @param correlationId the correlation Id for the request * @param originatorNodeId the Id of the originator node * @throws IOException if the input stream could not be read */ final void submit(ArcRecordBase entry, String entryName, URI parentName, InputStream in, ResourceId correlationId, long originatorNodeId) throws IOException { long size = entry.getArchiveLength(); Date time = entry.getArchiveDate(); RequestMetaData metaData = new RequestMetaData( size == -1 ? null : size, time == null ? null : time.getTime(), entryName); super.submit(WEB_ARCHIVE_TYPE, metaData, parentName, entry.getPayloadContent(), correlationId, originatorNodeId); }
private ResourceId submitDirectory(String fullPath, Date mTime) throws URISyntaxException, UnsupportedEncodingException { String parentPath = FilenameUtils.getPath(fullPath.substring(0, fullPath.length() - 1)); String name = FilenameUtils.getName(fullPath.substring(0, fullPath.length() - 1)); //CHECKSTYLE:OFF log.debug("submitDirectory, processing path: " + parentPath + " name: " + name); //CHECKSTYLE:ON ResourceId resourceId = getFromDirCache(fullPath); if (resourceId == null) { ResourceId parentID = getFromDirCache(parentPath); if (parentID == null) { parentID = submitDirectory(parentPath, mTime); } RequestMetaData metaData = new RequestMetaData(null, mTime.getTime(), name); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toRarUri(parentURI, fullPath)); IdentificationResultImpl result = new IdentificationResultImpl(); result.setRequestMetaData(metaData); result.setIdentifier(identifier); resourceId = resultHandler.handleDirectory(result, parentID, false); saveDirToCache(fullPath, resourceId); } return resourceId; }
private void processEntry(FsDirectoryEntry entry, URI uri, String newPath) throws CommandExecutionException, IOException { String name = entry.getName(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getFile().getLength(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); FatFileIdentificationRequest req = new FatFileIdentificationRequest(metaData, identifier, getTmpDir()); ByteBuffer buffer = ByteBuffer.allocate((int) entry.getFile().getLength()); entry.getFile().read(0, buffer); buffer.flip(); expandContainer(req, new ByteArrayInputStream(buffer.array(), buffer.position(), buffer.limit()), newPath); } else { log.trace("processing directory : " + entry.getName()); } } }
private ResourceId submitDirectory(String fullPath, Date mTime) throws URISyntaxException, UnsupportedEncodingException { String parentPath = FilenameUtils.getPath(fullPath.substring(0, fullPath.length() - 1)); String name = FilenameUtils.getName(fullPath.substring(0, fullPath.length() - 1)); //CHECKSTYLE:OFF log.debug("submitDirectory, processing path: " + parentPath + " name: " + name); //CHECKSTYLE:ON ResourceId resourceId = getFromDirCache(fullPath); if (resourceId == null) { ResourceId parentID = getFromDirCache(parentPath); if (parentID == null) { parentID = submitDirectory(parentPath, mTime); } RequestMetaData metaData = new RequestMetaData(null, mTime.getTime(), name); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toRarUri(parentURI, fullPath)); IdentificationResultImpl result = new IdentificationResultImpl(); result.setRequestMetaData(metaData); result.setIdentifier(identifier); resourceId = resultHandler.handleDirectory(result, parentID, false); saveDirToCache(fullPath, resourceId); } return resourceId; }
private void submitDirectory(FsDirectoryEntry directoryEntry) throws IOException { ResourceId resourceId = directories.get(directoryEntry); if (resourceId == null) { FsDirectoryEntry parent = parentMap.get(directoryEntry); ResourceId parentID; if (parent != null) { parentID = directories.get(parent); } else { parentID = rootParentId; } RequestMetaData metaData = new RequestMetaData(null, directoryEntry.getLastModified(), directoryEntry.getName()); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toFatImageUri(fatFileUri, expand(directoryEntry, parentMap))); IdentificationResultImpl result = new IdentificationResultImpl(); result.setRequestMetaData(metaData); result.setIdentifier(identifier); resourceId = resultHandler.handleDirectory(result, parentID, false); this.directories.put(directoryEntry, resourceId); } }
/** * Handles a directory. * @param dir the directory to handle * @param parentId the directory's parent id * @param depth the depth of the directory in the tree * @param restricted true if access to the directory was restricted, false otherwise * @return the id of the directory */ public ResourceId onEvent(File dir, ResourceId parentId, int depth, boolean restricted) { IdentificationResultImpl result = new IdentificationResultImpl(); result.setMethod(IdentificationMethod.NULL); RequestMetaData metaData = new RequestMetaData( dir.length(), dir.lastModified(), depth == 0 ? dir.getAbsolutePath() : dir.getName()); RequestIdentifier identifier = new RequestIdentifier(SubmitterUtils.toURI(dir, uriStringBuilder)); identifier.setParentResourceId(parentId); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, parentId, restricted); }
private void submitFile(FsFile file, FsDirectoryEntry entry) throws IOException { FsDirectoryEntry parent = parentMap.get(entry); ResourceId correlationId = rootParentId; if (parent != null) { correlationId = directories.get(parent); } RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toFatImageUri(fatFileUri, expand(entry, parentMap))); identifier.setAncestorId(originatorNodeId); identifier.setParentResourceId(correlationId); RequestMetaData requestMetaData = new RequestMetaData(file.getLength(), entry.getCreated(), entry.getName()); IdentificationRequest<InputStream> req = factory.newRequest(requestMetaData, identifier); Path tempFile = ArchiveFileUtils.writeFsFileToTemp(entry, ((FatFileIdentificationRequest) req).getTempDir()); InputStream is = new FileInputStream(tempFile.toFile()); req.open(is); droid.submit(req); }
private void processEntry(FileHeader entry, Archive archive, URI uri, String newPath) throws CommandExecutionException, IOException, RarException { String name = entry.getFileNameString(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getUnpSize(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); RarIdentificationRequest req = new RarIdentificationRequest(metaData, identifier, getTmpDir()); expandContainer(req, archive.getInputStream(entry), newPath); } else { log.trace("processing directory : " + entry.getFileNameString()); } } }
private void processEntry(Iso9660FileEntry entry, URI uri, Iso9660FileSystem fileSystem, String newPath) throws CommandExecutionException { String name = entry.getPath(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getSize(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); ISOImageIdentificationRequest req = new ISOImageIdentificationRequest(metaData, identifier, getTmpDir()); expandContainer(req, fileSystem.getInputStream(entry), newPath); } else { log.trace("processing directory : " + entry.getPath()); } } }
/** * @param webArchiveType * @param parentName * @param resourceName * @param entryName * @param correlationId * @return */ private ResourceId submitDirectory(final String webArchiveType, final URI parentName, String resourceName, String entryName, ResourceId correlationId) { IdentificationResultImpl result = new IdentificationResultImpl(); RequestMetaData metaData = new RequestMetaData(null, null, entryName); RequestIdentifier identifier = new RequestIdentifier( ArchiveFileUtils.toWebArchiveUri(webArchiveType, parentName, resourceName)); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, correlationId, false); }
/** * @param webArchiveType * @param parentName * @param resourceName * @param entryName * @param correlationId * @return */ private ResourceId submitDirectory(final String webArchiveType, final URI parentName, String resourceName, String entryName, ResourceId correlationId) { IdentificationResultImpl result = new IdentificationResultImpl(); RequestMetaData metaData = new RequestMetaData(null, null, entryName); RequestIdentifier identifier = new RequestIdentifier( ArchiveFileUtils.toWebArchiveUri(webArchiveType, parentName, resourceName)); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, correlationId, false); }
private void processEntry(SevenZArchiveEntry entry, ArchiveInputStream archiveStream, URI uri, String newPath) throws CommandExecutionException { String name = entry.getName(); if (!entry.isDirectory()) { final RequestMetaData metaData = new RequestMetaData(entry.getSize(), 2L, name); final RequestIdentifier identifier = new RequestIdentifier(uri); SevenZipEntryIdentificationRequest req = new SevenZipEntryIdentificationRequest(metaData, identifier, getTmpDir()); BoundedInputStream entryStream = new BoundedInputStream(archiveStream, entry.getSize()); entryStream.setPropagateClose(false); //Don't close ArchiveStream!!!! expandContainer(req, entryStream, newPath); } else { log.debug("processing directory : " + entry.getName()); } }
/** * @param parentName * @param entry * @param entryName * @param correlationId * @return */ private ResourceId submitDirectory(final URI parentName, TarArchiveEntry entry, String entryName, ResourceId correlationId) { IdentificationResultImpl result = new IdentificationResultImpl(); long size = entry.getSize(); Date date = entry.getModTime(); long time = date == null ? -1 : date.getTime(); RequestMetaData metaData = new RequestMetaData( size != -1 ? size : null, time != -1 ? time : null, entryName); RequestIdentifier identifier = new RequestIdentifier( ArchiveFileUtils.toTarUri(parentName, entry.getName())); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, correlationId, false); }
/** * @param parentName * @param entry * @param entryName * @param correlationId * @return */ private ResourceId submitDirectory(final URI parentName, TarArchiveEntry entry, String entryName, ResourceId correlationId) { IdentificationResultImpl result = new IdentificationResultImpl(); long size = entry.getSize(); Date date = entry.getModTime(); long time = date == null ? -1 : date.getTime(); RequestMetaData metaData = new RequestMetaData( size != -1 ? size : null, time != -1 ? time : null, entryName); RequestIdentifier identifier = new RequestIdentifier( ArchiveFileUtils.toTarUri(parentName, entry.getName())); result.setRequestMetaData(metaData); result.setIdentifier(identifier); return resultHandler.handleDirectory(result, correlationId, false); }
private void submitFile(FileHeader entry) throws IOException, URISyntaxException, RarException { String fullpath = entry.getFileNameString(); String path = FilenameUtils.getPath(fullpath); String name = FilenameUtils.getName(fullpath); //CHECKSTYLE:OFF log.debug("submitFile, processing path: " + path + " name: " + name); //CHECKSTYLE:ON ResourceId correlationId = getFromDirCache(path); if (correlationId == null) { correlationId = submitDirectory(path, entry.getMTime()); } InputStream entryInputStream = archive.getInputStream(entry); RequestIdentifier identifier = new RequestIdentifier(ArchiveFileUtils.toRarUri(parentURI, path + name)); identifier.setAncestorId(originatorNodeId); identifier.setParentResourceId(correlationId); RequestMetaData metaData = new RequestMetaData(entry.getUnpSize(), entry.getMTime().getTime(), name); IdentificationRequest<InputStream> request = identificationRequestFactory.newRequest(metaData, identifier); request.open(entryInputStream); droid.submit(request); }