List of usage examples for java.nio.file Path toString
String toString();
From source file:org.apache.taverna.robundle.manifest.Manifest.java
protected static Path withSlash(Path dir) { if (dir == null) return null; if (isDirectory(dir)) { Path fname = dir.getFileName(); if (fname == null) return dir; String fnameStr = fname.toString(); if (fnameStr.endsWith("/")) return dir; return dir.resolveSibling(fnameStr + "/"); }// www . j a v a 2 s .c o m return dir; }
From source file:com.hubcap.inputs.CLIOptionBuilder.java
private static void buildAvailableOptions() { availableOptions = new Options(); Path p = Paths.get("resources/help", "help.txt"); String helpStr = "help is on the way...check the readme!"; if (helpContent == null) { try {//from ww w. j av a2 s .c o m helpContent = new String(Files.readAllBytes(p)); } catch (IOException ex) { helpContent = helpStr; System.err.println("Help File Couldn't be loaded! " + p.toString()); if (ProcessModel.instance().getVerbose()) ErrorUtils.printStackTrace(ex); } } availableOptions.addOption("h", "help", false, helpContent); availableOptions.addOption("v", "verbose", false, "Be verbose"); availableOptions.addOption("q", "quiet", false, "Be quiet (cancels verbose)"); availableOptions.addOption("r", "no-repl", false, "DONT fallback to repl mode"); availableOptions.addOption("f", "file", true, "Write results to this file (instead of the default)"); availableOptions.addOption("m", "mode", true, "Set the task mode, valid settings are 'search', 'deepsearch', 'watch', 'debug', default is 'search'"); Option property = Option.builder("D").hasArgs().valueSeparator('=').build(); availableOptions.addOption(property); }
From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java
private static void compressArchive(final Path pathToCompress, final ArchiveOutputStream archiveOutputStream, final ArchiveEntryFactory archiveEntryFactory, final CompressionType compressionType, final BuildListener listener) throws IOException { final List<File> files = addFilesToCompress(pathToCompress, listener); LoggingHelper.log(listener, "Compressing directory '%s' as a '%s' archive", pathToCompress.toString(), compressionType.name());// ww w . j av a 2 s . c o m for (final File file : files) { final String newTarFileName = pathToCompress.relativize(file.toPath()).toString(); final ArchiveEntry archiveEntry = archiveEntryFactory.create(file, newTarFileName); archiveOutputStream.putArchiveEntry(archiveEntry); try (final FileInputStream fileInputStream = new FileInputStream(file)) { IOUtils.copy(fileInputStream, archiveOutputStream); } archiveOutputStream.closeArchiveEntry(); } }
From source file:com.amazon.kinesis.streaming.agent.config.Configuration.java
/** * Build a configuration from a JSON file. * * @param file//from ww w.j a v a2 s .c o m * @return * @throws IOException */ public static Configuration get(Path file) throws IOException { try (InputStream is = new FileInputStream(file.toString())) { return get(is); } }
From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java
/** * Saves the instance identifier of this security server to file. * @param confPath path to the configuration * @param instanceIdentifier the instance identifier * @throws Exception if saving instance identifier fails *///from w w w .j a va 2s . c o m public static final void saveInstanceIdentifier(String confPath, String instanceIdentifier) throws Exception { Path file = Paths.get(confPath, INSTANCE_IDENTIFIER_FILE); log.trace("Saving instance identifier to {}", file); AtomicSave.execute(file.toString(), "inst", instanceIdentifier.getBytes(StandardCharsets.UTF_8)); }
From source file:codes.thischwa.c5c.UserObjectProxy.java
public static java.nio.file.Path removeExif(java.nio.file.Path tempPath) { if (exifRemover == null) return tempPath; try {/*w w w . ja v a 2 s .com*/ String fileName = tempPath.toString(); String ext = FilenameUtils.getExtension(fileName); java.nio.file.Path woExifPath = Paths.get(tempPath.toString() + "_woExif"); boolean removed = exifRemover.removeExif(Files.newInputStream(tempPath), Files.newOutputStream(woExifPath, StandardOpenOption.CREATE_NEW), ext); logger.debug("potential exif data removed: {}", removed); return (removed) ? woExifPath : tempPath; } catch (IOException e) { logger.warn("Error while removing EXIF data.", e); return tempPath; } }
From source file:Main.java
/** * Saves the object to the file./* w w w . jav a 2 s . c o m*/ * * @param <T> the object type. * @param path the XML file. * @param object the object to be saved. */ public static <T> void saveObject(Path path, T object) { if (path == null || object == null) { throw new RuntimeException("The path to file or object is null!"); } try { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(object, path.toFile()); } catch (Exception ex) { throw new RuntimeException("Error saving the object to path " + path.toString(), ex); } }
From source file:de.tuberlin.uebb.jbop.access.ClassAccessor.java
/** * Return the bytes of the corresponding class. * //from w ww.ja va2s. co m * @param input * the input Object (may be a class-Object) * @return the byte[] of the class * @throws JBOPClassException * if the Classfile for the given Object cannot be accessed * (e.g. if the class is synthetic) */ public static byte[] toBytes(final Object input) throws JBOPClassException { if (input == null) { throw new JBOPClassException("Nullvalue for input is not allowed.", null); } Path file; Class<?> clazz; if (input instanceof Class) { clazz = (Class<?>) input; } else { clazz = input.getClass(); } file = toPath(clazz); final String filename = file.toString(); if (StringUtils.contains(filename, "!")) { file = getPathInJar(filename); } try { return Files.readAllBytes(file); } catch (final IOException e) { throw new JBOPClassException("The content of the Classfile (" + filename + ") couldn't be read.", e); } }
From source file:lucene.IndexFiles.java
/** 135 * Indexes the given file using the given writer, or if a directory is given, 136 * recurses over files and directories found under the given directory. 137 * //from www. ja va 2 s. c om 138 * NOTE: This method indexes one document per input file. This is slow. For good 139 * throughput, put multiple documents into your input file(s). An example of this is 140 * in the benchmark module, which can create "line doc" files, one document per line, 141 * using the 142 * <a href="../../../../../contrib-benchmark/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.html" 143 * >WriteLineDocTask</a>. 144 * 145 * @param writer Writer to the index where the given file/dir info will be stored 146 * @param path The file to index, or the directory to recurse into to find files to index 147 * @throws IOException If there is a low-level I/O error 148 */ static void indexDocs(final IndexWriter writer, Path path) throws IOException { System.out.println("Test 2.1"); if (Files.isDirectory(path)) { System.out.println("Test 2.2"); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { try { System.out.println("Test 2.3"); System.out.println(file.toString()); indexDoc(writer, file, attrs.lastModifiedTime().toMillis()); System.out.println("Test 2.4"); } catch (IOException ignore) { // don't index files that can't be read. } return FileVisitResult.CONTINUE; } }); } else { indexDoc(writer, path, Files.getLastModifiedTime(path).toMillis()); } }
From source file:mv.Main.java
/** * Opens the ASM source code file and checks for any errors on it. * Returns false if the user did not specify a file path, if it doesn't exist or if it's empty * * @param asmFileString ASM source code filename /* www . java 2 s. c o m*/ * @return the success of the operation */ private static boolean setupProgramFile(String asmFileString) { boolean success = false; Path inFilePath; File asmFile; if (asmFileString != null) { try { inFilePath = Paths.get(asmFileString); asmFile = new File(inFilePath.toString()); if (Files.exists(inFilePath)) { if (asmFile.length() != 0) { success = true; } else { throw new EmptyFileException(asmFile); } } else { throw new FileNotFoundException(); } } catch (FileNotFoundException e) { System.err.println(ERR_ASM_NOT_FOUND); success = false; } catch (EmptyFileException e) { System.err.println(e.getMessage()); success = false; } } return success; }