List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:com.liferay.sync.engine.util.FileUtil.java
public static boolean isValidFileName(String fileName) { if (StringUtils.isBlank(fileName)) { return false; }/*ww w .ja va 2 s.c om*/ for (String blacklistChar : PropsValues.SYNC_FILE_BLACKLIST_CHARS) { if (fileName.contains(blacklistChar)) { return false; } } for (String blacklistLastChar : PropsValues.SYNC_FILE_BLACKLIST_CHARS_LAST) { if (blacklistLastChar.startsWith("\\u")) { blacklistLastChar = StringEscapeUtils.unescapeJava(blacklistLastChar); } if (fileName.endsWith(blacklistLastChar)) { return false; } } String nameWithoutExtension = FilenameUtils.removeExtension(fileName); for (String blacklistName : PropsValues.SYNC_FILE_BLACKLIST_NAMES) { if (nameWithoutExtension.equalsIgnoreCase(blacklistName)) { return false; } } return true; }
From source file:com.textocat.textokit.corpus.statistics.dao.corpus.XmiFileTreeCorpusDAO.java
private URI getDocumentURI(File xmiFile) throws URISyntaxException { return new URI(FilenameUtils.removeExtension(xmiFile.getName())); }
From source file:com.alibaba.otter.shared.common.utils.extension.classpath.FileSystemClassScanner.java
private Class<?> scanInJar(String jarFileName, String className) { ZipFile zipfile = null;//from w ww. java 2s . c o m try { zipfile = new ZipFile(jarFileName); Enumeration<?> zipenum = zipfile.entries(); ZipEntry entry = null; String tempClassName = null; while (zipenum.hasMoreElements()) { entry = (ZipEntry) zipenum.nextElement(); tempClassName = entry.getName(); if (tempClassName.endsWith(".class")) { tempClassName = StringUtils.replace(FilenameUtils.removeExtension(tempClassName), "/", "."); if (tempClassName.equals(className)) { try { return fileClassLoader.loadClass(className); } catch (Exception ex) { logger.warn("WARN ## load this class has an error,the fileName is = " + className, ex); } } } } } catch (IOException ex) { logger.error(ex.getMessage(), ex); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException ex) { logger.warn(ex.getMessage(), ex); } } } return null; }
From source file:ca.on.oicr.pde.workflows.GATK3Workflow.java
@Override public Map<String, SqwFile> setupFiles() { List<String> inputFilesList = Arrays.asList(StringUtils.split(getProperty("input_files"), ",")); Set<String> inputFilesSet = new HashSet<>(inputFilesList); if (inputFilesList.size() != inputFilesSet.size()) { throw new RuntimeException("Duplicate files detected in input_files"); }/* w w w. j a va2 s. co m*/ if ((inputFilesSet.size() % 2) != 0) { throw new RuntimeException("Each bam should have a corresponding index"); } Map<String, String> bams = new HashMap<>(); Map<String, String> bais = new HashMap<>(); for (String f : inputFilesSet) { String fileExtension = FilenameUtils.getExtension(f); String fileKey = FilenameUtils.removeExtension(f); if (null != fileExtension) { switch (fileExtension) { case "bam": bams.put(fileKey, f); break; case "bai": bais.put(fileKey, f); break; default: throw new RuntimeException("Unsupported input file type"); } } } int id = 0; for (Entry<String, String> e : bams.entrySet()) { String key = e.getKey(); String bamFilePath = e.getValue(); String baiFilePath = bais.get(key); if (baiFilePath == null) { throw new RuntimeException("Missing index for " + FilenameUtils.getName(bamFilePath)); } SqwFile bam = this.createFile("file_in_" + id++); bam.setSourcePath(bamFilePath); bam.setType("application/bam"); bam.setIsInput(true); SqwFile bai = this.createFile("file_in_" + id++); bai.setSourcePath(baiFilePath); bai.setType("application/bam-index"); bai.setIsInput(true); //FIXME: this seems to work for now, it would be better to be able to set the provisionedPath as //bai.getProvisionedPath != bai.getOutputPath ... //at least with seqware 1.1.0, setting output path changes where the output file will be stored, //but the commonly used get provisioned path will return the incorrect path to the file bai.setOutputPath(FilenameUtils.getPath(bam.getProvisionedPath())); inputBamFiles.add(bam.getProvisionedPath()); } return this.getFiles(); }
From source file:de.bund.bfr.knime.gis.GisUtils.java
public static CoordinateReferenceSystem getCoordinateSystem(String shpFile) throws InvalidPathException, MalformedURLException, IOException, FactoryException, NoSuchFileException { try (Stream<String> stream = Files .lines(KnimeUtils.getFile(FilenameUtils.removeExtension(shpFile) + ".prj").toPath())) { return CRS.parseWKT(stream.collect(Collectors.joining())); }//from ww w. j a va 2s. c om }
From source file:com.googlesource.gerrit.plugins.rabbitmq.config.PluginProperties.java
@Override public String getName() { if (propertiesFile != null) { Path path = propertiesFile.getFileName(); if (path != null) { return FilenameUtils.removeExtension(path.toString()); }/*w w w . j a va 2s . c o m*/ } return null; }
From source file:de.unidue.ltl.integration.mekaMultiLabel.MultiLabelOutcomeAnnotator.java
public Set<String> getTextClassificationOutcomes(JCas jcas) throws CollectionException { Set<String> outcomes = new HashSet<String>(); DocumentMetaData dmd = DocumentMetaData.get(jcas); String titleWithoutExtension = FilenameUtils.removeExtension(dmd.getDocumentTitle()); if (!goldLabelMap.containsKey(titleWithoutExtension)) { throw new CollectionException(new Throwable("No gold label for document: " + dmd.getDocumentTitle())); }//from w ww.j a v a 2 s . c om for (String label : goldLabelMap.get(titleWithoutExtension)) { outcomes.add(label); } return outcomes; }
From source file:com.nuvolect.securesuite.webserver.connector.CmdDuplicate.java
@Override public InputStream go(@NonNull Map<String, String> params) { String url = params.get("url"); String suffix = "~"; /**/*from www . ja v a 2 s.c o m*/ * Params only has the first element of the targets[] array. * This is fine if there is only one target but an issue for multiple file operations. * Manually parse the query parameter strings to get all targets. */ String[] qps = params.get("queryParameterStrings").split("&"); JsonArray added = new JsonArray(); boolean hasFailed = false; for (String candidate : qps) { if (!candidate.contains("targets")) { continue; } String[] parts = candidate.split("="); OmniFile fromFile = new OmniFile(parts[1]); String toPath = fromFile.getPath(); OmniFile toFile = null; for (int dupCount = 0; dupCount < 10; dupCount++) { // add no more than 10 tilda toFile = new OmniFile(fromFile.getVolumeId(), toPath); if (!toFile.exists()) { break; } String extension = FilenameUtils.getExtension(toPath);// add ~ to filename, keep extension if (!extension.isEmpty()) { extension = "." + extension; } toPath = FilenameUtils.removeExtension(toPath) + suffix; toPath = toPath + extension; } LogUtil.log(LogUtil.LogType.CMD_DUPLICATE, "file path: " + fromFile.getPath()); LogUtil.log(LogUtil.LogType.CMD_DUPLICATE, "file exists: " + fromFile.exists()); boolean success; if (fromFile.isDirectory()) { success = OmniFiles.copyDirectory(fromFile, toFile); } else { success = OmniFiles.copyFile(fromFile, toFile); } /** * If there's just only one fail, set this to include warning */ hasFailed = hasFailed || !success; /** * Duplicate files have a new name, so update the modification time to present */ toFile.setLastModified(System.currentTimeMillis() / 1000); if (success) { added.add(FileObj.makeObj(toFile, url));// note: full depth of directory not added } else { LogUtil.log(LogUtil.LogType.CMD_DUPLICATE, "Duplicate failed: " + toFile.getPath()); } } JsonObject wrapper = new JsonObject(); if (hasFailed) { JsonArray warning = new JsonArray(); warning.add("errPerm"); wrapper.add("warning", warning); } else { wrapper.add("added", added); } if (DEBUG) { LogUtil.log(LogUtil.LogType.CMD_DUPLICATE, "json result: " + wrapper.toString()); } return getInputStream(wrapper); }
From source file:de.nbi.ontology.test.OntologyIndexTest.java
/** * Test, if isPrefix(*) works./*w w w. j a va2 s .c om*/ * * @param inFile * an ontology * @throws IOException */ @SuppressWarnings("unchecked") @Test(dataProviderClass = TestFileProvider.class, dataProvider = "prefixTestFiles", groups = { "functest" }) public void isPrefix(File inFile) throws IOException { log.info("Processing " + inFile.getName()); String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath()); File txtFile = new File(basename + ".txt"); index.reset(); index.load(new FileInputStream(inFile)); List<String> prefixes = FileUtils.readLines(txtFile); for (String p : prefixes) { log.trace("** checking " + p); Assert.assertTrue(index.isPrefix(p)); Assert.assertTrue(index.isPrefix(Arrays.asList(StringUtils.split(p)))); } }
From source file:ch.cern.dss.teamcity.agent.util.ArchiveExtractor.java
/** * @param archivePath/*from ww w . jav a 2 s. c o m*/ * @return * @throws IOException * @throws InterruptedException */ public String rpm2cpio(String archivePath) throws IOException, InterruptedException { Loggers.AGENT.debug("Converting to cpio: " + archivePath); String cpioPath = FilenameUtils.removeExtension(archivePath) + ".cpio"; String[] rpm2cpioCommand = { "/bin/sh", "-c", "/usr/bin/rpm2cpio " + archivePath + " > " + cpioPath }; SystemCommandResult result = IOUtil.runSystemCommand(rpm2cpioCommand); Loggers.AGENT.debug("rpm2cpio returned with code " + result.getReturnCode()); return cpioPath; }