List of usage examples for java.io File isAbsolute
public boolean isAbsolute()
From source file:com.comcast.cats.video.service.VideoServiceImpl.java
@Override public void saveVideoImage(String filePath) { if (null == filePath || filePath.isEmpty()) { logger.error("Saving video image failed. The file location cannot be null or empty: " + filePath); } else {/* www .j a va 2s.co m*/ String imagePath = filePath; File imagefile = new File(imagePath); // If the file path specified is a relative path, the image must be saved in to CATS_HOME/$macFolder/<filePath> if (!imagefile.isAbsolute()) { String catsHome = System.getProperty("cats.home"); if (null != catsHome) { imagePath = catsHome + System.getProperty("file.separator") + getCleanMac() + System.getProperty("file.separator") + imagePath; } imagefile = new File(imagePath); } /** * If the specified file path is of an existing directory, the image will be saved in to * <filepath>/$macFolder/$defaultFileName.jpg */ if (imagefile.exists() && imagefile.isDirectory()) { imagePath = imagePath + System.getProperty("file.separator") + getFolderAndFileName(); imagefile = new File(imagePath); } try { FileUtils.forceMkdir(imagefile.getAbsoluteFile().getParentFile()); ImageIO.write(getVideoImage(), IMAGE_FILE_FORMAT, imagefile); logger.info("Saved video image to file: " + imagefile.getAbsolutePath()); } catch (Exception e) { logger.error("Saving video image failed. Error in creating file: '" + imagePath + "'.\n" + e.getMessage()); } } }
From source file:org.eclipse.jubula.autagent.commands.AbstractStartJavaAut.java
/** * {@inheritDoc}//w w w. j a va2s . c o m */ protected String createBaseCmd(Map<String, String> parameters) throws IOException { String executableFileName = parameters.get(AutConfigConstants.EXECUTABLE); if (executableFileName != null && executableFileName.length() > 0) { // Use the given executable, prepending the working directory if // the filename is relative File exe = new File(executableFileName); if (!exe.isAbsolute()) { exe = new File(parameters.get(AutConfigConstants.WORKING_DIR), executableFileName); } if (exe.isFile() && exe.exists()) { return exe.getCanonicalPath(); } // else String errorMsg = executableFileName + " does not point to a valid executable."; //$NON-NLS-1$ LOG.warn(errorMsg); return executableFileName; } // Use java if no executable file is defined String java = StringConstants.EMPTY; String jre = parameters.get(AutConfigConstants.JRE_BINARY); if (jre == null) { jre = StringConstants.EMPTY; } File jreFile = new File(jre); if (jre.length() == 0) { java = "java"; //$NON-NLS-1$ } else { if (!jreFile.isAbsolute()) { jreFile = new File(getWorkingDir(parameters), jre); } if (jreFile.isFile() && jreFile.exists()) { java = jreFile.getCanonicalPath(); } else { String errorMsg = jreFile + " does not point to a valid JRE executable."; //$NON-NLS-1$ LOG.error(errorMsg); throw new FileNotFoundException(errorMsg); } } return java; }
From source file:com.git.original.common.config.XMLFileConfigDocument.java
protected ConfigNode doLoad(String configFilePath) throws Exception { InputStream in = null;/*from w w w . jav a 2s. c om*/ try { File confFile = new File(configFilePath); if (!confFile.isAbsolute()) { confFile = new File(this.getHmailHome(), configFilePath); } if (!confFile.exists()) { throw new FileNotFoundException("path:" + confFile); } String currentDigest = confFile.lastModified() + ";" + confFile.length(); if (currentDigest.equals(this.configFileDigest)) { // ??, ? return null; } in = new FileInputStream(confFile); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); NodeBuilder nb = new NodeBuilder(); parser.parse(in, nb); ConfigNode result = nb.getRootNode(); if (result != null) { try { this.dbVersion = result.getAttribute(CONF_DOC_ATTRIBUTE_DB_VERSION); } catch (Exception ex) { this.dbVersion = null; } try { String str = result.getAttribute(CONF_DOC_ATTRIBUTE_IGNORE_DB); if (StringUtils.isEmpty(str)) { this.ignoreDb = false; } else { this.ignoreDb = Boolean.parseBoolean(str); } } catch (Exception ex) { this.ignoreDb = false; } try { String tmp = result.getAttribute(CONF_DOC_ATTRIBUTE_SCAN_PERIOD); if (StringUtils.isEmpty(tmp)) { this.scanMillis = null; } else { this.scanMillis = ConfigNode.textToNumericMillis(tmp.trim()); } } catch (Exception ex) { this.scanMillis = null; } } LOG.debug("Load config from local dir success, file:{}", configFilePath); return result; } finally { if (in != null) { try { in.close(); } catch (IOException e) { // ignore exception } } } }
From source file:com.mgmtp.jfunk.core.scripting.ModuleArchiver.java
/** * Adds a file or directory (recursively) to the archive directory if it is not already present * in the archive directory.//w w w . j a v a 2 s .c om * * @param relativeDir * the directory relative to the archive root directory which the specified file or * directory is added to * @param fileOrDirToAdd * the file or directory to add * @throws IOException * if an IO error occurs during copying */ public void addToArchive(final File relativeDir, final File fileOrDirToAdd) throws IOException { checkArgument(!relativeDir.isAbsolute(), "'relativeDir' must be a relative directory"); if (isArchivingDisabled()) { return; } if (fileOrDirToAdd.getCanonicalPath().startsWith(moduleArchiveDir.getCanonicalPath())) { // File already in archive dir log.info("File '" + fileOrDirToAdd + "' already in archive directory. No copying necessary."); return; } File archiveTargetDir = new File(moduleArchiveDir, relativeDir.getPath()); if (fileOrDirToAdd.isDirectory()) { copyDirectory(fileOrDirToAdd, archiveTargetDir); } else { copyFileToDirectory(fileOrDirToAdd, archiveTargetDir); } }
From source file:com.funambol.pushlistener.service.config.PushListenerConfigBean.java
/** * Called by PushListenerConfiguration to say to the bean the config path. * In this waym the config bean can arrange relative path. * @param configPath the configuration path *//*from w w w .ja v a 2s.co m*/ void fixConfigPath(String configPath) { // // We updated the clusterConfiguration objecct in order to have the // cluster configuration file under config dir // if (clusterConfiguration != null) { if (clusterConfiguration.getConfigurationFile() != null) { File file = new File(clusterConfiguration.getConfigurationFile()); String filePath = file.getPath(); if (!file.isAbsolute()) { File newFile = new File(configPath + File.separator + filePath); clusterConfiguration.setConfigurationFile(newFile.getPath()); } } } }
From source file:com.jayway.maven.plugins.android.common.UnpackedLibHelper.java
public UnpackedLibHelper(ArtifactResolverHelper artifactResolverHelper, MavenProject project, Logger log, File unpackedLibsFolder) { this.artifactResolverHelper = artifactResolverHelper; if (unpackedLibsFolder != null) { // if absolute then use it. // if relative then make it relative to the basedir of the project. this.unpackedLibsDirectory = unpackedLibsFolder.isAbsolute() ? unpackedLibsFolder : new File(project.getBasedir(), unpackedLibsFolder.getPath()); } else {// ww w. j av a2 s.c om // If not specified then default to target/unpacked-libs final File targetFolder = new File(project.getBuild().getDirectory()); this.unpackedLibsDirectory = new File(targetFolder, "unpacked-libs"); } this.log = log; }
From source file:com.enjoyxstudy.selenium.autoexec.AutoExecServer.java
/** * @throws IOException// www .java 2 s . co m * @throws SVNException */ private void exportSuiteRepository() throws IOException, SVNException { File suiteDir = configuration.getSuiteDir(); if (!suiteDir.isAbsolute()) { suiteDir = suiteDir.getAbsoluteFile(); } if (suiteDir.exists()) { log.info("Delete suite directory."); FileUtils.deleteDirectory(suiteDir); } SVNUtils.export(configuration.getSuiteRepo(), suiteDir, configuration.getSuiteRepoUsername(), configuration.getSuiteRepoPassword()); log.info("Suite Export repository[" + configuration.getSuiteRepo() + "] dist=[" + suiteDir.getPath() + "]"); }
From source file:interactivespaces.workbench.project.ProjectTaskContext.java
@Override public File getProjectTarget(File rootDirectory, String target) { String targetPath = project.getConfiguration().evaluate(target); File targetFile = new File(targetPath); if (targetFile.isAbsolute()) { return targetFile; }/*from w w w . j av a2s. c om*/ return new File(rootDirectory, targetPath); }
From source file:org.apache.ofbiz.content.data.DataResourceWorker.java
public static File getContentFile(String dataResourceTypeId, String objectInfo, String contextRoot) throws GeneralException, FileNotFoundException { File file = null; if (dataResourceTypeId.equals("LOCAL_FILE") || dataResourceTypeId.equals("LOCAL_FILE_BIN")) { file = FileUtil.getFile(objectInfo); if (!file.exists()) { throw new FileNotFoundException("No file found: " + (objectInfo)); }//from www . ja v a2 s. c o m if (!file.isAbsolute()) { throw new GeneralException("File (" + objectInfo + ") is not absolute"); } } else if (dataResourceTypeId.equals("OFBIZ_FILE") || dataResourceTypeId.equals("OFBIZ_FILE_BIN")) { String prefix = System.getProperty("ofbiz.home"); String sep = ""; if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) { sep = "/"; } file = FileUtil.getFile(prefix + sep + objectInfo); if (!file.exists()) { throw new FileNotFoundException("No file found: " + (prefix + sep + objectInfo)); } } else if (dataResourceTypeId.equals("CONTEXT_FILE") || dataResourceTypeId.equals("CONTEXT_FILE_BIN")) { if (UtilValidate.isEmpty(contextRoot)) { throw new GeneralException("Cannot find CONTEXT_FILE with an empty context root!"); } String sep = ""; if (objectInfo.indexOf("/") != 0 && contextRoot.lastIndexOf("/") != (contextRoot.length() - 1)) { sep = "/"; } file = FileUtil.getFile(contextRoot + sep + objectInfo); if (!file.exists()) { throw new FileNotFoundException("No file found: " + (contextRoot + sep + objectInfo)); } } return file; }
From source file:org.apache.archiva.rest.services.AbstractArchivaRestTest.java
protected void createAndIndexRepo(String testRepoId, String repoPath, boolean stageNeeded) throws ArchivaRestServiceException, IOException, RedbackServiceException { if (getManagedRepositoriesService(authorizationHeader).getManagedRepository(testRepoId) != null) { getManagedRepositoriesService(authorizationHeader).deleteManagedRepository(testRepoId, false); }//ww w.j a v a 2 s . c o m ManagedRepository managedRepository = new ManagedRepository(); managedRepository.setId(testRepoId); managedRepository.setName("test repo"); File badContent = new File(repoPath, "target"); if (badContent.exists()) { FileUtils.deleteDirectory(badContent); } File file = new File(repoPath); if (!file.isAbsolute()) { repoPath = getBasedir() + "/" + repoPath; } managedRepository.setLocation(new File(repoPath).getPath()); managedRepository.setIndexDirectory( System.getProperty("java.io.tmpdir") + "/target/.index-" + Long.toString(new Date().getTime())); managedRepository.setStageRepoNeeded(stageNeeded); managedRepository.setSnapshots(true); //managedRepository.setScanned( scanned ); ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader); service.addManagedRepository(managedRepository); getRoleManagementService(authorizationHeader) .assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin"); getRoleManagementService(authorizationHeader) .assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "guest"); }