List of usage examples for java.nio.file Files isWritable
public static boolean isWritable(Path path)
From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceConfig.java
private void checkOrientDBRootDir() { checkArgument(Files.exists(orientDBRootDir), PATH_DOES_NOT_EXIST, "orientDBRootDir", orientDBRootDir); checkArgument(Files.isDirectory(orientDBRootDir), PATH_IS_NOT_A_DIRECTORY, "orientDBRootDir", orientDBRootDir);//from ww w.j ava 2 s. c o m checkArgument(Files.isReadable(orientDBRootDir), PATH_IS_NOT_READABLE, "orientDBRootDir", orientDBRootDir); checkArgument(Files.isWritable(orientDBRootDir), PATH_IS_NOT_WRITEABLE, "orientDBRootDir", orientDBRootDir); }
From source file:io.bitsquare.app.gui.BitsquareApp.java
private void initAppDir(String appDir) { Path dir = Paths.get(appDir); if (Files.exists(dir)) { if (!Files.isWritable(dir)) { throw new BitsquareException("Application data directory '%s' is not writeable", dir); }/*from ww w.j a v a 2s. c o m*/ return; } try { Files.createDirectory(dir); } catch (IOException ex) { throw new BitsquareException(ex, "Application data directory '%s' could not be created", dir); } }
From source file:ee.ria.xroad.proxy.messagelog.LogArchiver.java
private Path getArchivePath() { if (!Files.isDirectory(archivePath)) { throw new RuntimeException("Log output path (" + archivePath + ") must be directory"); }/*from ww w. j a v a 2 s .co m*/ if (!Files.isWritable(archivePath)) { throw new RuntimeException("Log output path (" + archivePath + ") must be writable"); } return archivePath; }
From source file:ee.ria.xroad.proxy.messagelog.LogArchiver.java
private Path getWorkingPath() { if (!Files.isDirectory(workingPath)) { throw new RuntimeException("Log working path (" + workingPath + ") must be directory"); }/* w ww .j ava2s. co m*/ if (!Files.isWritable(workingPath)) { throw new RuntimeException("Log working path (" + workingPath + ") must be writable"); } return workingPath; }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java
private static void parseCli(String[] args) { CommandLineParser parser = new PosixParser(); try {/*from w w w.j av a 2s.c o m*/ CommandLine cmd = parser.parse(options, args); // Show usage, ignore other parameters and quit if (cmd.hasOption('h')) { usage(); logger.debug("Help called, main() exit."); System.exit(0); } if (cmd.hasOption('d')) { // Activate debug markup only - does not affect logging! debugMarkupOutput = true; } if (cmd.hasOption('m')) { exportMarkup = true; } if (cmd.hasOption('t')) { title = cmd.getOptionValue('t'); } if (cmd.hasOption('f')) { filename = cmd.getOptionValue('f'); } if (cmd.hasOption('n')) { exportMarkup = true; // implicit markup export noMobiConversion = true; } if (cmd.hasOption('i')) { String[] inputValues = cmd.getOptionValues('i'); for (String inputValue : inputValues) { inputPaths.add(Paths.get(inputValue)); } } else { logger.error("You have to specify an inputPath file or directory!"); usage(); System.exit(1); } if (cmd.hasOption('o')) { String outputDirectory = cmd.getOptionValue('o'); outputPath = Paths.get(outputDirectory).toAbsolutePath(); logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); if (!Files.isDirectory(outputPath) && Files.isRegularFile(outputPath)) { logger.error("Given output directory is a file! Exiting..."); System.exit(1); } if (!Files.exists(outputPath)) { Files.createDirectory(outputPath); } if (!Files.isWritable(outputPath)) { logger.error("Given output directory is not writable! Exiting..."); logger.debug(outputPath.toAbsolutePath().toString()); System.exit(1); } logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); } else { // Set default output directory if none is given outputPath = workingDirectory; } // If set, replace LaTeX Formulas with PNG images, created by if (cmd.hasOption("r")) { logger.debug("Picture Flag set"); replaceWithPictures = true; } if (cmd.hasOption("u")) { logger.debug("Use calibre instead of kindlegen"); useCalibreInsteadOfKindleGen = true; } // Executable configuration LatexToHtmlConverter latexToHtmlConverter = (LatexToHtmlConverter) applicationContext .getBean("latex2html-converter"); if (cmd.hasOption(latexToHtmlConverter.getExecOption().getOpt())) { String execValue = cmd.getOptionValue(latexToHtmlConverter.getExecOption().getOpt()); logger.info("LaTeX to HTML Executable argument was given: " + execValue); Path execPath = Paths.get(execValue); latexToHtmlConverter.setExecPath(execPath); } String htmlToMobiConverterBean = KINDLEGEN_HTML2MOBI_CONVERTER; if (useCalibreInsteadOfKindleGen) { htmlToMobiConverterBean = CALIBRE_HTML2MOBI_CONVERTER; } HtmlToMobiConverter htmlToMobiConverter = (HtmlToMobiConverter) applicationContext .getBean(htmlToMobiConverterBean); Option htmlToMobiOption = htmlToMobiConverter.getExecOption(); if (cmd.hasOption(htmlToMobiOption.getOpt())) { String execValue = cmd.getOptionValue(htmlToMobiOption.getOpt()); logger.info("HTML to Mobi Executable argument was given: " + execValue); try { Path execPath = Paths.get(execValue); htmlToMobiConverter.setExecPath(execPath); } catch (InvalidPathException e) { logger.error("Invalid path given for --" + htmlToMobiOption.getLongOpt() + " <" + htmlToMobiOption.getArgName() + ">"); logger.error("I will try to use your system's PATH variable..."); } } } catch (MissingOptionException m) { Iterator<String> missingOptionsIterator = m.getMissingOptions().iterator(); while (missingOptionsIterator.hasNext()) { logger.error("Missing required options: " + missingOptionsIterator.next() + "\n"); } usage(); System.exit(1); } catch (MissingArgumentException a) { logger.error("Missing required argument for option: " + a.getOption().getOpt() + "/" + a.getOption().getLongOpt() + "<" + a.getOption().getArgName() + ">"); usage(); System.exit(2); } catch (ParseException e) { logger.error("Error parsing command line arguments, exiting..."); logger.error(e.getMessage(), e); System.exit(3); } catch (IOException e) { logger.error("Error creating output path at " + outputPath.toAbsolutePath().toString()); logger.error(e.getMessage(), e); logger.error("Exiting..."); System.exit(4); } }
From source file:com.dianping.resource.io.PathResource.java
/** * This implementation checks whether the underlying file is marked as writable * (and corresponds to an actual file with content, not to a directory). * @see java.nio.file.Files#isWritable(java.nio.file.Path) * @see java.nio.file.Files#isDirectory(java.nio.file.Path, java.nio.file.LinkOption...) *//*from w ww. j av a 2 s . c o m*/ @Override public boolean isWritable() { return Files.isWritable(this.path) && !Files.isDirectory(this.path); }
From source file:fr.duminy.jbackup.core.ConfigurationManagerTest.java
private void existsRW(Path configFile, boolean existsRW) { assertThat(Files.exists(configFile)).as("configFile exists").isEqualTo(existsRW); assertThat(Files.isReadable(configFile)).as("configFile is readable").isEqualTo(existsRW); assertThat(Files.isWritable(configFile)).as("configFile is writable").isEqualTo(existsRW); }
From source file:at.tfr.securefs.ui.CopyFilesServiceBean.java
private Path validateToPath(String toPathName, ProcessFilesData pfd) throws IOException { Path to = Paths.get(toPathName); if (Files.exists(to, LinkOption.NOFOLLOW_LINKS)) { if (Files.isSameFile(to, Paths.get(pfd.getFromRootPath()))) { throw new IOException("Path " + to + " may not be same as FromPath: " + pfd.getFromRootPath()); }//from ww w. j a v a 2 s. c o m if (!Files.isDirectory(to, LinkOption.NOFOLLOW_LINKS)) { throw new IOException("Path " + to + " is no directory"); } if (!Files.isWritable(to)) { throw new IOException("Path " + to + " is not writable"); } if (!Files.isExecutable(to)) { throw new IOException("Path " + to + " is not executable"); } if (!pfd.isAllowOverwriteExisting()) { if (Files.newDirectoryStream(to).iterator().hasNext()) { throw new IOException("Path " + to + " is not empty, delete content copy."); } } } return to; }
From source file:io.openvidu.server.recording.service.RecordingManager.java
private void checkRecordingPaths(String openviduRecordingPath, String openviduRecordingCustomLayout) throws OpenViduException { log.info("Initializing recording paths"); Path recordingPath = null;/*ww w . java 2s .c o m*/ try { recordingPath = Files.createDirectories(Paths.get(openviduRecordingPath)); } catch (IOException e) { String errorMessage = "The recording path \"" + openviduRecordingPath + "\" is not valid. Reason: OpenVidu Server cannot find path \"" + openviduRecordingPath + "\" and doesn't have permissions to create it"; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); } // Check OpenVidu Server write permissions in recording path if (!Files.isWritable(recordingPath)) { String errorMessage = "The recording path \"" + openviduRecordingPath + "\" is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 " + openviduRecordingPath + "\""; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); } else { log.info("OpenVidu Server has write permissions on recording path: {}", openviduRecordingPath); } final String testFolderPath = openviduRecordingPath + "/TEST_RECORDING_PATH_" + System.currentTimeMillis(); final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm"; // Check Kurento Media Server write permissions in recording path KurentoClientSessionInfo kcSessionInfo = new OpenViduKurentoClientSessionInfo("TEST_RECORDING_PATH", "TEST_RECORDING_PATH"); MediaPipeline pipeline = this.kcProvider.getKurentoClient(kcSessionInfo).createMediaPipeline(); RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build(); final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false); recorder.addErrorListener(new EventListener<ErrorEvent>() { @Override public void onEvent(ErrorEvent event) { if (event.getErrorCode() == 6) { // KMS write permissions error kurentoRecorderError.compareAndSet(false, true); } } }); recorder.record(); try { // Give the error event some time to trigger if necessary Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } if (kurentoRecorderError.get()) { String errorMessage = "The recording path \"" + openviduRecordingPath + "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 " + openviduRecordingPath + "\""; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); } recorder.stop(); recorder.release(); pipeline.release(); log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath); try { new CustomFileManager().deleteFolder(testFolderPath); log.info("OpenVidu Server has write permissions over files created by Kurento Media Server"); } catch (IOException e) { String errorMessage = "The recording path \"" + openviduRecordingPath + "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. " + "Try running Kurento Media Server as user \"" + System.getProperty("user.name") + "\" or run OpenVidu Server as superuser"; log.error(errorMessage); log.error( "Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")", testFolderPath, testFolderPath); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); } if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) { // Property openvidu.recording.custom-layout changed File dir = new File(openviduRecordingCustomLayout); if (dir.exists()) { if (!dir.isDirectory()) { String errorMessage = "The custom layouts path \"" + openviduRecordingCustomLayout + "\" is not valid. Reason: path already exists but it is not a directory"; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage); } else { if (dir.listFiles() == null) { String errorMessage = "The custom layouts path \"" + openviduRecordingCustomLayout + "\" is not valid. Reason: OpenVidu Server needs read permissions. Try running command \"sudo chmod 755 " + openviduRecordingCustomLayout + "\""; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage); } else { log.info("OpenVidu Server has read permissions on custom layout path: {}", openviduRecordingCustomLayout); log.info("Custom layouts path successfully initialized at {}", openviduRecordingCustomLayout); } } } else { try { Files.createDirectories(dir.toPath()); log.warn( "OpenVidu custom layouts path (system property 'openvidu.recording.custom-layout') has been created, being folder {}. " + "It is an empty folder, so no custom layout is currently present", dir.getAbsolutePath()); } catch (IOException e) { String errorMessage = "The custom layouts path \"" + openviduRecordingCustomLayout + "\" is not valid. Reason: OpenVidu Server cannot find path \"" + openviduRecordingCustomLayout + "\" and doesn't have permissions to create it"; log.error(errorMessage); throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage); } } } log.info("Recording path successfully initialized at {}", openviduRecordingPath); }
From source file:nl.minvenj.pef.stream.LiveCapture.java
private static boolean checkConfiguration(final XMLConfiguration config) { final long MAX_FILE_SIZE = 1000; //Test if all fields are available. For now it exits per field. try {/*from w w w .j a va 2 s .c om*/ //First all normal fields. The library field is optional, default to metal. final boolean live = config.getBoolean("live"); final String inputFile = config.getString("input"); if (!live) { if (inputFile == null) { throw new NoSuchElementException( "For offline use, the parameter 'input' file needs to be specified"); } File testInput = new File(inputFile); if (!testInput.exists()) { logger.severe("The specified input file " + testInput.toPath().toAbsolutePath().toString() + " does not exist."); return false; } if (!testInput.canRead()) { logger.severe("The user is not allowed to read the file"); } } // Will throw an error if conversion fails. config.getBoolean("remove_failing_packets"); config.getBoolean("remove_unknown_protocols"); config.getBoolean("checksum_reset"); config.getBoolean("timer", false); final String outputDir = config.getString("output_directory"); // The file size does not need to be specified. Therefore a default is provided. final long fileSize = config.getLong("file_size", 120); if (fileSize > MAX_FILE_SIZE) { logger.severe(" A file size over 1000 MB is not supported."); return false; } if (outputDir == null) { throw new NoSuchElementException("The output_directory parameter is not set"); } final Path path = Paths.get(outputDir); if (!Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { logger.severe("The output directory configured is not a path."); return false; } if (!Files.isWritable(path)) { logger.severe("The selected output directory is not writable."); return false; } final String parseLibrary = config.getString("parse_library"); if (!parseLibrary.equals("metal")) { logger.severe("Only the metal library is currently implemented as parse library."); return false; } String[] packetInputLibraryOptions = { "metal", "jnetpcap" }; final String packetInputLibrary = config.getString("packets_input_library"); if (!Arrays.asList(packetInputLibraryOptions).contains(packetInputLibrary)) { logger.severe("Packet Input Library: " + packetInputLibrary + " is not implemented."); } // Test all algorithms and their parameters. testPseudonymizationSettings(config); } catch (NoSuchElementException e) { logger.severe("Input element is missing: " + e.getMessage()); return false; } catch (InvalidPathException e) { logger.severe("The path specified in the config file is invalid: " + e.getMessage()); return false; } catch (ConversionException e) { logger.severe("Conversion failed: " + e.getMessage()); return false; } catch (ClassNotFoundException e) { logger.severe("Error in creating a parameter: the class could not be found: " + e.getMessage()); return false; } catch (ConfigurationException e) { logger.severe(e.getMessage()); return false; } return true; }