List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:net.fckeditor.tool.UtilsFile.java
/** * Iterates over a base name and returns the first non-existent file.<br /> * This method extracts a file's base name, iterates over it until the first * non-existent appearance with <code>basename(n).ext</code>. Where n is a * positive integer starting from one.// w w w. ja v a 2 s .c om * * @param file * base file * @return first non-existent file */ public static File getUniqueFile(final File file) { if (!file.exists()) return file; File tmpFile = new File(file.getAbsolutePath()); File parentDir = tmpFile.getParentFile(); int count = 1; String extension = FilenameUtils.getExtension(tmpFile.getName()); String baseName = FilenameUtils.getBaseName(tmpFile.getName()); do { tmpFile = new File(parentDir, baseName + "(" + count++ + ")." + extension); } while (tmpFile.exists()); return tmpFile; }
From source file:DIA_Umpire_To_Skyline.FileThread.java
private void ChangeScanTitlePepXML() throws FileNotFoundException, IOException { File fileEntry = new File(FilenameUtils.getFullPath(mzXMLFile)); String basename = FilenameUtils.getBaseName(mzXMLFile); for (File file : fileEntry.listFiles()) { if (file.isFile() && file.getAbsoluteFile().toString().toLowerCase().endsWith("pep.xml")) { String pepxmlbase = file.getName().split("\\.")[0]; if (pepxmlbase.equals(basename + "_Q1") || pepxmlbase.equals(basename + "_Q2") || pepxmlbase.equals(basename + "_Q3")) { BufferedReader reader = new BufferedReader(new FileReader(file)); String outputname = file.getName().replace("_Q", ".ForLibQ"); Logger.getRootLogger() .info("Writing new pepXML files and correct the scan titles: " + outputname); FileWriter writer = new FileWriter(FilenameUtils.getFullPath(mzXMLFile) + FilenameUtils.getBaseName(mzXMLFile) + "_Skyline/" + outputname); String line = ""; while ((line = reader.readLine()) != null) { writer.write(line.replaceAll(basename + "_Q", basename + ".ForLibQ") + "\n"); }/*from www .j av a2 s .c o m*/ writer.close(); } } } }
From source file:edu.umn.msi.tropix.webgui.server.ExportServiceImpl.java
@ServiceMethod() public void export(final String[] ids, final GridFtpServerOptions gridFtpOptions) { final TropixFile[] tropixFiles = fileService.getFiles(userSession.getGridId(), ids); final String host = gridFtpOptions.getHostname(); final int port = gridFtpOptions.getPort(); final Credential credential = userSession.getProxy(); LOG.info("GridFTP request to host and port " + host + " " + port); final GridFtpClient gridFtpClient = gridFtpFactory.getClient(host, port, credential); final String path = FilenameUtils.normalizeNoEndSeparator(gridFtpOptions.getPath()); try {//from w w w . j av a 2 s . c om LOG.debug("Attempting to create path " + path); gridFtpClient.makeDir(path); } catch (final RuntimeException e) { LOG.warn("Failed to make directory with path " + path + " proceeding anyway in case directory already exists.", e); } for (final TropixFile tropixFile : tropixFiles) { final StorageData data = storageDataFactory.getStorageData(tropixFile, credential); final String name = FilenameUtils.getBaseName(tropixFile.getName()); LOG.debug("Attempting to transfer file wit id " + tropixFile.getFileId() + " and name " + name); data.getDownloadContext().get(GridFtpClientUtils.getOutputContext(gridFtpClient, path + "/" + name)); } }
From source file:fr.inria.soctrace.tools.importer.pajedump.PajeDumpImporter.java
private String getNewTraceDBName(Set<String> usedNames, String traceFile) { String basename = FilenameUtils.getBaseName(traceFile); String extension = FilenameUtils.getExtension(traceFile); if (extension.equals(PJDumpConstants.TRACE_EXT)) { basename = basename.replace(PJDumpConstants.TRACE_EXT, ""); }//from ww w.j av a 2 s . co m final String traceDbName = FramesocManager.getInstance().getTraceDBName(basename); String realName = traceDbName; int n = 0; while (usedNames.contains(realName)) { System.out.println("tested " + realName); realName = traceDbName + "_" + n++; } usedNames.add(realName); return realName; }
From source file:ac.ucy.cs.spdx.parser.CaptureLicense.java
/** * Constructor for the {@link CaptureLicense} object. It initializes the * fields with the {@link SPDXDocument}, {@link SpdxPackage} and the * declared licenses expression via a {@link LicenseExpression} object. * /* w w w. j a v a 2 s. co m*/ * @return {@link CaptureLicense} */ public CaptureLicense(String path) throws IOException, InvalidSPDXAnalysisException, InvalidLicenseStringException { SpdxDocument spdxDoc = SPDXDocumentFactory.createSpdxDocument(path); SpdxPackage spdxPackage = spdxDoc.getSpdxPackage(); AnyLicenseInfo declared = LicenseInfoFactory .parseSPDXLicenseString(spdxPackage.getDeclaredLicense().toString()); this.setFileName(FilenameUtils.getBaseName(path)); this.setReferencedLicenses(new HashMap<String, String>()); for (ExtractedLicenseInfo exLicense : spdxDoc.getExtractedLicenseInfos()) { referencedLicenses.put(exLicense.getLicenseId(), exLicense.getName()); } this.captureDocument = spdxDoc; this.capturePackage = spdxPackage; this.captureLicenses = LicenseExpression.parseExpression(declared.toString(), this.referencedLicenses); }
From source file:gov.nih.nci.caarray.plugins.affymetrix.CdfHandler.java
/** * {@inheritDoc}/*from w w w .j av a 2 s. c o m*/ */ @Override protected String getArrayDesignName() { // the CDFData just reports the name of the file as the design name. but the name of the physical file // may not correspond to the original filename. instead get the name from the CaArrayFile, which will // be the original name return FilenameUtils.getBaseName(this.cdfFile.getName()); }
From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java
private void copyAuditComment(Comment comment, File commentDir) throws IOException, Ole10NativeException { switch (comment.getType()) { case PHOTO:/*from ww w .ja v a2 s.com*/ FileUtils.copyFileToDirectory(FileUtils.toFile(new URL(comment.getAttachment())), commentDir); break; case AUDIO: { String baseName = FilenameUtils.getBaseName(comment.getAttachment()); File from = FileUtils.toFile(new URL(comment.getAttachment())); File to = new File(commentDir, String.format("%s.bin", baseName)); createOleObject(from, to); break; } default: break; } }
From source file:edu.wisc.doit.tcrypt.ant.DecryptFileTask.java
@Override
String getFileName(String srcFileName) {
return FilenameUtils.getBaseName(srcFileName);
}
From source file:com.kegare.caveworld.core.Config.java
public static String getConfigName(Configuration config) { String name = FilenameUtils.getBaseName(config.toString()); if (name != null && name.startsWith("caveworld-")) { return name.substring(name.lastIndexOf('-') + 1); }// w w w. j a v a2 s . co m return null; }
From source file:com.googlecode.l10nmavenplugin.validators.property.SpellCheckValidator.java
/** * Initialize by loading dictionaries following {@link Locale} naming convention * /* w w w. j a v a 2s .com*/ * @param logger * @param directory * dictionaries location */ public SpellCheckValidator(L10nValidatorLogger logger, File directory) { super(logger); spellCheckerLocaleRepository = new LocaleTreeSpellCheckerRepository(logger); if (directory != null) { logger.getLogger().info("Looking for .dic files in: " + directory.getAbsolutePath()); File[] files = directory.listFiles((FilenameFilter) new SuffixFileFilter(".dic")); if (files == null || files.length == 0) { logger.getLogger().warn("No dictionary file under folder " + directory.getAbsolutePath() + ". Skipping spellcheck validation."); } else { // Load each dictionary, using file name to detect associated locale for (File file : files) { try { String fileName = FilenameUtils.getBaseName(file.getName()); String localePart = null; String[] parts = fileName.split("_", 2); if (parts[0].length() == 2) { localePart = fileName; } else if (parts.length == 2) { localePart = parts[1]; } Locale locale = PropertiesFileUtils.getLocale(localePart); logger.getLogger().info( "Loading file <" + file.getName() + "> associated to locale <" + locale + ">"); SpellDictionary dictionary = new SpellDictionaryHashMap(file); spellCheckerLocaleRepository.addDictionary(locale, dictionary); } catch (IOException e) { logger.getLogger().error(e); } } } } else { logger.getLogger().warn("No dictionary folder provided, skipping spellcheck validation."); } }