List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceTDB.java
public RDFServiceTDB(String directoryPath) throws IOException { Path tdbDir = Paths.get(directoryPath); if (!Files.exists(tdbDir)) { Path parentDir = tdbDir.getParent(); if (!Files.exists(parentDir)) { throw new IllegalArgumentException( "Cannot create TDB directory '" + tdbDir + "': parent directory does not exist."); }/* w w w .j a va2 s . c o m*/ Files.createDirectory(tdbDir); } this.dataset = TDBFactory.createDataset(directoryPath); }
From source file:io.github.lxgaming.mcc.Configuration.java
public static void saveConfig(String comment) { try {/*from w ww . j av a 2 s . c om*/ Files.write(Paths.get(CONFIGFILE.getPath()), new JSONObject().put("Email", EMAIL).put("ClientToken", CLIENTTOKEN) .put("AccessToken", ACCESSTOKEN).put("ConnectMessage", CONNECTMESSAGE) .put("CommandPrefix", COMMANDPREFIX).put("FontName", FONTNAME).put("FontSize", FONTSIZE) .put("Theme", THEME).toString().getBytes()); LogManager.info("Configuration File Successfully Saved - " + comment + "."); } catch (Exception ex) { LogManager.error("Configuration File Failed to Save - " + comment + "."); } return; }
From source file:its.tools.SonarlintProject.java
/** * Copies project to a temporary location and returns its root path. *//*w ww . j a v a 2 s .c o m*/ public Path deployProject(String location) throws IOException { Path originalLoc = Paths.get("projects").resolve(location); String projectName = originalLoc.getFileName().toString(); if (!Files.isDirectory(originalLoc)) { throw new IllegalArgumentException( "Couldn't find project directory: " + originalLoc.toAbsolutePath().toString()); } cleanProject(); project = Files.createTempDirectory(projectName); FileUtils.copyDirectory(originalLoc.toFile(), project.toFile()); return project; }
From source file:com.eviware.soapui.Util.SoapUITools.java
public static Path soapuiHomeDir() { String homePath = System.getProperty("soapui.home"); if (homePath == null) { File homeFile = new File("."); log.warn("System property 'soapui.home' is not set! Using this directory instead: {}", homeFile); return homeFile.toPath(); }/*from www . ja v a 2 s.c om*/ return ensureExists(Paths.get(homePath)); }
From source file:org.gyt.schema.json.Utils.java
public static String readFile(String path, Charset encoding) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, encoding); }
From source file:fr.logfiletoes.Config.java
/** * Construct config from json file path/*from w w w . j a v a 2 s .c o m*/ * @param filepath json config file path * @throws IOException */ public Config(String filepath) throws IOException { String json = new String(Files.readAllBytes(Paths.get(filepath))); JSONTokener jsont = new JSONTokener(json); JSONObject config = (JSONObject) jsont.nextValue(); JSONArray unitsJSON = config.getJSONArray("unit"); LOG.fine(unitsJSON.length() + " unit(s)"); for (int i = 0; i < unitsJSON.length(); i++) { JSONObject unitFormJson = unitsJSON.getJSONObject(i); Unit unit = createUnit(unitFormJson); if (unit != null) { this.units.add(unit); } else { LOG.warning("unit skip : " + unitFormJson.toString()); } } }
From source file:com.twosigma.beakerx.kernel.PathToJar.java
public PathToJar(final String path) { checkNotNull(path);/*from w w w .j a v a2 s . c om*/ File file = getFile(path); try { canonicalPath = file.getCanonicalPath(); this.url = Paths.get(canonicalPath).toUri().toURL(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:audiomanagershell.commands.InfoCommand.java
@Override public void execute() throws CommandException { String OS = System.getProperty("os.name").toLowerCase(); Path file;/*from w ww.j av a2 s. c om*/ if (OS.equals("windows")) file = Paths.get(this.pathRef.toString() + "\\" + this.arg); else file = Paths.get(this.pathRef.toString() + "/" + this.arg); String fileName = file.getFileName().toString(); List<String> acceptedExtensions = Arrays.asList("wav", "mp3", "flac"); List<String> infoWanted = Arrays.asList("title", "xmpDM:artist", "xmpDM:genre", "xmpDM:album", "xmpDM:releaseDate"); if (!Files.exists(file)) throw new FileNotFoundException(file.getFileName().toString()); if (Files.isRegularFile(file)) { //Get the extension of the file String extension = FilenameUtils.getExtension(fileName); if (acceptedExtensions.contains(extension)) { try { FileInputStream input = new FileInputStream(file.toFile()); Metadata metadata = new Metadata(); BodyContentHandler handler = new BodyContentHandler(); ParseContext pcontext = new ParseContext(); //MP3 Parser Mp3Parser AudioParser = new Mp3Parser(); AudioParser.parse(input, handler, metadata, pcontext); for (String name : infoWanted) { String[] metadataName = name.split(":"); if (metadata.get(name) != null) if (name.equals("title")) System.out.println("TITLE:" + metadata.get(name)); else System.out.println(metadataName[1].toUpperCase() + ":" + metadata.get(name)); } input.close(); } catch (IOException | TikaException | SAXException e) { e.printStackTrace(); } } else { throw new NotAudioFileException(fileName); } } else throw new NotAFileException(file.getFileName().toString()); }
From source file:dyco4j.instrumentation.entry.CLI.java
private static void processCommandLine(final CommandLine cmdLine) throws IOException { final Path _srcRoot = Paths.get(cmdLine.getOptionValue(IN_FOLDER_OPTION)); final Path _trgRoot = Paths.get(cmdLine.getOptionValue(OUT_FOLDER_OPTION)); final Predicate<Path> _nonClassFileSelector = p -> !p.toString().endsWith(".class") && Files.isRegularFile(p); final BiConsumer<Path, Path> _fileCopier = (srcPath, trgPath) -> { try {// w w w.j a va2s . c o m Files.copy(srcPath, trgPath); } catch (final IOException _ex) { throw new RuntimeException(_ex); } }; processFiles(_srcRoot, _trgRoot, _nonClassFileSelector, _fileCopier); final Predicate<Path> _classFileSelector = p -> p.toString().endsWith(".class"); final String _methodNameRegex = cmdLine.getOptionValue(METHOD_NAME_REGEX_OPTION, METHOD_NAME_REGEX); final Boolean _onlyAnnotatedTests = cmdLine.hasOption(ONLY_ANNOTATED_TESTS_OPTION); final BiConsumer<Path, Path> _classInstrumenter = (srcPath, trgPath) -> { try { final byte[] _bytecode = Files.readAllBytes(srcPath); final ClassReader _cr = new ClassReader(_bytecode); final ClassWriter _cw = new ClassWriter(_cr, ClassWriter.COMPUTE_MAXS); final ClassVisitor _cv1 = new LoggerInitializingClassVisitor(CLI.ASM_VERSION, _cw); final ClassVisitor _cv2 = new TracingClassVisitor(_cv1, _methodNameRegex, _onlyAnnotatedTests); _cr.accept(_cv2, 0); final byte[] _out = _cw.toByteArray(); Files.write(trgPath, _out); } catch (final IOException _ex) { throw new RuntimeException(_ex); } }; processFiles(_srcRoot, _trgRoot, _classFileSelector, _classInstrumenter); }
From source file:com.github.tteofili.p2h.DataSplitTest.java
@Ignore @Test// w ww . java 2s .c om public void testDataSplit() throws Exception { String regex = "\\n\\d(\\.\\d)*\\.?\\u0020[\\w|\\-|\\|\\:]+(\\u0020[\\w|\\-|\\:|\\]+){0,10}\\n"; String prefix = "/path/to/h2v/"; Pattern pattern = Pattern.compile(regex); Path path = Paths.get(getClass().getResource("/papers/raw/").getFile()); File file = path.toFile(); if (file.exists() && file.list() != null) { for (File doc : file.listFiles()) { String s = IOUtils.toString(new FileInputStream(doc)); String docName = doc.getName(); File fileDir = new File(prefix + docName); assert fileDir.mkdir(); Matcher matcher = pattern.matcher(s); int start = 0; String sectionName = "abstract"; while (matcher.find(start)) { String string = matcher.group(0); if (isValid(string)) { String content; if (start == 0) { // abstract content = s.substring(0, matcher.start()); } else { content = s.substring(start, matcher.start()); } File f = new File(prefix + docName + "/" + docName + "_" + sectionName); assert f.createNewFile() : "could not create file" + f.getAbsolutePath(); FileOutputStream outputStream = new FileOutputStream(f); IOUtils.write(content, outputStream); start = matcher.end(); sectionName = string.replaceAll("\n", "").trim(); } else { start = matcher.end(); } } // remaining File f = new File(prefix + docName + "/" + docName + "_" + sectionName); assert f.createNewFile(); FileOutputStream outputStream = new FileOutputStream(f); IOUtils.write(s.substring(start), outputStream); } } }