List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:de.kaixo.mubi.lists.store.MubiListsToElasticSearchLoader.java
public void loadFromJson(Path path) { logger.info("Processing " + path.toString()); try {/*from ww w .ja v a 2 s .c o m*/ JsonNode node = mapper.readTree(path.toFile()); if (node.isArray()) { node.elements().forEachRemaining(elem -> { StringWriter writer = new StringWriter(); try { JsonGenerator generator = factory.createGenerator(writer); mapper.writeTree(generator, elem); client.prepareIndex(INDEX_NAME, TYPE).setSource(writer.toString()).get(); } catch (IOException e) { logger.error("Failed to write item", e); } }); } } catch (IOException e) { logger.error("Failed to process " + path.toString(), e); } }
From source file:com.collaide.fileuploader.models.GroupSync.java
private void addListeners(FilesSynchronization sync) { sync.addFileChangeListener(new FileMonitorAdapter(this) { @Override/*from w w w. j a v a 2 s . c o m*/ public void onChange(Path child) { logger.debug(child.toFile().getAbsoluteFile() + " is changed. Synchronizing"); synchronize(); if (this.isEventsMissed()) { synchronize(); } } }); }
From source file:de.doncarnage.minecraft.jailquarry.data.QuarryData.java
/** * Creates a {@link QuarryData} instance from the given file. * * @param file the file to be loaded/*from www .jav a 2 s .c o m*/ */ public QuarryData(Path file) { Validate.notNull(file, "File may not be null."); this.file = file; this.quarryData = YamlConfiguration.loadConfiguration(file.toFile()); quarries = new HashMap<>(); loadData(); }
From source file:io.fabric8.profiles.containers.wildfly.YamlTransformer.java
public YamlTransformer transform(Path path) throws IOException { try (FileInputStream input = new FileInputStream(path.toFile())) { return transform(input); }/*from w w w. j av a2 s . c o m*/ }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.LoadedDataset.java
private File[] getFiles(String aRole) { List<File> files = new ArrayList<>(); List<String> patterns = description.getRoles().get(aRole); if (patterns == null) { return new File[0]; }//from w w w . j a va 2 s. c o m for (String pattern : patterns) { Path baseDir = factory.resolve(description); Collection<File> matchedFiles = FileUtils.listFiles(baseDir.toFile(), new AntFileFilter(baseDir, asList(pattern), null), TrueFileFilter.TRUE); files.addAll(matchedFiles); } File[] all = files.toArray(new File[files.size()]); Arrays.sort(all, (File a, File b) -> { return a.getName().compareTo(b.getName()); }); return all; }
From source file:com.att.aro.core.settings.impl.JvmSettings.java
@Override public String getAttribute(String name) { if (!StringUtils.equals("Xmx", name)) { throw new IllegalArgumentException("Not a valid property:" + name); }//from ww w .j av a 2 s.c o m Path path = Paths.get(CONFIG_FILE_PATH); if (!path.toFile().exists()) { return DEFAULT_MEM; } try (Stream<String> lines = Files.lines(path)) { List<String> values = lines.filter((line) -> StringUtils.contains(line, name)) .collect(Collectors.toList()); if (values == null || values.isEmpty()) { LOGGER.error("No xmx entries on vm options file"); return DEFAULT_MEM; } else { return values.get(values.size() - 1).replace("-Xmx", "").replace("m", ""); } } catch (IOException e) { String message = "Counldn't read vm options file"; LOGGER.error(message, e); throw new ARORuntimeException(message, e); } }
From source file:com.yahoo.maven.visitor.SuccessfulCompilationAsserter.java
public void assertNoCompilationErrors() throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>(); try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, StandardCharsets.UTF_8)) { List<File> javaFiles = new ArrayList<>(); try (Stream<Path> stream = Files.walk(scratchSpace)) { Iterator<Path> iterator = stream.iterator(); while (iterator.hasNext()) { Path path = iterator.next(); if (Files.isRegularFile(path) && "java".equals(FilenameUtils.getExtension(path.toString()))) { javaFiles.add(path.toFile()); }//from w ww . j a va 2s.c o m } } Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromFiles(javaFiles); compiler.getTask(null, fileManager, diagnostics, Arrays.asList("-classpath", System.getProperty("java.class.path")), null, compilationUnits) .call(); } int errors = 0; for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) { if (Diagnostic.Kind.ERROR.equals(diagnostic.getKind())) { System.err.println(diagnostic); errors++; } } assertEquals(0, errors); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.fileManagement.FileUtility.java
public boolean destroyDir(@NotNull File path) throws IOException { Path directory = path.toPath(); @Getter/* www . j av a 2 s. c om*/ @Setter class BooleanWrapper { boolean deleted; } BooleanWrapper status = new BooleanWrapper(); Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { status.setDeleted(policy.delete(file.toFile())); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { status.setDeleted(policy.delete(dir.toFile())); return FileVisitResult.CONTINUE; } }); return status.isDeleted(); }
From source file:edu.usu.sdl.openstorefront.service.ReportServiceImpl.java
@Override public void deleteReport(String reportId) { Report existingReport = persistenceService.findById(Report.class, reportId); if (existingReport != null) { Path path = existingReport.pathToReport(); if (path != null) { if (path.toFile().exists()) { boolean success = path.toFile().delete(); if (success == false) { log.log(Level.WARNING, MessageFormat.format("Unable to remove old report: {0}", path.toString())); }/*from w ww. j av a 2 s . co m*/ } } persistenceService.delete(existingReport); } }
From source file:istata.web.HtmlController.java
@RequestMapping(value = { "/edit \"**", "/edit \"**/**" }) @ResponseBody//from ww w. jav a 2s . c om public String edit(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws IOException { String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); stataService.saveCmd(path); path = path.substring(7, path.length() - 1); Path dofile = Paths.get(path).toAbsolutePath(); if (dofile.toString().equals(path) && dofile.toFile().exists()) { model.put("content", stataService.loadDoFile(path).getContent()); model.put("title", path); return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "edit.vm", "UTF-8", model); } else { path = stataService.expandPath(path); dofile = Paths.get(path).toAbsolutePath(); if (dofile.toFile().exists()) { response.sendRedirect("/edit \"" + dofile.toAbsolutePath().toString() + "\""); return null; } else { // TODO maybe this can be done more graceful throw new NoSuchFileException(path); } } }