List of usage examples for java.io File toPath
public Path toPath()
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME/PERMANENT for the provided dem. * * The dem is staged in GISBASE/dem.tif and then moved to * GISBASE/LOCATION_NAME/PERMANENT/dem.tif * * @param operation//from w w w . j av a 2 s . c om * Name used for the location on disk * @param dem * File used to establish CRS and Bounds for the location * @return Array of files consisting of {GISBASE, LOCATION, MAPSET, dem.tif} * @throws Exception */ static File[] location(String operation, GridCoverage2D dem) throws Exception { File geodb = new File(System.getProperty("user.home"), "grassdata"); //File location = Files.createTempDirectory(geodb.toPath(),operation).toFile(); File location = new File(geodb, operation); File mapset = new File(location, "PERMANENT"); File file = new File(geodb, "dem.tif"); final GeoTiffFormat format = new GeoTiffFormat(); GridCoverageWriter writer = format.getWriter(file); writer.write(dem, null); System.out.println("Staging file:" + file); // grass70 + ' -c ' + myfile + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("${file}"); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(new KVP("file", file, "location", location)); LOGGER.info(cmd.toString()); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); executor.setWatchdog(watchdog); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); File origional = file; file = new File(mapset, file.getName()); Files.move(origional.toPath(), file.toPath()); return new File[] { geodb, location, mapset, file }; }
From source file:de.flashpixx.rrd_antlr4.CMain.java
/** * returns a list of grammar files/*from www . ja v a 2 s .c om*/ * * @param p_input grammar file or directory with grammar files * @param p_import imported files * @param p_exclude file names which are ignored * @return stream of file objects */ private static Stream<File> filelist(final File p_input, final Set<File> p_import, final Set<String> p_exclude) { if (!p_input.exists()) throw new RuntimeException(CCommon.languagestring(CMain.class, "notexist", p_input)); try { return (p_input.isFile() ? Stream.of(p_input) : Files.find(p_input.toPath(), Integer.MAX_VALUE, (i, j) -> (j.isRegularFile()) && (!j.isSymbolicLink())).map(Path::toFile)) .filter(i -> i.getName().endsWith(GRAMMARFILEEXTENSION)) .filter(i -> !p_import.contains(i)) .filter(i -> !p_exclude.contains(i.getName())); } catch (final IOException l_exception) { throw new RuntimeException(l_exception); } }
From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java
private static Example loadExample(String path, String parentUrl, boolean loadTestVersion, List<ObjectNode> commonFilesManifests) throws IOException { File manifestFile = new File(path + File.separator + "manifest.json"); try (BufferedInputStream reader = new BufferedInputStream(new FileInputStream(manifestFile))) { ObjectNode manifest = (ObjectNode) JsonUtils.getObjectMapper().readTree(reader); String name = new File(path).getName(); String id = (parentUrl + name).replaceAll(" ", "%20"); String args = manifest.has("args") ? manifest.get("args").asText() : ""; String runConfiguration = manifest.get("confType").asText(); boolean searchForMain = manifest.has("searchForMain") ? manifest.get("searchForMain").asBoolean() : true;/*from w w w. ja v a 2 s. co m*/ String expectedOutput; List<String> readOnlyFileNames = new ArrayList<>(); List<ProjectFile> files = new ArrayList<>(); List<ProjectFile> hiddenFiles = new ArrayList<>(); if (manifest.has("expectedOutput")) { expectedOutput = manifest.get("expectedOutput").asText(); } else if (manifest.has("expectedOutputFile")) { Path expectedOutputFilePath = Paths .get(path + File.separator + manifest.get("expectedOutputFile").asText()); expectedOutput = new String(Files.readAllBytes(expectedOutputFilePath)); } else { expectedOutput = null; } String help = null; File helpFile = new File(path + File.separator + "task.md"); if (helpFile.exists()) { PegDownProcessor processor = new PegDownProcessor(org.pegdown.Extensions.FENCED_CODE_BLOCKS); String helpInMarkdown = new String(Files.readAllBytes(helpFile.toPath())); help = new GFMNodeSerializer().toHtml(processor.parseMarkdown(helpInMarkdown.toCharArray())); } List<JsonNode> fileManifests = new ArrayList<JsonNode>(); if (manifest.has("files")) { for (JsonNode fileManifest : manifest.get("files")) { fileManifests.add(fileManifest); } } fileManifests.addAll(commonFilesManifests); for (JsonNode fileDescriptor : fileManifests) { if (loadTestVersion && fileDescriptor.has("skipInTestVersion") && fileDescriptor.get("skipInTestVersion").asBoolean()) { continue; } String filePath = fileDescriptor.has("path") ? fileDescriptor.get("path").asText() : path + File.separator + fileDescriptor.get("filename").textValue(); ExampleFile file = loadExampleFile(filePath, id, fileDescriptor); if (!loadTestVersion && file.getType().equals(ProjectFile.Type.SOLUTION_FILE)) { continue; } if (!file.isModifiable()) { readOnlyFileNames.add(file.getName()); } if (file.isHidden()) { hiddenFiles.add(file); } else { files.add(file); } } loadDefaultFiles(path, id, files, loadTestVersion); return new Example(id, name, args, runConfiguration, id, expectedOutput, searchForMain, files, hiddenFiles, readOnlyFileNames, help); } catch (IOException e) { System.err.println("Can't load project: " + e.toString()); return null; } }
From source file:io.werval.cli.DamnSmallDevShell.java
private static File createClassesDirectory(boolean debug, File tmpDir) throws IOException { final File classesDir = new File(tmpDir, "classes"); Files.createDirectories(classesDir.toPath()); if (debug) {/*from w ww. j a v a 2 s . c o m*/ System.out.println("Classes directory is: " + classesDir.getAbsolutePath()); } return classesDir; }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME for the provided dem. * * @param operation Name used for the location on disk * @param dem File used to establish CRS and Bounds for the location * @return//from w ww . j a v a 2s .co m * @throws Exception */ static File location(CoordinateReferenceSystem crs) throws Exception { String code = CRS.toSRS(crs, true); File geodb = new File(System.getProperty("user.home"), "grassdata"); File location = Files.createTempDirectory(geodb.toPath(), code).toFile(); KVP kvp = new KVP("geodb", geodb, "location", location); // grass70 + ' -c epsg:' + myepsg + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("epsg:" + code); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(kvp); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.setWatchdog(new ExecuteWatchdog(60000)); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); return location; }
From source file:de.cebitec.readXplorer.util.GeneralUtils.java
/** * Deletes the given file and if existent also the corresponding ".bai" * index file./*from w w w.j a v a 2 s. c o m*/ * @param lastWorkFile the file to delete * @return true, if the file could be deleted, false otherwise * @throws IOException */ public static boolean deleteOldWorkFile(File lastWorkFile) throws IOException { boolean deleted = false; if (lastWorkFile.canWrite()) { try { Files.delete(lastWorkFile.toPath()); deleted = true; File indexFile = new File(lastWorkFile.getAbsolutePath().concat(Properties.BAM_INDEX_EXT)); if (indexFile.canWrite()) { Files.delete(indexFile.toPath()); } } catch (IOException ex) { throw new IOException(NbBundle.getMessage(GeneralUtils.class, "MSG_GeneralUtils.FileDeletionError", lastWorkFile.getAbsolutePath())); } } return deleted; }
From source file:org.lightcouch.CouchDbUtil.java
/** * List directory contents for a resource folder. Not recursive. This is * basically a brute-force implementation. Works for regular files and also * JARs./*from w ww . j av a 2s . co m*/ * * @author Greg Briggs * @param clazz * Any java class that lives in the same place as the resources * you want. * @param path * Should end with "/", but not start with one. * @return Just the name of each member item, not the full paths. */ public static List<String> listResources(String path) { String fileURL = null; try { URL entry = Platform.getBundle("org.lightcouch").getEntry(path); File file = null; if (entry != null) { fileURL = FileLocator.toFileURL(entry).getPath(); // remove leading slash from absolute path when on windows if (OSValidator.isWindows()) fileURL = fileURL.substring(1, fileURL.length()); file = new File(fileURL); } URL dirURL = file.toPath().toUri().toURL(); if (dirURL != null && dirURL.getProtocol().equals("file")) { return Arrays.asList(new File(dirURL.toURI()).list()); } if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); Enumeration<JarEntry> entries = jar.entries(); Set<String> result = new HashSet<String>(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.startsWith(path)) { String entry1 = name.substring(path.length()); int checkSubdir = entry1.indexOf("/"); if (checkSubdir >= 0) { entry1 = entry1.substring(0, checkSubdir); } if (entry1.length() > 0) { result.add(entry1); } } } return new ArrayList<String>(result); } return null; } catch (Exception e) { throw new CouchDbException("fileURL: " + fileURL, e); } }
From source file:de.blizzy.backup.Utils.java
public static void zipFile(File source, File target) throws IOException { ZipOutputStream out = null;// w w w . j a v a 2 s.c om try { out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target))); out.setLevel(Deflater.BEST_COMPRESSION); ZipEntry entry = new ZipEntry(source.getName()); entry.setTime(source.lastModified()); out.putNextEntry(entry); Files.copy(source.toPath(), out); } finally { IOUtils.closeQuietly(out); } }
From source file:io.werval.cli.DamnSmallDevShell.java
private static void cleanCommand(boolean debug, File tmpDir) { try {//from ww w . ja va2 s .co m // Clean if (tmpDir.exists()) { Files.walkFileTree(tmpDir.toPath(), new DeltreeFileVisitor()); } // Inform user System.out.println( "Temporary files " + (debug ? "in '" + tmpDir.getAbsolutePath() + "' " : "") + "deleted."); } catch (IOException ex) { ex.printStackTrace(System.err); } }
From source file:it.uniud.ailab.dcore.launchers.Launcher.java
/** * Distill the content of a file.// w w w . j a v a 2s .c o m * * @param filePath the file to analyze. * * @throws IOException if there's an error reading the file. */ private static void analyzeFile(File filePath) throws IOException { setupDistiller(); String fileName = filePath.toPath().getFileName().toString(); IOBlackboard.setCurrentDocument(filePath.getAbsolutePath()); String document = loadDocument(filePath); IOBlackboard.setOutputPathPrefix(outputPath.getAbsolutePath() + FileSystem.getSeparator() + fileName); distiller.distill(document); }