org.apache.commons.io.FilenameUtils#getFullPathNoEndSeparator ( )源码实例Demo

下面列出了org.apache.commons.io.FilenameUtils#getFullPathNoEndSeparator ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: vividus   文件: BddResourceLoader.java
@Override
public Resource getResource(String rawResourcePath)
{
    String parentDir = FilenameUtils.getFullPathNoEndSeparator(rawResourcePath);
    String fileName = FilenameUtils.getName(rawResourcePath);
    Resource[] resources = getResources(parentDir, fileName);
    if (resources.length > 1)
    {
        throw new ResourceLoadException("More than 1 resource is found for " + rawResourcePath);
    }
    if (resources.length == 0)
    {
        throw new ResourceLoadException("No resource is found for " + rawResourcePath);
    }
    return resources[0];
}
 
源代码2 项目: ghidra   文件: ImporterDialog.java
private boolean isFilenameTooLong() {
	int maxNameLen = tool.getProject().getProjectData().getMaxNameLength();
	String fullPath = getName();
	String currentPath = fullPath;
	while (!StringUtils.isBlank(currentPath)) {
		String filename = FilenameUtils.getName(currentPath);
		if (filename.isEmpty()) {
			return false;
		}
		if (filename.length() >= maxNameLen) {
			return true;
		}
		currentPath = FilenameUtils.getFullPathNoEndSeparator(currentPath);
	}
	return false;
}
 
源代码3 项目: thym   文件: PBXProject.java
private NSString searchPathForFile(PBXFile pbxfile) throws PBXProjectException {
	String filepath = FilenameUtils.getFullPathNoEndSeparator(pbxfile.getPath());
	if(filepath.equals(".")){
		filepath = "";
	}else{
		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 );
	}
}
 
源代码4 项目: ghidra   文件: ImporterDialog.java
private boolean isDuplicateFilename() {
	String pathFilename = getName();
	String parentPath = FilenameUtils.getFullPathNoEndSeparator(pathFilename);
	String filename = FilenameUtils.getName(pathFilename);
	DomainFolder localDestFolder =
		(parentPath != null) ? ProjectDataUtils.lookupDomainPath(destinationFolder, parentPath)
				: destinationFolder;
	if (localDestFolder != null) {
		if (localDestFolder.getFolder(filename) != null ||
			localDestFolder.getFile(filename) != null) {
			return true;
		}
	}
	return false;
}
 
源代码5 项目: ghidra   文件: ImportBatchTask.java
private Pair<DomainFolder, String> getDestinationInfo(BatchLoadConfig batchLoadConfig,
		DomainFolder rootDestinationFolder) {
	FSRL fsrl = batchLoadConfig.getFSRL();
	String pathStr = fsrlToPath(fsrl, batchLoadConfig.getUasi().getFSRL(), stripLeadingPath,
		stripAllContainerPath);
	String preferredName = batchLoadConfig.getPreferredFileName();

	String fsrlFilename = fsrl.getName();
	if (!fsrlFilename.equals(preferredName)) {
		pathStr = FSUtilities.appendPath(pathStr, preferredName);
	}
	// REGEX doc: match any character in the set ('\\', ':', '|') and replace with '/'
	pathStr = pathStr.replaceAll("[\\\\:|]+", "/");
	String parentDir = FilenameUtils.getFullPathNoEndSeparator(pathStr);
	if (parentDir == null) {
		parentDir = "";
	}
	String destFilename = FilenameUtils.getName(pathStr);
	try {
		DomainFolder batchDestFolder =
			ProjectDataUtils.createDomainFolderPath(rootDestinationFolder, parentDir);
		return new Pair<>(batchDestFolder, destFilename);
	}
	catch (InvalidNameException | IOException e) {
		Msg.error(this, "Problem creating project folder root: " +
			rootDestinationFolder.getPathname() + ", subpath: " + parentDir, e);
	}

	return new Pair<>(rootDestinationFolder, fsrlFilename);
}
 
