List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.ow2.proactive.scheduler.task.TaskLogger.java
public File createFileAppender(File pathToFolder) throws IOException { if (taskLogAppender.getAppender(FILE_APPENDER_NAME) != null) { throw new IllegalStateException("Only one file appender can be created"); }/* www .j a v a2 s. c o m*/ File logFile = new File(pathToFolder, new TaskLoggerRelativePathGenerator(taskId).getRelativePath()); logFile.getParentFile().mkdirs(); FileUtils.touch(logFile); logFile.setWritable(true, false); FileAppender fap = new FileAppender(Log4JTaskLogs.getTaskLogLayout(), logFile.getAbsolutePath(), false); fap.setName(FILE_APPENDER_NAME); taskLogAppender.addAppender(fap); return logFile; }
From source file:org.ow2.proactive.utils.appenders.FileAppender.java
public void append(String fileName, LoggingEvent event) { if (filesLocation != null) { fileName = filesLocation + File.separator + fileName; }//from w ww .ja v a 2 s. c o m File file = new File(fileName); if (!file.exists()) { try { FileUtils.forceMkdirParent(file); FileUtils.touch(file); } catch (IOException e) { Logger.getRootLogger().error(e.getMessage(), e); } } try { RollingFileAppender appender = new RollingFileAppender(getLayout(), fileName, true); appender.setMaxBackupIndex(1); if (maxFileSize != null) { appender.setMaxFileSize(maxFileSize); } appender.append(event); appender.close(); } catch (IOException e) { Logger.getRootLogger().error(e.getMessage(), e); } }
From source file:org.owasp.jbrofuzz.io.FileHandler.java
@Override public void writeFuzzFile(MessageContainer outputMessage, String sessionId) { final String fileName = outputMessage.getFileName() + ".html"; final File toWrite = new File(fuzzDirectory, fileName); try {/*from ww w .ja va 2 s. c o m*/ FileUtils.touch(toWrite); FileUtils.writeStringToFile(toWrite, outputMessage.toString()); } catch (final IOException e) { Logger.log("Error writting fuzz file: " + fileName, 3); } }
From source file:org.paxle.filter.blacklist.impl.BlacklistFileStore.java
/** * @see org.paxle.filter.blacklist.IBlacklistStore#updateBlacklist(IBlacklist) *///from w ww. ja va2 s.c o m public boolean updateBlacklist(IBlacklist blacklist) throws InvalidBlacklistnameException { this.validateBlacklistname(blacklist.getName()); final File file = new File(this.blacklistDir.getAbsolutePath() + File.separatorChar + blacklist.getName()); if (!file.exists()) { try { FileUtils.touch(file); } catch (IOException e) { e.printStackTrace(); return false; } } if (file.isFile() && file.canWrite()) { try { FileUtils.writeLines(file, blacklist.getPatternList()); this.blacklists.put(blacklist.getName(), blacklist); return true; } catch (IOException e) { e.printStackTrace(); return false; } } return false; }
From source file:org.restcomm.connect.commons.amazonS3.S3AccessTool.java
public URI uploadFile(final String fileToUpload) { if (s3client == null) { s3client = getS3client();//from w w w .ja v a 2 s . c om } if (logger.isInfoEnabled()) { logger.info("S3 Region: " + bucketRegion.toString()); } try { if (testing && (!testingUrl.isEmpty() || !testingUrl.equals(""))) { // s3client.setEndpoint(testingUrl); // s3client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true)); FileUtils.touch(new File(URI.create(fileToUpload))); } StringBuffer bucket = new StringBuffer(); bucket.append(bucketName); if (folder != null && !folder.isEmpty()) bucket.append("/").append(folder); URI fileUri = URI.create(fileToUpload); if (logger.isInfoEnabled()) { logger.info("File to upload to S3: " + fileUri.toString()); } File file = new File(fileUri); while (!FileUtils.waitFor(file, 30)) { } if (file.exists()) { PutObjectRequest putRequest = new PutObjectRequest(bucket.toString(), file.getName(), file); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentType(new MimetypesFileTypeMap().getContentType(file)); putRequest.setMetadata(metadata); if (reducedRedundancy) putRequest.setStorageClass(StorageClass.ReducedRedundancy); s3client.putObject(putRequest); if (removeOriginalFile) { removeLocalFile(file); } URI recordingS3Uri = s3client.getUrl(bucket.toString(), file.getName()).toURI(); return recordingS3Uri; // return downloadUrl.toURI(); } else { logger.error("Timeout waiting for the recording file: " + file.getAbsolutePath()); return null; } } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException"); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); return null; } catch (AmazonClientException ace) { logger.error("Caught an AmazonClientException "); logger.error("Error Message: " + ace.getMessage()); return null; } catch (URISyntaxException e) { logger.error("URISyntaxException: " + e.getMessage()); return null; } catch (IOException e) { logger.error("Problem while trying to touch recording file for testing", e); return null; } }
From source file:org.rhq.core.pc.drift.FilterFileVisitorTest.java
private File touch(File dir, String fileName) throws IOException { File file = new File(dir, fileName); FileUtils.touch(file); return file;//ww w .j a va 2 s . c o m }
From source file:org.seasar.uruma.eclipath.ArtifactHelper.java
public void resolve(EclipathArtifact artifact, boolean throwOnError, boolean forceResolve) { // TODO Maven3 ???? // Check if jar is not available File notAvailableFile = null; if (workspaceConfigurator.isConfigured()) { String notAvailablePath = workspaceConfigurator.getClasspathVariableM2REPO() + "/" + artifact.getRepositoryPath() + NOT_AVAILABLE_SUFFIX; notAvailableFile = new File(notAvailablePath); if (!forceResolve) { if (!throwOnError && notAvailableFile.exists()) { return; }//from w ww .j ava 2s. c o m } else { notAvailableFile.delete(); } } // prepare artifact resolution request ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact.getArtifact()); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); // TODO ? request.setForceUpdate(forceResolve); // do resolve ArtifactResolutionResult result = repositorySystem.resolve(request); if (result.isSuccess()) { for (Artifact resolvedSrcArtifact : result.getArtifacts()) { Logger.info(" resolved: " + resolvedSrcArtifact.toString()); } } else { try { if (result.hasMissingArtifacts() && notAvailableFile != null) { FileUtils.touch(notAvailableFile); } } catch (IOException ignore) { } if (throwOnError) { throw new ArtifactResolutionRuntimeException("artifact resolution failed.", result); } else { Logger.warn("artifact resolution failed. : " + artifact.toString()); } } }
From source file:org.silverpeas.admin.domain.SQLDomainServiceTest.java
@Test @Transactional/*w w w . jav a 2 s . c om*/ public void testCreateDomainWithPropertiesNameConflicts() throws Exception { Domain domain = new Domain(); domain.setName("TestCreation"); File conflictousPropertiesFile = new File(tmpFile, "Domain3TestCrea.properties"); FileUtils.touch(conflictousPropertiesFile); conflictousPropertiesFile.deleteOnExit(); try { service.createDomain(domain); fail("Exception must have been thrown"); } catch (Exception e) { assertThat(e instanceof DomainPropertiesAlreadyExistsException, is(true)); } conflictousPropertiesFile.delete(); conflictousPropertiesFile = new File(tmpFile, "autDomain3TestCrea.properties"); FileUtils.touch(conflictousPropertiesFile); // create domain try { service.createDomain(domain); fail("Exception must have been thrown"); } catch (Exception e) { assertThat(e instanceof DomainAuthenticationPropertiesAlreadyExistsException, is(true)); } }
From source file:org.silverpeas.core.admin.domain.SQLDomainServiceIT.java
@Test(expected = DomainPropertiesAlreadyExistsException.class) public void testCreateDomainWithPropertiesNameConflictsOnDomainProperties() throws Exception { Domain domain = new Domain(); domain.setName("TestCreation"); File conflictingPropertiesFile = new File(domainPropertyPath, "domain3TestCrea.properties"); FileUtils.touch(conflictingPropertiesFile); service.createDomain(domain);/*w w w . j ava2s . c o m*/ fail("Exception must have been thrown"); }
From source file:org.silverpeas.core.admin.domain.SQLDomainServiceIT.java
@Test(expected = DomainAuthenticationPropertiesAlreadyExistsException.class) public void testCreateDomainWithPropertiesNameConflictsOnAutDomainProperties() throws Exception { Domain domain = new Domain(); domain.setName("TestCreation"); File conflictingPropertiesFile = new File(autDomainPropertyPath, "autDomain3TestCrea.properties"); FileUtils.touch(conflictingPropertiesFile); // create domain service.createDomain(domain);/*ww w.j av a2 s. c om*/ fail("Exception must have been thrown"); }