List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:ListFiles.java
@Override public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes attributes) throws IOException { indent();/* ww w. ja va2s .c om*/ System.out.println("About to traverse the directory: " + directory.getFileName()); indentionLevel += indentionAmount; return FileVisitResult.CONTINUE; }
From source file:com.marklogic.entityservices.e2e.CSVLoader.java
public void go() throws InterruptedException { logger.info("job started."); File dir = new File(projectDir + "/data/superstore-csv"); WriteHostBatcher batcher = moveMgr.newWriteHostBatcher().withBatchSize(100).withThreadCount(10) .onBatchSuccess((client, batch) -> logger.info(getSummaryReport(batch))) .onBatchFailure((client, batch, throwable) -> { logger.warn("FAILURE on batch:" + batch.toString() + "\n", throwable); throwable.printStackTrace(); });//w ww. j a v a 2 s. co m ticket = moveMgr.startJob(batcher); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath(), "*.csv")) { for (Path entry : stream) { logger.debug("Adding " + entry.getFileName().toString()); MappingIterator<ObjectNode> it = csvMapper.readerFor(ObjectNode.class).with(bootstrapSchema) .readValues(entry.toFile()); long i = 0; while (it.hasNext()) { ObjectNode jsonNode = it.next(); String jsonString = mapper.writeValueAsString(jsonNode); String uri = entry.toUri().toString() + "-" + Long.toString(i++) + ".json"; DocumentMetadataHandle metadata = new DocumentMetadataHandle() // .withCollections("raw", "csv") // .withPermission("nwind-reader", Capability.READ) // .withPermission("nwind-writer", Capability.INSERT, Capability.UPDATE); batcher.add(uri, metadata, new StringHandle(jsonString)); if (i % 1000 == 0) logger.debug("Inserting JSON document " + uri); } it.close(); } } catch (IOException e) { e.printStackTrace(); } batcher.flush(); }
From source file:com.marklogic.entityservices.examples.CSVLoader.java
public void go() throws InterruptedException { logger.info("job started."); File dir = new File(projectDir + "/data/third-party/csv"); WriteHostBatcher batcher = moveMgr.newWriteHostBatcher().withBatchSize(100).withThreadCount(10) .onBatchSuccess((client, batch) -> logger.info(getSummaryReport(batch))) .onBatchFailure((client, batch, throwable) -> { logger.warn("FAILURE on batch:" + batch.toString() + "\n", throwable); throwable.printStackTrace(); });// w w w . ja va2 s. co m ticket = moveMgr.startJob(batcher); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath(), "*.csv")) { for (Path entry : stream) { logger.debug("Adding " + entry.getFileName().toString()); MappingIterator<ObjectNode> it = csvMapper.readerFor(ObjectNode.class).with(bootstrapSchema) .readValues(entry.toFile()); long i = 0; while (it.hasNext()) { ObjectNode jsonNode = it.next(); String jsonString = mapper.writeValueAsString(jsonNode); String uri = entry.toUri().toString() + "-" + Long.toString(i++) + ".json"; DocumentMetadataHandle metadata = new DocumentMetadataHandle() // .withCollections("raw", "csv") // .withPermission("race-reader", Capability.READ) // .withPermission("race-writer", Capability.INSERT, Capability.UPDATE); batcher.add(uri, metadata, new StringHandle(jsonString)); if (i % 1000 == 0) logger.debug("Inserting JSON document " + uri); } it.close(); } } catch (IOException e) { e.printStackTrace(); } batcher.flush(); }
From source file:joachimeichborn.geotag.io.writer.kml.KmlWriter.java
/** * Create the output KML file containing: * <ul>/* w ww . j av a2 s.c o m*/ * <li>placemarks for all positions * <li>a path connecting all positions in chronological order * <li>circles showing the accuracy information for all positions * </ul> * * @throws IOException */ public void write(final Track aTrack, final Path aOutputFile) throws IOException { final String documentTitle = FilenameUtils.removeExtension(aOutputFile.getFileName().toString()); final GeoTagKml kml = createKml(documentTitle, aTrack); try (final Writer kmlWriter = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(aOutputFile.toFile())), StandardCharsets.UTF_8)) { kml.marshal(kmlWriter); } logger.fine("Wrote track to " + aOutputFile); }
From source file:com.yahoo.sql4d.indexeragent.sql.SqlFileSniffer.java
@Override public void onDelete(Path path) { String fileNameOnly = path.getFileName().toString().replaceAll(".sql", ""); DataSource existingDs = db().getDataSource(fileNameOnly); if (existingDs != null) { db().removeDataSource(existingDs); }// w w w . java 2s . com }
From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.UploadCommand.java
@Override @SuppressWarnings("unchecked") public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { List<FileItemStream> listFiles = (List<FileItemStream>) request .getAttribute(FileItemStream.class.getName()); List<FsItemEx> added = new ArrayList<FsItemEx>(); String target = request.getParameter("target"); FsItemEx dir = super.findItem(fsService, target); FsItemFilter filter = FsItemFilterUtils.createFilterFromRequest(request); for (FileItemStream fis : listFiles) { java.nio.file.Path p = java.nio.file.Paths.get(fis.getName()); FsItemEx newFile = new FsItemEx(dir, p.getFileName().toString()); newFile.createFile();//from w w w.j a v a2 s . c o m InputStream is = fis.openStream(); newFile.writeStream(is); if (filter.accepts(newFile)) added.add(newFile); } json.put("added", files2JsonArray(request, added)); }
From source file:ListFiles.java
@Override public FileVisitResult postVisitDirectory(Path directory, IOException e) throws IOException { indentionLevel -= indentionAmount;//from w ww .j ava2 s . c o m indent(); System.out.println("Finished with the directory: " + directory.getFileName()); return FileVisitResult.CONTINUE; }
From source file:fi.jumi.launcher.daemon.DirBasedStewardTest.java
@Test public void copies_the_embedded_daemon_JAR_to_the_settings_dir() throws IOException { Path daemonJar = steward.getDaemonJar(jumiHome); assertThat(daemonJar.getFileName().toString(), is(expectedName)); assertThat(FileUtils.readFileToByteArray(daemonJar.toFile()), is(expectedContent)); }
From source file:org.wte4j.examples.showcase.server.hsql.ShowCaseDbInitializerTest.java
private Set<String> listFiles(Path directory) throws IOException { Set<String> fileNamesInDirectory = new HashSet<String>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { for (Path path : directoryStream) { fileNamesInDirectory.add(path.getFileName().toString()); }// w ww. j ava 2s . c o m } return fileNamesInDirectory; }
From source file:com.devti.JavaXMPPBot.JavaXMPPBot.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { // Get paths// w ww.j a v a 2s . c o m String[] args = context.getArguments(); Path configsDir, logsDir; if (args.length > 0) { configsDir = Paths.get(args[0]); } else { configsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "conf.d"); } if (args.length > 1) { logsDir = Paths.get(args[1]); } else { logsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "log.d"); } if (!logsDir.toFile().exists()) { throw new DaemonInitException("Logs directory '" + logsDir + "' doesn't exist."); } // Get bot configs List<Path> botConfigs = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configsDir, "*.conf")) { for (Path entry : stream) { botConfigs.add(entry); } } catch (DirectoryIteratorException e) { throw new DaemonInitException( "Can't list configs directory '" + configsDir + "': " + e.getLocalizedMessage()); } if (botConfigs.size() <= 0) { throw new DaemonInitException("There is no .conf files in '" + configsDir + "' directory."); } // Load bots for (Path config : botConfigs) { String id = config.getFileName().toString().replaceFirst(".conf$", ""); Path log = Paths.get(logsDir.toString(), id + ".log"); try { bots.add(new XMPPBot(id, config, new Log(log))); } catch (Exception e) { throw new DaemonInitException( "Can't load a bot with config file '" + config + "': " + e.getLocalizedMessage()); } } }