源代码6 项目: pgptool   文件: MultipleFilesWatcher.java
public void watchForFileChanges(String filePathName) {
	try {
		String baseFolderStr = FilenameUtils.getFullPathNoEndSeparator(filePathName);
		String relativeFilename = FilenameUtils.getName(filePathName);

		synchronized (watcherName) {
			BaseFolder baseFolder = baseFolders.get(baseFolderStr);
			if (baseFolder != null) {
				log.debug("Parent directory is already being watched " + baseFolderStr
						+ ", will just add file to watch " + relativeFilename);
				baseFolder.interestedFiles.add(relativeFilename);
				return;
			}

			Path path = Paths.get(baseFolderStr);
			WatchKey key = path.register(watcher, ENTRY_DELETE, ENTRY_MODIFY, ENTRY_CREATE);
			baseFolder = new BaseFolder(baseFolderStr, key, path, relativeFilename);

			keys.put(key, baseFolder);
			baseFolders.put(baseFolderStr, baseFolder);

			log.debug("New watch key created for folder " + baseFolderStr + ", add first file " + relativeFilename);
		}
	} catch (Throwable t) {
		log.error("Failed to watch file " + filePathName, t);
		// not goinf to ruin app workflow
	}
}
 
源代码7 项目: pgptool   文件: MultipleFilesWatcher.java
public void stopWatchingFile(String filePathName) {
	try {
		String baseFolderStr = FilenameUtils.getFullPathNoEndSeparator(filePathName);
		String relativeFilename = FilenameUtils.getName(filePathName);

		synchronized (watcherName) {
			BaseFolder baseFolder = baseFolders.get(baseFolderStr);
			if (baseFolder == null) {
				log.debug("No associated watchers found for " + baseFolderStr);
				return;
			}

			baseFolder.interestedFiles.remove(relativeFilename);
			log.debug("File is no longer watched in folder " + baseFolderStr + " file " + relativeFilename);
			if (baseFolder.interestedFiles.size() > 0) {
				return;
			}

			// NOTE: Decided to turn this off, because file might re-appear in case it's app
			// re-created it. See #91, #75
			// keys.remove(baseFolder.key);
			// baseFolders.remove(baseFolder.folder);
			// baseFolder.key.cancel();
			// log.debug("Folder watch key is canceled " + baseFolderStr);
		}
	} catch (Throwable t) {
		log.error("Failed to watch file " + filePathName, t);
		// not goinf to ruin app workflow
	}
}
 
源代码8 项目: piper   文件: TempDir.java
@Override
public TypedValue execute (EvaluationContext aContext, Object aTarget, Object... aArguments) throws AccessException {
  String tmpDir = System.getProperty("java.io.tmpdir");
  if(tmpDir.endsWith(File.separator)) {
    tmpDir = FilenameUtils.getFullPathNoEndSeparator(tmpDir);
  }
  return new TypedValue(tmpDir);
}
 
源代码9 项目: logsniffer   文件: RollingLogsSource.java
protected Log[] getPastLogs(final String liveLog) throws IOException {
	final File dir = new File(FilenameUtils.getFullPathNoEndSeparator(liveLog));
	final String pastPattern = FilenameUtils.getName(liveLog) + getPastLogsSuffixPattern();
	final FileFilter fileFilter = new WildcardFileFilter(pastPattern);
	final File[] files = dir.listFiles(fileFilter);
	final FileLog[] logs = new FileLog[files.length];
	Arrays.sort(files, getPastLogsType().getPastComparator());
	int i = 0;
	for (final File file : files) {
		// TODO Decouple direct file log association
		logs[i++] = new FileLog(file);
	}
	logger.debug("Found {} past logs for {} with pattern {}", logs.length, liveLog, pastPattern);
	return logs;
}
 
源代码10 项目: datacollector   文件: FileEL.java
@ElFunction(
    prefix = "file",
    name = "parentPath",
    description = "Returns parent path to given file or directory. Returns path without separator (e.g. result will not end with slash)."
)
public static String parentPath (
  @ElParam("filePath") String filePath
) {
  if(isEmpty(filePath)) {
    return null;
  }
  return FilenameUtils.getFullPathNoEndSeparator(filePath);
}
 
