List of usage examples for java.nio.file Path toString
String toString();
From source file:io.crate.testing.Utils.java
static void uncompressTarGZ(File tarFile, File dest) throws IOException { TarArchiveInputStream tarIn = new TarArchiveInputStream( new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tarFile)))); TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); // tarIn is a TarArchiveInputStream while (tarEntry != null) { Path entryPath = Paths.get(tarEntry.getName()); if (entryPath.getNameCount() == 1) { tarEntry = tarIn.getNextTarEntry(); continue; }// w ww. j a v a 2 s. co m Path strippedPath = entryPath.subpath(1, entryPath.getNameCount()); File destPath = new File(dest, strippedPath.toString()); if (tarEntry.isDirectory()) { destPath.mkdirs(); } else { destPath.createNewFile(); byte[] btoRead = new byte[1024]; BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath)); int len; while ((len = tarIn.read(btoRead)) != -1) { bout.write(btoRead, 0, len); } bout.close(); if (destPath.getParent().equals(dest.getPath() + "/bin")) { destPath.setExecutable(true); } } tarEntry = tarIn.getNextTarEntry(); } tarIn.close(); }
From source file:com.sonar.it.scanner.msbuild.TestUtils.java
public static Path getCustomRoslynPlugin() { Path customPluginDir = Paths.get("").resolve("analyzers"); DirectoryStream.Filter<Path> jarFilter = new DirectoryStream.Filter<Path>() { public boolean accept(Path file) throws IOException { return Files.isRegularFile(file) && file.toString().endsWith(".jar"); }/*from w w w .j a v a2s .co m*/ }; List<Path> jars = new ArrayList<>(); try { Files.newDirectoryStream(customPluginDir, jarFilter).forEach(p -> jars.add(p)); } catch (IOException e) { throw new IllegalStateException(e); } if (jars.isEmpty()) { throw new IllegalStateException("No jars found in " + customPluginDir.toString()); } else if (jars.size() > 1) { throw new IllegalStateException("Several jars found in " + customPluginDir.toString()); } return jars.get(0); }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java
public static void prepareInputOutput(Path in, Path out) throws IOException { if (!Files.exists(in)) throw new IOException(in.toString() + " does not exist. Ensure it exists and re-run this program."); Optional<Path> outPath = Optional.ofNullable(out.getParent()); outPath.ifPresent(p -> {/* ww w. j a v a 2s. c o m*/ if (!Files.exists(p)) { LOGGER.debug("Attempting to create output directory: {}", outPath.toString()); try { Files.createDirectories(p); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }
From source file:de.sanandrew.mods.turretmod.registry.assembly.TurretAssemblyRecipes.java
private static boolean processJson(Path file, Ex2Function<JsonObject, Boolean, JsonParseException, IOException> callback) { if (!"json".equals(FilenameUtils.getExtension(file.toString())) || FilenameUtils.getName(file.toString()).startsWith("_")) { return true; }/*w w w . j ava 2 s. c o m*/ try (BufferedReader reader = Files.newBufferedReader(file)) { JsonObject json = JsonUtils.fromJson(reader, JsonObject.class); if (json == null || json.isJsonNull()) { throw new JsonSyntaxException("Json cannot be null"); } callback.apply(json); return true; } catch (JsonParseException e) { TmrConstants.LOG.log(Level.ERROR, String.format("Parsing error loading assembly table recipe from %s", file), e); return false; } catch (IOException e) { TmrConstants.LOG.log(Level.ERROR, String.format("Couldn't read recipe from %s", file), e); return false; } }
From source file:ch.bender.evacuate.Testconstants.java
/** * Creates a new file with given name in given parent directory. * <p>// w w w . j a v a 2 s .c o m * The path of the new file is written into the file. * <p> * * @param aParent * must be an existing directory * @param aNewFileName * the name of the new file * @return the path object of the new file * @throws IOException */ public static Path createNewFile(Path aParent, String aNewFileName) throws IOException { if (!Files.isDirectory(aParent)) { throw new IllegalArgumentException("Given parent is not a directory or does not exist"); } Path file1 = Paths.get(aParent.toString(), aNewFileName); Files.createFile(file1); FileUtils.writeStringToFile(file1.toFile(), file1.toString() + "\n"); return file1; }
From source file:cc.kave.commons.externalserializationtests.ExternalTestCaseProvider.java
@Nonnull public static List<TestCase[]> getTestCases(Path baseDirectory) throws ClassNotFoundException, IOException { if (!baseDirectory.toFile().exists()) { return Lists.newLinkedList(); }//from w w w .j av a2s. c om return recursiveGetTestCases(baseDirectory.toFile(), baseDirectory.toString()); }
From source file:com.tripod.solr.util.EmbeddedSolrServerFactory.java
/** * @param solrHome the Solr home directory to use * @param configSetHome the directory containing config sets * @param coreName the name of the core, must have a matching directory in configHome * @param cleanSolrHome if true the directory for solrHome will be deleted and re-created if it already exists * @return an EmbeddedSolrServer with a core created for the given coreName *//*from w w w . j av a 2 s . com*/ public static SolrClient create(final String solrHome, final String configSetHome, final String coreName, final boolean cleanSolrHome) throws IOException, SolrServerException { final File solrHomeDir = new File(solrHome); if (solrHomeDir.exists()) { FileUtils.deleteDirectory(solrHomeDir); solrHomeDir.mkdirs(); } else { solrHomeDir.mkdirs(); } final SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toPath()); final Path configSetPath = Paths.get(configSetHome).toAbsolutePath(); final NodeConfig config = new NodeConfig.NodeConfigBuilder("embeddedSolrServerNode", loader) .setConfigSetBaseDirectory(configSetPath.toString()).build(); final EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(config, coreName); final CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); createRequest.setCoreName(coreName); createRequest.setConfigSet(coreName); embeddedSolrServer.request(createRequest); return embeddedSolrServer; }
From source file:com.ery.server.util.ToolUtil.java
public static String getPath(Path path) { try {/*from www.ja v a2 s .c o m*/ URI aUri = new URI(path.toString()); return aUri.getPath(); } catch (URISyntaxException e) { return path.toString(); } }
From source file:com.sldeditor.ui.detail.config.symboltype.externalgraphic.RelativePath.java
/** * Gets the relative path.// ww w.ja va 2s . c o m * * @param file the file * @param folder the folder * @return the relative path */ public static String getRelativePath(File file, File folder) { if (file == null) { return null; } if (folder == null) { return null; } Path filePath = Paths.get(file.getAbsolutePath()); Path folderPath = Paths.get(folder.getAbsolutePath()); Path path = null; try { path = folderPath.relativize(filePath); } catch (Exception e) { path = filePath; } return path.toString(); }
From source file:fi.johannes.kata.ocr.utils.files.CFileOperations.java
public static List<String> getFileContentAsStrings(Path f) throws IOException { FileReader fr = new FileReader(f.toString()); BufferedReader br = new BufferedReader(fr); List<String> res = getFileContentAsStrings(br); fr.close();/*from w w w .j av a2 s . co m*/ return res; }