List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.goldmansachs.kata2go.tools.utils.TarGz.java
public static void compress(Path sourceDirectoryPath, Path archiveFilePath) throws Exception { try {//from w ww.j a v a2 s .co m ImmutableList<String> tarArgs = Lists.immutable.of(UNIX_TAR, "cvzf", archiveFilePath.toFile().getAbsolutePath(), "."); Process process = new ProcessBuilder(tarArgs.toList()).directory(sourceDirectoryPath.toFile()).start(); int exitCode = process.waitFor(); if (exitCode != 0) { logStdout(process.getInputStream()); logStdErr(process.getErrorStream()); throw new Exception("Failed to compress"); } } catch (Exception e) { throw new Exception("Failed to compress", e); } }
From source file:de.monticore.io.paths.IterablePath.java
/** * Encapsulates creation of a {@link Stream} of {@link Path}s for a given start {@link Path}. * //ww w. j a va 2 s . co m * @param path * @return */ protected static Stream<Path> walkFileTree(Path path) { if (path.toFile().exists()) { try { return Files.walk(path); } catch (IOException e) { throw new RuntimeException(e); } } else { Log.warn("0xA4074 The supplied path " + path.toString() + " does not exist."); return Stream.empty(); } }
From source file:net.rptools.maptool.client.AppUtil.java
public static String readClientId() { Path clientFile = Paths.get(getAppHome().getAbsolutePath(), CLIENT_ID_FILE); String clientId = "unknown"; if (!clientFile.toFile().exists()) { clientId = UUID.randomUUID().toString(); try {// w w w .jav a2s . c om Files.write(clientFile, clientId.getBytes()); } catch (IOException e) { log.info("msg.error.unableToCreateClientIdFile", e); } } else { try { clientId = new String(Files.readAllBytes(clientFile)); } catch (IOException e) { log.info("msg.error.unableToReadClientIdFile", e); } } return clientId; }
From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java
private static void addPage(String urlPrefix, String imageDirectoryName, List<Canvas> canvases, int pageCounter, Path file) throws IOException, URISyntaxException { Path fileName = file.getFileName(); System.out.println(fileName.toAbsolutePath()); BufferedImage bimg = ImageIO.read(file.toFile()); int width = bimg.getWidth(); int height = bimg.getHeight(); // add a new page Canvas canvas1 = new Canvas(urlPrefix + imageDirectoryName + "/canvas/canvas-" + pageCounter, "p-" + pageCounter, height, width); canvases.add(canvas1);//w w w . j av a 2s .c om List<Image> images = new ArrayList<>(); canvas1.setImages(images); Image image1 = new Image(); image1.setOn(canvas1.getId()); images.add(image1); ImageResource imageResource1 = new ImageResource( urlPrefix + imageDirectoryName + "/" + fileName.toString()); imageResource1.setHeight(height); imageResource1.setWidth(width); image1.setResource(imageResource1); Service service1 = new Service(urlPrefix + imageDirectoryName + "/" + fileName.toString() + "?"); service1.setContext("http://iiif.io/api/image/2/context.json"); service1.setProfile("http://iiif.io/api/image/2/level1.json"); imageResource1.setService(service1); }
From source file:com.nwn.NwnFileHandler.java
/** * Get md5 value of given file/*from w ww . ja v a 2 s . co m*/ * @param file file to get md5 of * @return String representation of MD5 value */ public static String getMd5(Path file) { try { FileInputStream fis = new FileInputStream(file.toFile()); String md5 = DigestUtils.md5Hex(fis); fis.close(); return md5; } catch (IOException ex) { ex.printStackTrace(); } return ""; }
From source file:org.neo4j.ogm.auth.AuthenticationTest.java
@BeforeClass public static void setUp() throws Exception { Path authStore = Files.createTempFile("neo4j", "credentials"); authStore.toFile().deleteOnExit(); try (Writer authStoreWriter = new FileWriter(authStore.toFile())) { IOUtils.write(/*from ww w . j av a 2 s . co m*/ "neo4j:SHA-256,03C9C54BF6EEF1FF3DFEB75403401AA0EBA97860CAC187D6452A1FCF4C63353A,819BDB957119F8DFFF65604C92980A91:", authStoreWriter); } neoPort = TestUtils.getAvailablePort(); try { ServerControls controls = TestServerBuilders.newInProcessBuilder() .withConfig("dbms.security.auth_enabled", "true") .withConfig("org.neo4j.server.webserver.port", String.valueOf(neoPort)) .withConfig("dbms.security.auth_store.location", authStore.toAbsolutePath().toString()) .newServer(); initialise(controls); } catch (Exception e) { throw new RuntimeException("Error starting in-process server", e); } }
From source file:Main.java
public static Document DocumentFactory(Path xmlfile) { //get document object of the xml file DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); Document document = null;/*from ww w. j a va 2 s. c o m*/ try { DocumentBuilder builder = builderFactory.newDocumentBuilder(); document = builder.parse(xmlfile.toFile()); } catch (ParserConfigurationException e) { log.error("DOM parser configuration exception"); e.printStackTrace(); } catch (SAXException e) { log.error("DOM parse error"); e.printStackTrace(); } catch (IOException e) { log.error("IO exception"); e.printStackTrace(); } return document; }
From source file:com.joyent.manta.client.MantaClientAuthenticationChangeIT.java
private static void swapKeyLocation(final AuthAwareConfigContext config, final boolean fromPathToContent) throws IOException { if (fromPathToContent) { // move key to MANTA_KEY_CONTENT final String keyContent = FileUtils.readFileToString(new File(config.getMantaKeyPath()), StandardCharsets.UTF_8); config.setMantaKeyPath(null);//from w ww . j a va 2 s .c o m config.setPrivateKeyContent(keyContent); return; } // move key to MANTA_KEY_FILE final Path tempKey = Paths.get("/Users/tomascelaya/sandbox/"); FileUtils.forceDeleteOnExit(tempKey.toFile()); FileUtils.writeStringToFile(tempKey.toFile(), config.getPrivateKeyContent(), StandardCharsets.UTF_8); config.setPrivateKeyContent(null); config.setMantaKeyPath(tempKey.toString()); }
From source file:com.excelsiorjet.api.util.Utils.java
public static void copyFile(Path source, Path target) throws IOException { if (!target.toFile().exists()) { Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES); } else if (source.toFile().lastModified() != target.toFile().lastModified()) { //copy only files that were changed Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); }// ww w . j a v a2 s. c o m }
From source file:net.sf.jabref.collab.FileUpdateMonitor.java
private static synchronized Path getTempFile() { Path temporaryFile = null; try {/*from w ww . j av a2 s .c o m*/ temporaryFile = Files.createTempFile("jabref", null); temporaryFile.toFile().deleteOnExit(); } catch (IOException ex) { LOGGER.warn("Could not create temporary file.", ex); } return temporaryFile; }