List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:jsonbrowse.JsonBrowse.java
@Override public void run() { try {//from ww w. j a va2s . c o m WatchKey key = watcher.take(); while (key != null) { if (watching) { for (WatchEvent event : key.pollEvents()) { if (event.context() instanceof Path) { Path path = (Path) (event.context()); if (path.getFileName().equals(jsonFilePath.getFileName())) { if (path.toFile().length() > 0) updateModel(); } } } } key.reset(); key = watcher.take(); } } catch (InterruptedException | IOException ex) { Logger.getLogger(JsonBrowse.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Stopping thread."); }
From source file:io.cloudslang.lang.tools.build.ArgumentProcessorUtilsTest.java
@Test public void testGetPropertiesFromFileThrowsException() throws URISyntaxException, IOException { InputStream fis = null;//from w w w . j a v a 2 s .co m Writer outputWriter = null; File tempRunConfigFile = null; try { fis = new FileInputStream( new File(getResource("lang/tools/build/builder_run_configuration.properties").toURI())); Path tempRunConfig = Files.createTempFile("temp_run_config", ".properties"); tempRunConfigFile = tempRunConfig.toFile(); outputWriter = new PrintWriter(new FileWriter(tempRunConfigFile)); IOUtils.copy(fis, outputWriter); outputWriter.flush(); String absolutePath = tempRunConfigFile.getAbsolutePath(); Properties propertiesFromFile = getPropertiesFromFile(absolutePath); assertEquals("false", propertiesFromFile.get(TEST_COVERAGE)); assertEquals("sequential", propertiesFromFile.get(TEST_SUITES_RUN_UNSPECIFIED)); assertEquals("!default,vmware-local,xml-local,images", propertiesFromFile.get(TEST_SUITES_TO_RUN)); assertEquals("images", propertiesFromFile.get(TEST_SUITES_SEQUENTIAL)); assertEquals("xml-local,vmware-local", propertiesFromFile.get(TEST_SUITES_PARALLEL)); assertEquals("8", propertiesFromFile.get(TEST_PARALLEL_THREAD_COUNT)); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(outputWriter); FileUtils.deleteQuietly(tempRunConfigFile); } }
From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java
private TiffOutputSet getOutputSet(final Path aFile) throws ImageReadException, IOException, ImageWriteException { final ImageMetadata metadata = Imaging.getMetadata(aFile.toFile()); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (null != jpegMetadata) { final TiffImageMetadata exif = jpegMetadata.getExif(); if (exif != null) { return exif.getOutputSet(); }// ww w . j ava 2 s . c o m } return new TiffOutputSet(); }
From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java
private PhotoshopApp13Data getPhotoshopMetadata(final Path aFile) throws ImageReadException, IOException, ImageWriteException { final ImageMetadata metadata = Imaging.getMetadata(aFile.toFile()); final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata; if (jpegMetadata != null) { final JpegPhotoshopMetadata photoshopMetadata = jpegMetadata.getPhotoshop(); if (photoshopMetadata != null) { return photoshopMetadata.photoshopApp13Data; }//from w w w.java2 s .c o m } return null; }
From source file:business.services.FileService.java
public boolean checkUploadPath() { Path path = fileSystem.getPath(uploadPath).normalize(); java.io.File f = path.toFile(); if (f.exists() && f.isDirectory() && f.canWrite()) { return true; }/*from w w w .j a v a2 s . com*/ return false; }
From source file:com.dickthedeployer.dick.web.service.CommandService.java
public String invoke(Path workingDir, String... command) throws RuntimeException { try {/*from ww w.j a va 2s . com*/ log.info("Executing command {} in path {}", Arrays.toString(command), workingDir.toString()); StringBuilder text = new StringBuilder(); ProcessBuilder builder = new ProcessBuilder(command); builder.directory(workingDir.toFile()); builder.redirectErrorStream(true); Process process = builder.start(); try (Scanner s = new Scanner(process.getInputStream())) { while (s.hasNextLine()) { text.append(s.nextLine()); } int result = process.waitFor(); log.info("Process exited with result {} and output {}", result, text); if (result != 0) { throw new CommandExecutionException(); } return text.toString(); } } catch (IOException | InterruptedException ex) { throw new CommandExecutionException(ex); } }
From source file:dpfmanager.shell.modules.client.core.ClientService.java
private void newCheckRequest(List<String> files, List<String> tmpFiles, Configuration config) { HttpClient client = new HttpClient(context, parameters.get("-url")); if (client.isError()) { context.send(BasicConfig.MODULE_MESSAGE, new LogMessage(getClass(), Level.ERROR, bundle.getString("urlError").replace("%1", parameters.get("-url")))); return;//w ww .j a v a 2s. c o m } // Add the files to check for (String path : files) { File file = new File(path); if (file.exists() && file.isFile()) { client.addFile(file); } } for (String path : tmpFiles) { File file = new File(path); if (file.exists() && file.isFile()) { client.addTmpFile(file); } } // Add the configuration file try { Path tmpPath = Files.createTempFile("config", "dpf"); File dest = tmpPath.toFile(); if (dest == null) { context.send(BasicConfig.MODULE_MESSAGE, new LogMessage(getClass(), Level.ERROR, bundle.getString("errorTmpFile"))); return; } config.SaveFile(dest.getAbsolutePath()); client.addConfig(dest); } catch (Exception e) { e.printStackTrace(); context.send(BasicConfig.MODULE_MESSAGE, new LogMessage(getClass(), Level.ERROR, bundle.getString("errorTmpFile"))); return; } send(client); }
From source file:org.jboss.pnc.jenkinsbuilddriver.test.JenkinsDriverRemoteTest.java
private RunningEnvironment getRunningEnvironment() { final RepositorySession repositoryConfiguration = getRepositoryConfiguration(); return new RunningEnvironment() { @Override/*from w w w . ja va 2s . com*/ public RepositorySession getRepositorySession() { return repositoryConfiguration; } @Override public Path getWorkingDirectory() { try { Path tempDirectory = Files.createTempDirectory("JenkinsDriverRemoteTest"); tempDirectory.toFile().deleteOnExit(); return tempDirectory; } catch (IOException e) { throw new RuntimeException(e); } } @Override public String getJenkinsUrl() { return System.getenv("PNC_JENKINS_URL") + ":" + getJenkinsPort(); } @Override public String getInternalBuildAgentUrl() { return getJenkinsUrl(); } @Override public int getJenkinsPort() { return Integer.parseInt(System.getenv("PNC_JENKINS_PORT")); } @Override public String getId() { return null; } @Override public void destroyEnvironment() throws EnvironmentDriverException { } }; }
From source file:fr.duminy.jbackup.core.util.DefaultFileDeleter.java
private void deleteFiles(FileDeleteStrategy deleteStrategy, List<Path> paths, boolean expectFiles) { if (paths != null) { for (Path path : paths) { boolean deleted = false; try { PathUtils.setReadable(path, true); if (expectFiles && Files.isRegularFile(path)) { deleted = deleteStrategy.deleteQuietly(path.toFile()); } else if (!expectFiles && Files.isDirectory(path)) { deleted = deleteStrategy.deleteQuietly(path.toFile()); } else { LOG.error("Wrong path type. Expected: {} Actual: {} {}", new Object[] { (expectFiles ? "file" : "directory"), (Files.isRegularFile(path) ? "file" : ""), (Files.isDirectory(path) ? "directory" : "") }); deleted = false;/* w ww.j av a 2 s.c o m*/ } } catch (IOException e) { deleted = false; } if (deleted) { LOG.info("{} : deleted", path); } else { LOG.error("{} : NOT DELETED", path); } } } }
From source file:com.willwinder.ugp.tools.GcodeTilerTopComponent.java
private void generateGcode() { if (!loadDimensions()) return;/*ww w . j ava 2s . co m*/ Path path = null; try { path = Files.createTempFile("dowel_program", ".gcode"); File file = path.toFile(); generateAndLoadGcode(file); } catch (IOException e) { GUIHelpers.displayErrorDialog(ERROR_LOADING + e.getLocalizedMessage()); } }