源代码11 项目: ankush   文件: AgentConf.java
/**
 * Load the properties from the default file.
 * 
 * @throws IOException
 *             * @throws FileNotFoundException
 */
public void load() throws IOException {
	File file = new File(fileName);
	if (!file.exists()) {
		String confPath = FilenameUtils.getFullPathNoEndSeparator(fileName);
		FileUtils.forceMkdir(new File(confPath));
		FileUtils.touch(file);
	}
	this.properties = load(fileName);
}
 
源代码12 项目: ghidra   文件: ClassJar.java
private static boolean isPatchJar(String pathName) {
	String jarDirectory = FilenameUtils.getFullPathNoEndSeparator(pathName);
	return jarDirectory.equalsIgnoreCase(PATCH_DIR_PATH_FORWARD_SLASHED);
}
 
源代码13 项目: ghidra   文件: ProgramAnnotatedStringHandler.java
@Override
public boolean handleMouseClick(String[] annotationParts, Navigatable navigatable,
		ServiceProvider serviceProvider) {

	ProjectDataService projectDataService =
		serviceProvider.getService(ProjectDataService.class);
	ProjectData projectData = projectDataService.getProjectData();

	// default folder is the root folder
	DomainFolder folder = projectData.getRootFolder();

	// Get program name and folder from program comment annotation 
	// handles forward and back slashes and with and without first slash
	String programText = getProgramText(annotationParts);
	String programName = FilenameUtils.getName(programText);
	String path = FilenameUtils.getFullPathNoEndSeparator(programText);
	if (path.length() > 0) {
		path = StringUtils.prependIfMissing(FilenameUtils.separatorsToUnix(path), "/");
		folder = projectData.getFolder(path);
	}

	if (folder == null) {
		Msg.showInfo(getClass(), null, "No Folder: " + path,
			"Unable to locate folder by the name \"" + path);
		return true;
	}

	DomainFile programFile = findProgramByName(programName, folder);

	if (programFile == null) {
		Msg.showInfo(getClass(), null, "No Program: " + programName,
			"Unable to locate a program by the name \"" + programName +
				"\".\nNOTE: Program name is case-sensitive. ");
		return true;
	}

	SymbolPath symbolPath = getSymbolPath(annotationParts);
	navigate(programFile, symbolPath, navigatable, serviceProvider);

	return true;
}
 
源代码14 项目: pgptool   文件: EncryptOnePm.java
public SaveFileChooserDialog getTargetFileChooser() {
	if (targetFileChooser == null) {
		targetFileChooser = new SaveFileChooserDialog("action.chooseTargetFile", "action.choose", appProps,
				"EncryptionTargetChooser") {
			@Override
			protected String onDialogClosed(String filePathName, JFileChooser ofd) {
				String ret = super.onDialogClosed(filePathName, ofd);
				if (ret != null) {
					targetFile.setValueByOwner(ret);
				}
				return ret;
			}

			@Override
			protected void onFileChooserPostConstruct(JFileChooser ofd) {
				ofd.setAcceptAllFileFilterUsed(false);
				ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp"));
				// NOTE: Should we support other extensions?....
				ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter());
				ofd.setFileFilter(ofd.getChoosableFileFilters()[0]);
			}

			@Override
			protected void suggestTarget(JFileChooser ofd) {
				String sourceFileStr = sourceFile.getValue();
				if (StringUtils.hasText(targetFile.getValue())) {
					use(ofd, targetFile.getValue());
				} else if (encryptionDialogParameters != null
						&& encryptionDialogParameters.getTargetFile() != null) {
					if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) {
						use(ofd, encryptionDialogParameters.getTargetFile());
					} else {
						use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils
								.getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile())));
					}
				} else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) {
					String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr);
					ofd.setCurrentDirectory(new File(basePath));
					ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath)));
				}
			}

			private void use(JFileChooser ofd, String filePathName) {
				ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName)));
				ofd.setSelectedFile(new File(filePathName));
			}
		};
	}
	return targetFileChooser;
}
 
