List of usage examples for org.apache.commons.io FilenameUtils normalize
public static String normalize(String filename)
From source file:ch.unibas.fittingwizard.infrastructure.RealFittabMarkerScript.java
@Override public FittabScriptOutput execute(FittabScriptInput input) { String moleculeName = getMoleculeName(input.getCubeFile()); File specificMoleculeDir = new File(moleculesDir, moleculeName); runner.setWorkingDir(specificMoleculeDir); List<String> args = Arrays.asList("-cube", input.getCubeFile().getAbsoluteFile().toString(), "-vdw", input.getVdwFile().getAbsoluteFile().toString(), "-pun", input.getLpunFile().getAbsoluteFile().toString()); File mtpFile = new File(specificMoleculeDir, FilenameUtils.removeExtension(input.getCubeFile().getName()) + MtpFittabExtension); runner.exec(fitTabMarkerScriptFile, args); if (!mtpFile.exists()) { throw new ScriptExecutionException("FittabMarker script did not create " + FilenameUtils.normalize(mtpFile.getAbsolutePath()) + " output file."); }/*from ww w.j ava2s . c o m*/ return new FittabScriptOutput(mtpFile); }
From source file:gov.nih.nci.cabig.caaers.service.adverseevent.AdditionalInformationDocumentService.java
public AdditionalInformationDocument uploadFile(String fileName, AdditionalInformation additionalInformation, InputStream inputStream, AdditionalInformationDocumentType additionalInformationDocumentType) { try {/*from ww w .j av a 2 s . co m*/ String aeAttachmentsLocation = configuration.get(Configuration.AE_ATTACHMENTS_LOCATION); String directory = FilenameUtils.normalize(aeAttachmentsLocation + "/" + additionalInformation.getId()); String extension = StringUtils.isNotBlank(FilenameUtils.getExtension(fileName)) ? "." + FilenameUtils.getExtension(fileName) : ""; String filePath = FilenameUtils.normalize(directory + "/" + FilenameUtils.getBaseName(fileName) + Calendar.getInstance().getTimeInMillis() + RandomUtils.nextInt(100) + extension); if (logger.isDebugEnabled()) { logger.debug(String.format("creating file %s of type %s for additional information %s at %s ", fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath)); } FileUtils.forceMkdir(new File(directory)); File file = new File(filePath); if (file.createNewFile()) { long bytesCopied = IOUtils.copyLarge(inputStream, new FileOutputStream(file)); AdditionalInformationDocument additionalInformationDocument = new AdditionalInformationDocument(); additionalInformationDocument .setAdditionalInformationDocumentType(additionalInformationDocumentType); additionalInformationDocument.setAdditionalInformation(additionalInformation); additionalInformationDocument.setFileId(DigestUtils.md5Hex(file.getAbsolutePath())); additionalInformationDocument.setOriginalFileName(fileName); additionalInformationDocument.setFileName(file.getName()); additionalInformationDocument.setFilePath(file.getCanonicalPath()); additionalInformationDocument.setRelativePath(file.getAbsolutePath()); additionalInformationDocument.setFileSize(bytesCopied); additionalInformationDocumentDao.save(additionalInformationDocument); if (logger.isDebugEnabled()) { logger.debug(String.format( "successfully created file %s of type %s for additional information %s at %s. File information is - %s ", fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath, additionalInformationDocument)); } return additionalInformationDocument; } else { String errorMessage = String.format( "error while creating file %s of type %s for additional information %s ", fileName, additionalInformationDocumentType, additionalInformation.getId()); throw new RuntimeException(errorMessage); } } catch (Exception e) { String errorMessage = String.format( "error while creating file %s of type %s for additional information %s ", fileName, additionalInformationDocumentType, additionalInformation.getId()); logger.error(errorMessage, e); return null; } }
From source file:net.sf.zekr.engine.server.HttpServer.java
public String toUrl(String localPath) { String normPath = FilenameUtils.normalize(localPath); for (Entry<String, String> entry : pathLookup.entrySet()) { String value = entry.getValue(); if (normPath.startsWith(value)) return getUrl() + entry.getKey() + "/" + FilenameUtils.separatorsToUnix(normPath.substring(value.length() + 1)); }//from w ww.jav a2 s .c om return ""; }
From source file:net.sourceforge.jencrypt.lib.FolderList.java
public FolderList(String topFolderString) { // Make relative pathname absolute topFolder = new File(new File(topFolderString).getAbsolutePath()); // If the path ends in a dot the archive will not have a top folder. if (topFolderString.charAt(topFolderString.length() - 1) == '.') { // Make the archive top folder equal to the top folder (i.e. don't // use an archive top folder) archiveTopFolder = topFolder.getPath(); } else {/*from w ww . j a v a2s . com*/ if (topFolder.isDirectory()) { archiveTopFolder = getParent(topFolder); } else throw new IllegalArgumentException("Parameter " + topFolder.getName() + " is not a folder"); } // Normalize (remove double and single dot path steps) archiveTopFolder = FilenameUtils.normalize(archiveTopFolder); }
From source file:com.textocat.textokit.commons.cpe.XmiFileListReader.java
@Override protected Iterable<Resource> getResources(UimaContext ctx) throws IOException { String baseDirPath = this.baseDirPath; baseDirPath = FilenameUtils.normalize(baseDirPath); // ensure that baseDirPath ends with slash for proper relative path handling if (!baseDirPath.endsWith(File.separator)) { baseDirPath += File.separator; }//from www . ja v a2s . co m baseDir = new FileSystemResource(baseDirPath); if (!baseDir.exists()) { throw new IllegalStateException(String.format("Directory %s does not exist", baseDir)); } List<String> lines = FileUtils.readLines(listFile, "utf-8"); resources = Lists.transform(Lists.newArrayList(Iterables.filter(lines, notBlankString)), relativeFileResourceFunc); return resources; }
From source file:com.frostwire.gui.updates.PortableUpdater.java
public PortableUpdater(File zipFile) { if (OSUtils.isWindows()) { createScript(PORTABLE_UPDATER_SCRIPT_WINDOWS); } else if (OSUtils.isMacOSX()) { createScript(PORTABLE_UPDATER_SCRIPT_MACOSX); }/* w ww. j a v a 2s . c o m*/ File rootFolder = CommonUtils.getPortableRootFolder(); this.zipFile = zipFile; this.tempDir = new File(FilenameUtils.normalize(new File(rootFolder, TEMP_DIR).getAbsolutePath())); this.destDir = new File(FilenameUtils.normalize(new File(rootFolder, getDestDirName()).getAbsolutePath())); }
From source file:com.izforge.izpack.core.rules.process.ExistsCondition.java
@Override public boolean isTrue() { boolean result = false; switch (contentType) { case VARIABLE: if (this.content != null) { String value = this.getInstallData().getVariable(this.content); if (value != null) { result = true;//www. j a v a 2 s .com } } break; case FILE: if (this.content != null) { Variables variables = getInstallData().getVariables(); File file = new File(FilenameUtils.normalize(variables.replace(this.content))); if (file.exists()) { result = true; } } break; default: logger.warning("Illegal content type '" + contentType.getAttribute() + "' of ExistsCondition"); break; } return result; }
From source file:com.izforge.izpack.core.rules.process.EmptyCondition.java
@Override public boolean isTrue() { boolean result = false; Variables variables = getInstallData().getVariables(); switch (contentType) { case STRING://from ww w .j a va 2 s .c om if (this.content == null) { return true; } String s = variables.replace(this.content); if (s != null && s.length() == 0) { result = true; } break; case VARIABLE: if (this.content != null) { String value = this.getInstallData().getVariable(this.content); if (value != null && value.length() == 0) { result = true; } } break; case FILE: if (this.content != null) { File file = new File(FilenameUtils.normalize(variables.replace(this.content))); if (!file.exists() && file.length() == 0) { result = true; } } break; case DIR: if (this.content != null) { File file = new File(FilenameUtils.normalize(variables.replace(this.content))); if (!file.exists() || file.isDirectory() && file.listFiles().length == 0) { result = true; } } break; default: logger.warning("Illegal content type '" + contentType.getAttribute() + "' of ExistsCondition"); break; } return result; }
From source file:com.igormaznitsa.mindmap.model.ExtraFile.java
public boolean hasParent(@Nonnull final File baseFolder, @Nonnull final MMapURI folder) { final File theFile = this.fileUri.asFile(baseFolder); final File thatFile = folder.asFile(baseFolder); final String theFilePath = FilenameUtils.normalize(theFile.getAbsolutePath()); final String thatFilePath = ensureFolderPath(FilenameUtils.normalize(thatFile.getAbsolutePath())); if (!theFilePath.equals(thatFilePath) && theFilePath.startsWith(thatFilePath)) { final String diff = theFilePath.substring(thatFilePath.length() - 1); return diff.startsWith("\\") || diff.startsWith("/"); } else {//from ww w .j a v a 2 s. com return false; } }
From source file:com.ewcms.publication.uri.UriRule.java
@Override public String getUri() throws PublishException { Assert.notNull(parameters);/*from w ww .ja v a2 s .c o m*/ Map<String, String> variables = ruleParse.getVariables(); if (variables.isEmpty()) { return ruleParse.getPatter(); } String uri = ruleParse.getPatter(); for (String name : variables.keySet()) { String format = variables.get(name); String exp = (format == null ? String.format("${%s}", name) : String.format("${%s?%s}", name, format)); Object value = getVariableValue(name, parameters); String formatValue = formatValue(value, format); uri = StringUtils.replace(uri, exp, formatValue); } uri = uri.replace("\\", "/").replace("//", "/"); return FilenameUtils.normalize(uri); }