List of usage examples for java.io File canWrite
public boolean canWrite()
From source file:eu.prestoprime.plugin.p4.AccessTasks.java
@WfService(name = "make_consumer_segment", version = "2.2.0") public void execute(Map<String, String> sParams, Map<String, String> dParamsString, Map<String, File> dParamFile) throws TaskExecutionFailedException { if (!Boolean.parseBoolean(dParamsString.get("isSegmented"))) { // retrieve static params String destVolume = sParams.get("dest.path.volume").trim(); String destFolder = sParams.get("dest.path.folder").trim(); // retrieve dynamic params String dipID = dParamsString.get("dipID"); String inputFilePath = dParamsString.get("source.file.path"); String mimeType = dParamsString.get("source.file.mimetype"); int startFrame = Integer.parseInt(dParamsString.get("start.frame")); int stopFrame = Integer.parseInt(dParamsString.get("stop.frame")); String outputFolder = destVolume + File.separator + destFolder; try {/*from w w w . ja v a 2s . c o m*/ if (dipID == null) throw new TaskExecutionFailedException("Missing AIP ID to extract fragment"); if (mimeType == null) throw new TaskExecutionFailedException("Missing MIME Type to extract fragment"); DIP dip = P4DataManager.getInstance().getDIPByID(dipID); if (inputFilePath == null) { // trying to retrieve file path from DIP, last chance... List<String> videoFileList = dip.getAVMaterial(mimeType, "FILE"); if (videoFileList.size() == 0) { throw new TaskExecutionFailedException("Missing input file path to extract fragment"); } else { inputFilePath = videoFileList.get(0); } } File targetDir = new File(outputFolder); targetDir.mkdirs(); if (!targetDir.canWrite()) throw new TaskExecutionFailedException("Unable to write to output dir " + outputFolder); String targetFileName = dipID + "." + startFrame + "." + stopFrame + "." + FilenameUtils.getExtension(inputFilePath); File targetFile = new File(targetDir, targetFileName); int startSec = startFrame / 25; int endSec = stopFrame / 25; int durationSec = endSec - startSec; String start = Integer.toString(startSec); String duration = Integer.toString(durationSec); List<String> formats = dip.getDCField(DCField.format); StringBuilder formatSB = new StringBuilder(); for (String format : formats) { formatSB.append(format + "\t"); } // extract fragment using ffmbc FFmbc ffmbc = new FFmbc(); ffmbc.extractSegment(inputFilePath, targetFile.getAbsolutePath(), start, duration, mimeType, formatSB.toString(), "2"); dParamsString.put("isSegmented", "true"); dParamsString.put("segment.file.path", targetFileName); logger.debug("Consumer copy available at: " + targetFile.getAbsolutePath()); } catch (DataException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to retrieve DIP with id: " + dipID); } catch (IPException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to retrieve MQ file"); } catch (ToolException e) { e.printStackTrace(); throw new TaskExecutionFailedException("Unable to extract segment with FFMBC"); } } }
From source file:net.lightbody.bmp.proxy.jetty.util.RolloverFileOutputStream.java
private synchronized void setFile() throws IOException { // Check directory File file = new File(_filename); _filename = file.getCanonicalPath(); file = new File(_filename); File dir = new File(file.getParent()); if (!dir.isDirectory() || !dir.canWrite()) throw new IOException("Cannot write log directory " + dir); Date now = new Date(); // Is this a rollover file? String filename = file.getName(); int i = filename.toLowerCase().indexOf(YYYY_MM_DD); if (i >= 0) { file = new File(dir, filename.substring(0, i) + _fileDateFormat.format(now) + filename.substring(i + YYYY_MM_DD.length())); }//from w w w .j a va 2 s . c om if (file.exists() && !file.canWrite()) throw new IOException("Cannot write log file " + file); // Do we need to change the output stream? if (out == null || !file.equals(_file)) { // Yep _file = file; if (!_append && file.exists()) file.renameTo(new File(file.toString() + "." + _fileBackupFormat.format(now))); OutputStream oldOut = out; out = new FileOutputStream(file.toString(), _append); if (oldOut != null) oldOut.close(); if (log.isDebugEnabled()) log.debug("Opened " + _file); } }
From source file:com.github.pmerienne.trident.state.cassandra.embedded.AbstractEmbeddedServer.java
private void cleanCassandraConfigFile(Map<String, Object> parameters) { if ((Boolean) parameters.get(CLEAN_CASSANDRA_CONFIG_FILE)) { String configYamlFilePath = (String) parameters.get(CONFIG_YAML_FILE); final File configYamlFile = new File(configYamlFilePath); if (configYamlFile.exists()) { String currentUser = System.getProperty("user.name"); assert configYamlFile.canWrite() : String.format( "No write credential. Please grant write permission for " + "the current user '%s' on file '%s'", currentUser, configYamlFile.getAbsolutePath()); configYamlFile.delete();// w w w. j av a 2s .c o m } } }
From source file:com.ingby.socbox.bischeck.configuration.DocManager.java
/** * Check if the output directory is valid to create output in. If it does * not exists it will be created.//from w w w.ja v a 2 s . c o m * @param dirname * @return the File to the directory * @throws IOException if the directory can not be written to, if it can * not be created. */ private File checkDir(String dirname) throws IOException { File outputdir = new File(dirname); if (outputdir.isDirectory()) { if (outputdir.canWrite() && outputdir.canExecute()) { return outputdir; } else { throw new IOException("Directory " + dirname + " is not writable."); } } else { File parent = outputdir.getParentFile(); if (parent == null) { // absolute name from . parent = new File("."); } if (parent.isDirectory() && parent.canWrite()) { outputdir.mkdir(); return outputdir; } else { throw new IOException( "Parent directory " + parent.getPath() + " does not exist or is not writable."); } } }
From source file:com.sse.abtester.VariantManager.java
@Override public void setServletContext(ServletContext servletContext) { sc = servletContext;//from w ww . java 2 s . c o m String filepath = sc.getRealPath(rewriteFilterConfPath); File filterConfFile = new File(filepath); System.out.println("found " + filepath + "and it is Writeable? " + filterConfFile.canWrite()); }
From source file:eu.openanalytics.rsb.config.BootstrapConfigurationServletContextListener.java
File getWritableConfigurationDirectory(final ServletContextEvent sce) { File rsbConfigurationDirectory = new File(ConfigurationFactory.RSB_CONFIGURATION_DIRECTORY); if (rsbConfigurationDirectory.isDirectory() && rsbConfigurationDirectory.canWrite()) { return rsbConfigurationDirectory; }/*from www .ja v a2 s . c o m*/ final String path = sce.getServletContext().getRealPath("/WEB-INF/classes"); if (StringUtils.isNotBlank(path)) { rsbConfigurationDirectory = new File(path); if (rsbConfigurationDirectory.isDirectory() && rsbConfigurationDirectory.canWrite()) { return rsbConfigurationDirectory; } } return null; }
From source file:com.amazonaws.services.s3.internal.MultiFileOutputStream.java
/** * Construct an instance to use the specified directory for temp file * creations, and the specified prefix for temp file naming. The * {@link #init(UploadObjectObserver, long, long)} must be called before * this stream is considered fully initialized. * @param namePrefix the prefix for file naming. * @param root the file foot./*from www . ja v a2s . c om*/ */ public MultiFileOutputStream(File root, String namePrefix) { if (root == null || !root.isDirectory() || !root.canWrite()) { throw new IllegalArgumentException(root + " must be a writable directory"); } if (namePrefix == null || namePrefix.trim().length() == 0) { throw new IllegalArgumentException("Please specify a non-empty name prefix"); } this.root = root; this.namePrefix = namePrefix; }
From source file:de.metanome.backend.algorithm_execution.TempFileGeneratorTest.java
/** * Test method for {@link TempFileGenerator#getTemporaryFile()} <p/> The generator should return * readable, writable, empty files./*from w ww .j a va 2 s. c o m*/ */ @Test public void testGetTemporaryFile() throws IOException, FileCreationException { // Setup TempFileGenerator tempFileGenerator = new TempFileGenerator(); // Execute functionality File actualFile = tempFileGenerator.getTemporaryFile(); // Check result assertTrue(actualFile.exists()); assertTrue(actualFile.isFile()); assertTrue(actualFile.canRead()); assertTrue(actualFile.canWrite()); assertEquals(0, actualFile.length()); // Cleanup tempFileGenerator.close(); }
From source file:com.mirth.connect.connectors.file.filesystems.FileConnection.java
@Override public boolean canWrite(String writeDir) { File writeDirectory = new File(writeDir); return writeDirectory.isDirectory() && writeDirectory.canWrite(); }
From source file:eu.europa.ejusticeportal.dss.applet.model.action.SavePdfActionTest.java
/** * Test the doExec method for SavePdfAction *///from ww w . j a va2s . c o m @Test public void testDoExec() { FileInputStream fis = null; FileInputStream result = null; SavePdfAction instance; try { fis = new FileInputStream("src/test/resources/hello-world.pdf"); byte[] pdf = (IOUtils.toByteArray(fis)); instance = new SavePdfAction(pdf, null); instance.exec(); File f = File.createTempFile("test", ".pdf"); f.deleteOnExit(); instance = new SavePdfAction(pdf, f); instance.exec(); assertNotNull(f); assertTrue(f.exists()); assertTrue(f.canRead()); assertTrue(f.canWrite()); result = new FileInputStream(f); byte[] resultPdf = (IOUtils.toByteArray(result)); assertTrue(resultPdf.length > 0); } catch (FileNotFoundException ex) { fail("Hello-world.pdf is not available."); } catch (IOException ex) { fail("IO Issue"); } finally { try { fis.close(); result.close(); } catch (IOException ex) { fail("Unable to close File stream"); } } }