源代码15 项目: piper   文件: FilePath.java
@Override
public Object handle (TaskExecution aTask) {
  return FilenameUtils.getFullPathNoEndSeparator(aTask.getRequiredString("filename"));
}
 
源代码16 项目: TranskribusCore   文件: LocalDocReader.java
public static File findDefaultPageXmlForImage(String imagePath) {
	String folder = FilenameUtils.getFullPathNoEndSeparator(imagePath);
	String basename = FilenameUtils.getBaseName(imagePath);
	
	return findXml(basename, new File(folder+File.separator+LocalDocConst.PAGE_FILE_SUB_FOLDER), false);
}
 
public void addResource(JAXBStorageResource storageResource, Properties properties) throws Throwable {
try {
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;
}
  }
 
public void deleteResource(Properties properties) throws Throwable {
String pathValue = properties.getProperty(PARAM_PATH);
String protectedValue = properties.getProperty(PARAM_IS_PROTECTED);
boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true");
  	try {    	
  		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;
  	}
  }
 
private Variable appendBPELAssignOperationShScript(final BPELPlanContext templateContext,
                                                   final AbstractOperation operation,
                                                   final AbstractArtifactReference reference,
                                                   final AbstractImplementationArtifact ia) {

    final String runShScriptStringVarName = "runShFile" + templateContext.getIdForNames();

    // install ansible
    String runShScriptString =
        "sudo apt-add-repository -y ppa:ansible/ansible && sudo apt-get update && sudo apt-get install -y ansible";

    // install unzip
    runShScriptString += " && sudo apt-get install unzip";

    final String ansibleZipPath = templateContext.getCSARFileName() + "/" + reference.getReference();
    final String ansibleZipFileName = FilenameUtils.getName(ansibleZipPath);
    final String ansibleZipFolderName = FilenameUtils.getBaseName(ansibleZipFileName);
    final String ansibleZipParentPath = FilenameUtils.getFullPathNoEndSeparator(ansibleZipPath);

    // go into directory of the ansible zip
    runShScriptString += " && cd " + ansibleZipParentPath;

    // unzip
    runShScriptString += " && unzip " + ansibleZipFileName;

    final String playbookPath = getAnsiblePlaybookFilePath(templateContext);

    if (playbookPath == null) {

        LOG.error("No specified Playbook found in the corresponding ArtifactTemplate!");
    } else {

        LOG.debug("Found Playbook: {}", playbookPath);

        final String completePlaybookPath =
            ansibleZipFolderName + "/" + FilenameUtils.separatorsToUnix(playbookPath);
        final String playbookFolder = FilenameUtils.getFullPathNoEndSeparator(completePlaybookPath);
        final String playbookFile = FilenameUtils.getName(completePlaybookPath);

        // go into the unzipped directory
        runShScriptString += " && cd " + playbookFolder;

        // execute ansible playbook
        runShScriptString += " && ansible-playbook " + playbookFile;
    }

    final Variable runShScriptStringVar =
        templateContext.createGlobalStringVariable(runShScriptStringVarName, runShScriptString);

    return runShScriptStringVar;
}
 
源代码20 项目: ghidra   文件: AbstractLibrarySupportLoader.java
/**
 * Returns the path the loaded {@link ByteProvider} is located in.
 * <p>
 * Special case when the ByteProvider specifies a {@link FSRL}, try to get the 'real'
 * path on the local filesystem, otherwise return null.
 *
 * @param provider The {@link ByteProvider}.
 * @return The path the loaded {@link ByteProvider} is located in.
 */
private String getProviderFilePath(ByteProvider provider) {
	FSRL fsrl = provider.getFSRL();
	if ((fsrl != null) && !fsrl.getFS().hasContainer()) {
		return FilenameUtils.getFullPathNoEndSeparator(fsrl.getPath());
	}
	File f = provider.getFile();
	return (f != null) ? f.getParent() : null;
}