List of usage examples for org.apache.commons.io FilenameUtils getFullPathNoEndSeparator
public static String getFullPathNoEndSeparator(String filename)
From source file:org.apache.falcon.cli.FalconCLIIT.java
private void createPropertiesFile(TestContext context) throws Exception { InputStream in = this.getClass().getResourceAsStream(RECIPE_PROPERTIES_FILE_XML); Properties props = new Properties(); props.load(in);/*from www . ja v a 2s . c o m*/ in.close(); String wfFile = TestContext.class.getResource("/fs-workflow.xml").getPath(); String resourcePath = FilenameUtils.getFullPathNoEndSeparator(wfFile); String libPath = TestContext.getTempFile("target/lib", "recipe", ".jar").getAbsolutePath(); File file = new File(resourcePath, "hdfs-replication.properties"); OutputStream out = new FileOutputStream(file); props.setProperty("falcon.recipe.name", context.getProcessName()); props.setProperty("falcon.recipe.cluster.name", context.getClusterName()); props.setProperty("falcon.recipe.cluster.validity.end", context.getProcessEndTime()); props.setProperty("falcon.recipe.workflow.path", TestContext.class.getResource("/fs-workflow.xml").getPath()); props.setProperty("falcon.recipe.workflow.lib.path", new File(libPath).getParent()); props.setProperty("falcon.recipe.cluster.hdfs.writeEndPoint", "jail://global:00"); props.store(out, null); out.close(); recipePropertiesFilePath = file.getAbsolutePath(); }
From source file:org.apache.flex.compiler.config.Configuration.java
/** * @return Path of the target's parent directory. *///from w w w . j a v a 2 s .co m public String getTargetFileDirectory() { final String targetFile = getTargetFile(); if (targetFile == null) return null; final String normalizedTargetFile = FilenameNormalization.normalize(targetFile); return FilenameUtils.getFullPathNoEndSeparator(normalizedTargetFile); }
From source file:org.apache.maven.plugin.cxx.CMakeMojo.java
protected String generalizeDependencyFileName(String dependency, boolean bMavenDependency) { String sName = FilenameUtils.getName(dependency); String fullPath = FilenameUtils.getFullPathNoEndSeparator(dependency); String sGeneralizedName = baseNameAsSharedLibrary(sName, bMavenDependency); if (StringUtils.isEmpty(sGeneralizedName)) { sGeneralizedName = baseNameAsStaticLibrary(sName, bMavenDependency); }//from ww w . j a v a 2 s .com if (StringUtils.isEmpty(sGeneralizedName)) { sGeneralizedName = baseNameAsSharedModule(sName, bMavenDependency); } // $FB always use unix path separator with cmake even under windows ! return (bMavenDependency ? fullPath + "/" : "") + (StringUtils.isEmpty(sGeneralizedName) ? sName : sGeneralizedName); }
From source file:org.cruk.genologics.api.impl.GenologicsAPIImpl.java
/** * Upload a file to the Genologics file store. This always uses the SFTP protocol. * * @param fileURLResource The URL resource of the file on the local machine. * @param targetFile The GenologicsFile object that holds the reference to the * uploaded file, which was newly created using the API. * * @throws IOException if there is a problem with the transfer. * @throws IllegalStateException if the file store host name or credentials * are not set./*from w w w. j av a2 s.c o m*/ */ protected void uploadViaSFTP(URLInputStreamResource fileURLResource, GenologicsFile targetFile) throws IOException { GenologicsEntity entityAnno = checkEntityAnnotated(GenologicsFile.class); checkFilestoreSet(); Session<LsEntry> session = filestoreSessionFactory.getSession(); try { URI targetURL = targetFile.getContentLocation(); logger.info("Uploading {} over SFTP to {} on {}", fileURLResource.getURL().getPath(), targetURL.getPath(), targetURL.getHost()); String directory = FilenameUtils.getFullPathNoEndSeparator(targetURL.getPath()); if (!session.exists(directory)) { String[] directoryParts = directory.split("/+"); StringBuilder incrementalPath = new StringBuilder(directory.length()); for (int i = 1; i < directoryParts.length; i++) { incrementalPath.append('/').append(directoryParts[i]); String currentPath = incrementalPath.toString(); if (!session.exists(currentPath)) { boolean made = session.mkdir(currentPath); if (!made) { throw new IOException("Could not create file store directory " + directory); } } } } session.write(fileURLResource.getInputStream(), targetURL.getPath()); } finally { session.close(); } // Post the targetFile object back to the server to set the // "publish in lablink" flag and get the LIMS id and URI for the // file object. String filesUrl = getServerApiAddress() + entityAnno.uriSection(); ResponseEntity<GenologicsFile> response = restClient.postForEntity(filesUrl, targetFile, GenologicsFile.class); reflectiveUpdate(targetFile, response.getBody()); }
From source file:org.eclipse.thym.ios.core.pbxproject.PBXProject.java
private NSString searchPathForFile(PBXFile pbxfile) throws PBXProjectException { String filepath = FilenameUtils.getFullPathNoEndSeparator(pbxfile.getPath()); if (filepath.equals(".")) { filepath = ""; } else {/*from w w w.j a v a 2 s . co m*/ filepath = "/" + filepath; } NSDictionary group = getGroupByName("Plugins"); if (pbxfile.isPlugin() && group.containsKey("path")) { NSString groupPath = (NSString) group.objectForKey("path"); return NSObject.wrap("$(SRCROOT)/" + groupPath.getContent().replace('"', ' ').trim()); } else { return NSObject.wrap("$(SRCROOT)/" + getProductName() + filepath); } }
From source file:org.entando.entando.aps.system.services.storage.api.LocalStorageManagerInterface.java
public void addResource(JAXBStorageResource storageResource, Properties properties) throws ApiException, Throwable { try {/*from w w w.j a v a2 s . c o m*/ boolean isProtected = storageResource.isProtectedResource(); //validate parent directory; String path = StringUtils.removeEnd(storageResource.getName(), "/"); String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path); if (StringUtils.isNotBlank(parentFolder)) parentFolder = URLDecoder.decode(parentFolder, "UTF-8"); if (!StorageManagerUtil.isValidDirName(parentFolder)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager() .getAttributes(parentFolder, isProtected); if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } //validate exists BasicFileAttributeView basicFileAttributeView2 = this.getStorageManager().getAttributes(path, isProtected); if (null != basicFileAttributeView2) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "File already present", Response.Status.CONFLICT); } String filename = StringUtils.substringAfter(storageResource.getName(), parentFolder); if (storageResource.isDirectory()) { if (!StorageManagerUtil.isValidDirName(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT); } this.getStorageManager().createDirectory(storageResource.getName(), isProtected); } else { //validate file content if (!storageResource.isDirectory() && (null == storageResource.getBase64() || storageResource.getBase64().length == 0)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "A file cannot be empty", Response.Status.CONFLICT); } if (!StorageManagerUtil.isValidFilename(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename name", Response.Status.CONFLICT); } this.getStorageManager().saveFile(storageResource.getName(), isProtected, new ByteArrayInputStream(storageResource.getBase64())); } } catch (ApiException ae) { throw ae; } catch (Throwable t) { _logger.error("Error adding new storage resource", t); throw t; } }
From source file:org.entando.entando.aps.system.services.storage.api.LocalStorageManagerInterface.java
public void deleteResource(Properties properties) throws ApiException, Throwable { String pathValue = properties.getProperty(PARAM_PATH); String protectedValue = properties.getProperty(PARAM_IS_PROTECTED); boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true"); try {//w ww . ja v a 2s . c o m if (StringUtils.isNotBlank(pathValue)) pathValue = URLDecoder.decode(pathValue, "UTF-8"); String path = StringUtils.removeEnd(pathValue, "/"); String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path); BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager() .getAttributes(parentFolder, isProtected); if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } if (!StorageManagerUtil.isValidDirName(parentFolder)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT); } BasicFileAttributeView basicFileAttributeView = this.getStorageManager().getAttributes(pathValue, isProtected); if (null == basicFileAttributeView) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The file does not exists", Response.Status.CONFLICT); } String filename = StringUtils.substringAfter(pathValue, parentFolder); if (basicFileAttributeView.isDirectory()) { if (!StorageManagerUtil.isValidDirName(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT); } String recursiveDelete = properties.getProperty(PARAM_DELETE_RECURSIVE); boolean isRecursiveDelete = StringUtils.equalsIgnoreCase(recursiveDelete, "true"); if (!isRecursiveDelete) { String[] dirContents = this.getStorageManager().list(pathValue, isProtected); if (null != dirContents && dirContents.length > 0) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The directory is not empty", Response.Status.CONFLICT); } } this.getStorageManager().deleteDirectory(pathValue, isProtected); } else { //it's a file if (!StorageManagerUtil.isValidFilename(filename)) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename", Response.Status.CONFLICT); } this.getStorageManager().deleteFile(pathValue, isProtected); } } catch (ApiException ae) { throw ae; } catch (Throwable t) { _logger.error("Error adding new storage resource", t); throw t; } }
From source file:org.geotools.gce.imagecollection.ImageCollectionReader.java
/** * Setup collection configuration by checking for a properties file containing basic info such as * coverageName, relative path of the default image, expand RGB flag, timeBetweenChecks. * @throws FileNotFoundException/*w w w . jav a 2 s .c o m*/ */ private void loadConfig() throws FileNotFoundException { final String propertiesPath = rootPath + Utils.CONFIG_FILE; final File propertiesFile = new File(propertiesPath); String coverage = null; final boolean hasPropertiesFile = Utils.checkFileReadable(propertiesFile); if (hasPropertiesFile) { // // // // STEP 0: // Loading configuration from properties file // // // Properties props = new Properties(); FileInputStream fis = null; try { fis = new FileInputStream(propertiesFile); props.load(fis); coverage = initProperties(props); } catch (FileNotFoundException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the config file: " + propertiesPath, e); } } catch (IOException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the config file: " + propertiesPath, e); } } finally { if (fis != null) { try { fis.close(); } catch (Throwable t) { // Does nothing } } } } // // // // STEP 1: // Setting parameter which haven't been found in the property file // // // if (coverage == null) { coverageName = FilenameUtils.getBaseName(FilenameUtils.getFullPathNoEndSeparator(rootPath)); } else { coverageName = coverage; } if (defaultValues.path == null) { final File parent = new File(rootPath); final List<File> files; if (parent.exists() && parent.isDirectory() && parent.canRead()) { files = Utils.getFileList(parent, Utils.FILE_FILTER, true); if (!files.isEmpty()) { String path = files.get(0).getAbsolutePath(); defaultValues.path = path; if (path.startsWith(rootPath)) { defaultValues.path = path.substring(rootPath.length()); } } } } if (!hasPropertiesFile) { updatePropertiesFile(propertiesFile); } }
From source file:org.gradle.api.internal.externalresource.transport.sftp.SftpResourceUploader.java
private void ensureParentDirectoryExists(SftpClient client, String path) throws IOException { String directory = FilenameUtils.getFullPathNoEndSeparator(path); if (!directory.equals("") && client.lstat(directory) == null) { ensureParentDirectoryExists(client, directory); client.mkdir(directory);// w w w . ja v a 2 s . c o m } }
From source file:org.gradle.internal.resource.transport.sftp.SftpResourceUploader.java
private void ensureParentDirectoryExists(ChannelSftp channel, URI uri) { String parentPath = FilenameUtils.getFullPathNoEndSeparator(uri.getPath()); if (parentPath.equals("")) { return;//from ww w. java 2 s .co m } URI parent = uri.resolve(parentPath); try { channel.lstat(parentPath); return; } catch (com.jcraft.jsch.SftpException e) { if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) { throw new ResourceException(parent, String.format("Could not lstat resource '%s'.", parent), e); } } ensureParentDirectoryExists(channel, parent); try { channel.mkdir(parentPath); } catch (com.jcraft.jsch.SftpException e) { throw new ResourceException(parent, String.format("Could not create resource '%s'.", parent), e); } }