List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:org.n52.oss.util.Util.java
public static String readResourceFile(Path p) { log.debug("Reading {}", p); StringBuilder sb = new StringBuilder(); try (Reader reader = new FileReader(p.toFile());) { int data = reader.read(); while (data != -1) { char dataChar = (char) data; sb.append(dataChar);//from w w w.j ava 2 s .c o m data = reader.read(); } reader.close(); } catch (IOException e) { log.error("Could not read from file " + p, e); } return sb.toString(); }
From source file:io.seqware.pipeline.whitestar.WhiteStarTest.java
protected static Path createSettingsFile(String engine, String metadataMethod) throws IOException { // override seqware settings file List<String> whiteStarProperties = new ArrayList<>(); whiteStarProperties.add("SW_METADATA_METHOD=" + metadataMethod); whiteStarProperties.add("SW_REST_USER=admin@admin.com"); whiteStarProperties.add("SW_REST_PASS=admin"); whiteStarProperties.add("SW_ADMIN_REST_URL=fubar"); whiteStarProperties.add("SW_DEFAULT_WORKFLOW_ENGINE=" + engine); whiteStarProperties.add("OOZIE_WORK_DIR=/tmp"); // use this if running locally via mvn tomcat7:run // whiteStarProperties.add("SW_REST_URL=http://localhost:8889/seqware-webservice"); // use this in our regression testing framework whiteStarProperties.add("SW_REST_URL=http://master:8080/SeqWareWebService"); Path createTempFile = Files.createTempFile("whitestar", "properties"); FileUtils.writeLines(createTempFile.toFile(), whiteStarProperties); return createTempFile; }
From source file:com.serli.open.data.poitiers.jobs.importer.ImportAllDataJobTest.java
public static void createDevNode() { LOGGER.info("Creating dev ES node ..."); Path localDevDataDirectory = Paths.get(ES_LOCAL_DATA); try {//from w ww . j a v a 2s . com FileUtils.deleteDirectory(localDevDataDirectory.toFile()); } catch (IOException e) { throw new RuntimeException(e); } Settings settings = ImmutableSettings.builder().put("http.port", "9200").put("network.host", "localhost") .put("path.data", ES_LOCAL_DATA).build(); Node node = NodeBuilder.nodeBuilder().local(true).data(true) .clusterName("elasticSearch" + UUID.randomUUID()).settings(settings).build(); node.start(); // loading settings run(ReloadDefaultSettings.class); ImportAllDataJob.elasticType = "test-ES"; ImportAllDataJob.filename = "conf/test-ES.properties"; run(ImportAllDataJob.class); }
From source file:net.sf.jabref.logic.exporter.FileSaveSession.java
private static VerifyingWriter getWriterForFile(Charset encoding, Path file) throws SaveException { try {// w ww. ja v a 2s . c om return new VerifyingWriter(new FileOutputStream(file.toFile()), encoding); } catch (FileNotFoundException e) { throw new SaveException(e); } }
From source file:com.swingtech.apps.filemgmt.util.MimeTypeUtils.java
public static String probeContentType(Path file) throws IOException { String mimetype = Files.probeContentType(file); if (mimetype != null) return mimetype; mimetype = tika.detect(file.toFile()); if (mimetype != null) return mimetype; return getMimeType(FilenameUtils.getExtension(String.valueOf(file.getFileName()))); }
From source file:io.yields.math.framework.kpi.ScoreDAO.java
private static ScoreResult fromFile(Path file) { ObjectMapper jsonMapper = getObjectMapper(); try {/*from ww w . j a v a2 s.c o m*/ return jsonMapper.readValue(file.toFile(), ScoreResult.class); } catch (IOException ioe) { throw new RuntimeException("Error reading yields KPI file from " + file, ioe); } }
From source file:com.geewhiz.pacify.model.utils.ModelUtils.java
public static PFile clonePFile(PFile cloneFrom, Path file) { String relativePath = FilenameUtils .separatorsToUnix(cloneFrom.getPMarker().getFolder().toPath().relativize(file).toString()); return clonePFile(cloneFrom, relativePath, file.toFile()); }
From source file:io.hightide.TemplateFetcher.java
public static Path extractTemplate(Path tempFile, Path targetDir) throws IOException { try (FileInputStream fin = new FileInputStream(tempFile.toFile()); BufferedInputStream in = new BufferedInputStream(fin); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn)) { TarArchiveEntry entry;/*w ww. j a v a 2 s . c om*/ Path rootDir = null; while ((entry = (TarArchiveEntry) tarIn.getNextEntry()) != null) { System.out.println("Extracting: " + entry.getName()); if (entry.isDirectory()) { if (isNull(rootDir)) { rootDir = targetDir.resolve(entry.getName()); } Files.createDirectory(targetDir.resolve(entry.getName())); } else { int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(targetDir.resolve(entry.getName()).toFile()); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); while ((count = tarIn.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.close(); } } return rootDir; } }
From source file:fr.cnrs.sharp.reasoning.Interlinking.java
/** * Generates a Jena Model with an SHA-512 fingerprint of a file content. * @param inputRawFile the file to be fingerprinted * @return a Jena Model with an SHA-512, based on PROV and tavernaprov vocabularies. * @throws IOException//from w ww . j av a2 s .c om */ public static Model fingerprint(Path inputRawFile) throws IOException { StopWatch sw = new StopWatch(); sw.start(); Model data = ModelFactory.createDefaultModel(); Path p = inputRawFile; String label = p.getFileName().toString(); System.out.println(); FileInputStream fis = new FileInputStream(p.toFile()); String sha512 = DigestUtils.sha512Hex(fis); StringBuffer sb = new StringBuffer(); sb.append("@base <http://fr.symetric> .\n" + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" + "@prefix prov: <http://www.w3.org/ns/prov#> .\n" + "@prefix tavernaprov: <http://ns.taverna.org.uk/2012/tavernaprov/> .\n" + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"); sb.append("<#" + UUID.randomUUID().toString() + ">\n" + "\t a prov:Entity ;\n"); sb.append("\t rdfs:label \"" + label + "\"^^xsd:String ;\n"); sb.append("\t tavernaprov:sha512 \"" + sha512 + "\"^^xsd:String ."); RDFDataMgr.read(data, new StringReader(sb.toString()), null, Lang.TTL); fis.close(); return data; }
From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java
public static List<File> getGnosKeys(BaseConfiguration config) { List<File> gnosKeys = new ArrayList(); Path dir = Paths.get(config.getString("gnosKeys")); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path item : stream) { File file = item.toFile(); if (file.isFile() && !file.isHidden()) { gnosKeys.add(file);/* w w w . j a va2s .com*/ } } } catch (IOException | DirectoryIteratorException e) { throw new RuntimeException(e.getMessage(), e); } return gnosKeys; }