List of usage examples for java.nio.file Files newDirectoryStream
public static DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException
From source file:com.marklogic.entityservices.e2e.ExamplesBase.java
private void importOrDescend(Path directory, WriteHostBatcher batcher, String collection, Format format) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { logger.info("Reading subdirectory " + entry.getFileName().toString()); importOrDescend(entry, batcher, collection, format); } else { logger.debug("Adding " + entry.getFileName().toString()); String uri = entry.toUri().toString(); if (collection != null) { DocumentMetadataHandle metadata = new DocumentMetadataHandle().withCollections(collection) // .withPermission("nwind-reader", Capability.READ) // .withPermission("nwind-writer", Capability.INSERT, Capability.UPDATE); batcher.add(uri, metadata, new FileHandle(entry.toFile()).withFormat(format)); } else { batcher.add(uri, new FileHandle(entry.toFile()).withFormat(format)); }/* w ww. j ava 2 s . c o m*/ logger.debug("Inserted " + format.toString() + " document " + uri); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.marklogic.entityservices.examples.ExamplesBase.java
private void importOrDescend(Path directory, WriteHostBatcher batcher, String collection, Format format) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { for (Path entry : stream) { if (entry.toFile().isDirectory()) { logger.info("Reading subdirectory " + entry.getFileName().toString()); importOrDescend(entry, batcher, collection, format); } else { logger.debug("Adding " + entry.getFileName().toString()); String uri = entry.toUri().toString(); if (collection != null) { DocumentMetadataHandle metadata = new DocumentMetadataHandle().withCollections(collection) // .withPermission("race-reader", Capability.READ) // .withPermission("race-writer", Capability.INSERT, Capability.UPDATE); batcher.add(uri, metadata, new FileHandle(entry.toFile()).withFormat(format)); } else { batcher.add(uri, new FileHandle(entry.toFile()).withFormat(format)); }/*from w ww . ja v a 2 s . c om*/ logger.debug("Inserted " + format.toString() + " document " + uri); } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.zergiu.tvman.controllers.FSBrowseController.java
/** * @param children// w ww. j a va2 s .c o m * @param parent * @return * @throws IOException */ private void addChildFolders(Map<String, String> children, Path parent) throws IOException { try (DirectoryStream<Path> paths = Files.newDirectoryStream(parent)) { for (Path path : paths) { if (Files.isDirectory(path)) { Path name = path.getFileName(); children.put(path.toString(), name.toString()); } } } //try }
From source file:com.cyc.corpus.nlmpaper.AIMedOpenAccessPaper.java
private List<Path> listArchiveFiles(Path underHere) { List res = new ArrayList<>(); try {/*w ww.j a va2 s . c om*/ Files.newDirectoryStream(underHere).forEach((p) -> { if (Files.isRegularFile(p, LinkOption.NOFOLLOW_LINKS)) { res.add(p); } else if (Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)) { res.addAll(listArchiveFiles(p)); } }); } catch (IOException ex) { LOG.log(Level.SEVERE, null, ex); } return res; }
From source file:edu.usc.goffish.gofs.tools.deploy.SCPPartitionDistributer.java
@Override public UUID distribute(URI location, ISerializablePartition partition) throws IOException { Path workingDir = Files.createTempDirectory("gofs_scpdist"); System.out.print("writing partition... "); long total = 0; int numSubgraphBins = _numSubgraphBins; if (_numSubgraphBins == -1 || _numSubgraphBins > partition.size()) { numSubgraphBins = partition.size(); }// w w w .j av a 2s .c o m // write slices for partition ISliceManager sliceManager = SliceManager.create(_serializer, new FileStorageManager(workingDir)); total += sliceManager.writePartition(partition, _instancesGroupingSize, numSubgraphBins); System.out.println("[" + total / 1000 + " KB]"); // prepare list of files to scp List<Path> sliceFiles = new LinkedList<>(); try (DirectoryStream<Path> sliceDir = Files.newDirectoryStream(workingDir)) { for (Path slice : sliceDir) { sliceFiles.add(slice); } } // scp files System.out.println("moving partition " + partition.getId() + " to " + location + "..."); SCPHelper.SCP(_scpBinaryPath, _extraSCPOptions, sliceFiles, location); // delete files FileUtils.deleteQuietly(workingDir.toFile()); // append partition UUID information as fragment to location and return location return sliceManager.getPartitionUUID(); }
From source file:de.fatalix.bookery.bl.background.importer.CalibriImporter.java
private void processArchive(final Path zipFile, final int batchSize) throws IOException { try (FileSystem zipFileSystem = FileSystems.newFileSystem(zipFile, null)) { final List<BookEntry> bookEntries = new ArrayList<>(); Path root = zipFileSystem.getPath("/"); Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override/*from w ww. j ava 2 s . c om*/ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (dir.toString().contains("__MACOSX")) { return FileVisitResult.SKIP_SUBTREE; } try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(dir)) { BookEntry bookEntry = new BookEntry().setUploader("admin"); for (Path path : directoryStream) { if (!Files.isDirectory(path)) { if (path.toString().contains(".opf")) { bookEntry = parseOPF(path, bookEntry); } if (path.toString().contains(".mobi")) { bookEntry.setMobi(Files.readAllBytes(path)).setMimeType("MOBI"); } if (path.toString().contains(".epub")) { bookEntry.setEpub(Files.readAllBytes(path)); } if (path.toString().contains(".jpg")) { bookEntry.setCover(Files.readAllBytes(path)); ByteArrayOutputStream output = new ByteArrayOutputStream(); Thumbnails.of(new ByteArrayInputStream(bookEntry.getCover())).size(130, 200) .toOutputStream(output); bookEntry.setThumbnail(output.toByteArray()); bookEntry.setThumbnailGenerated("done"); } } } if (bookEntry.getMobi() != null || bookEntry.getEpub() != null) { bookEntries.add(bookEntry); if (bookEntries.size() > batchSize) { logger.info("Adding " + bookEntries.size() + " Books..."); try { solrHandler.addBeans(bookEntries); } catch (SolrServerException ex) { logger.error(ex, ex); } bookEntries.clear(); } } } catch (IOException ex) { logger.error(ex, ex); } return super.preVisitDirectory(dir, attrs); } }); try { if (!bookEntries.isEmpty()) { logger.info("Adding " + bookEntries.size() + " Books..."); solrHandler.addBeans(bookEntries); } } catch (SolrServerException ex) { logger.error(ex, ex); } } finally { Files.delete(zipFile); } }
From source file:org.roda.core.model.iterables.LogEntryFileSystemIterable.java
public LogEntryFileSystemIterable(Path logPath) throws IOException { this.directoryStream = Files.newDirectoryStream(logPath); }
From source file:com.cirrus.server.osgi.service.local.LocalStorageService.java
@Override public List<ICirrusData> list(final String path) throws ServiceRequestFailedException { final Path newPath = Paths.get(this.getGlobalContext().getRootPath(), path); if (!Files.exists(newPath)) { throw new ServiceRequestFailedException("The directory <" + newPath + "> doesn't exist"); }//w w w . j a va 2s. co m if (!Files.isDirectory(newPath)) { throw new ServiceRequestFailedException("The path <" + newPath + "> is not a directory"); } final List<ICirrusData> result = new ArrayList<>(); try (final DirectoryStream<Path> directoryStream = Files.newDirectoryStream(newPath)) { for (final Path currentPath : directoryStream) { result.add(this.createCirrusDataFromFile(currentPath)); } } catch (final IOException e) { throw new ServiceRequestFailedException(e); } return result; }
From source file:net.certiv.antlr.project.util.Utils.java
/** * Move all files from the source directory to the destination directory. * /*w ww . jav a 2 s . c o m*/ * @param source * the source directory * @param dest * the destination directory * @return * @throws IOException */ public static boolean moveAllFiles(File source, File dest) throws IOException { if (source == null || dest == null) throw new IllegalArgumentException("Directory cannot be null"); if (!source.exists() || !source.isDirectory()) throw new IOException("Source directory must exist: " + source.getCanonicalPath()); dest.mkdirs(); if (!dest.exists() || !dest.isDirectory()) throw new IOException("Destination directory must exist: " + dest.getCanonicalPath()); Path srcDir = source.toPath(); Path dstDir = dest.toPath(); DirectoryStream<Path> ds = Files.newDirectoryStream(srcDir); int tot = 0; for (Path src : ds) { Files.copy(src, dstDir.resolve(src.getFileName()), REPLACE_EXISTING); tot++; } Log.info(Utils.class, "Moved " + tot + " files"); return false; }
From source file:org.digidoc4j.impl.bdoc.BDocContainerTest.java
@AfterClass public static void deleteTemporaryFiles() { try {//from ww w . java 2 s . c o m DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(".")); for (Path item : directoryStream) { String fileName = item.getFileName().toString(); if (fileName.endsWith("bdoc") && fileName.startsWith("test")) Files.deleteIfExists(item); } } catch (IOException e) { e.printStackTrace(); } }