List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:edu.fullerton.ldvplugin.WplotManager.java
@Override public ArrayList<Integer> makePlot(ArrayList<ChanDataBuffer> dbuf, boolean compact) throws WebUtilException { try {/*from w w w . j a v a 2 s .co m*/ WplotDefinition wpd = new WplotDefinition(); wpd.init(); // make sure wplot's sample frequency <= acquired sample frequency String smplFrqName = wpd.getNamespace() + "_" + "smplfrq"; String[] sampleFrequency = paramMap.get(smplFrqName); if (sampleFrequency != null && sampleFrequency.length == 1) { try { String strFreq = sampleFrequency[0].trim(); if (!strFreq.matches("^\\d+$")) { throw new WebUtilException( String.format("Sample frequency (%1$s) is not an integer.", strFreq)); } Integer requested = Integer.parseInt(strFreq); Float rate = dbuf.get(0).getChanInfo().getRate(); if (requested > rate) { sampleFrequency[0] = String.format("%1$.0f", rate); paramMap.put(smplFrqName, sampleFrequency); } } catch (LdvTableException ex) { throw new WebUtilException("Making omega plot", ex); } } wpd.setFormParameters(paramMap); List<String> cmd = wpd.getCommandArray(dbuf, paramMap); String cmdStr = wpd.getCommandLine(dbuf, paramMap); if (!paramMap.containsKey("embed")) { vpage.add(cmdStr); vpage.addBlankLines(2); } ArrayList<Integer> ret = new ArrayList<>(); if (runExternalProgram(cmd, "")) { File outDir = wpd.getTempDir(); ArrayList<File> imgs = getAllImgFiles(outDir); for (File file : imgs) { String desc = getDescription(file); String mime = "image/" + FilenameUtils.getExtension(file.getAbsolutePath()); int imgId = importImage(file, mime, desc); if (imgId > 0) { ret.add(imgId); } } } else { int stat = getStatus(); String stderr = getStderr(); vpage.add(String.format("%1$s returned and error: %2$d", getProductName(), stat)); vpage.addBlankLines(1); PageItemString ermsg = new PageItemString(stderr, false); vpage.add(ermsg); } return ret; } catch (LdvTableException ex) { throw new WebUtilException("Making Omega plot", ex); } }
From source file:me.xingrz.finder.EntriesActivity.java
protected String mimeOfFile(File file) { String extension = FilenameUtils.getExtension(file.getName()); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); }
From source file:com.sonicle.webtop.core.bol.js.JsGridIMMessage.java
public static String toData(String filename, OutOfBandData oob) { if (oob == null) return ""; MapItem mi = new MapItem(); mi.add("url", oob.getUrl()); mi.add("mime", oob.getMime()); mi.add("ext", FilenameUtils.getExtension(filename)); mi.add("size", oob.getLength()); return JsonResult.GSON.toJson(mi); }
From source file:com.nuvolect.securesuite.util.OmniUtil.java
/** * Return a unique file given the current file as a model. * Example if file exists: /Picture/mypic.jpg > /Picture/mypic~.jpg * @return/*from w ww .j ava 2s. c om*/ */ public static OmniFile makeUniqueName(OmniFile initialFile) { String path = initialFile.getPath(); String basePath = FilenameUtils.getFullPath(path); // path without name String baseName = FilenameUtils.getBaseName(path); // name without extension String extension = FilenameUtils.getExtension(path); // extension String volumeId = initialFile.getVolumeId(); String dot = "."; if (extension.isEmpty()) dot = ""; OmniFile file = initialFile; while (file.exists()) { // LogUtil.log("File exists: "+file.getPath()); baseName += "~"; String fullPath = basePath + baseName + dot + extension; file = new OmniFile(volumeId, fullPath); } // LogUtil.log("File unique: "+file.getPath()); return file; }
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./*from ww w. j a v a2s .c o m*/ * * @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:io.dockstore.webservice.helpers.GitHubSourceCodeRepo.java
@Override public Tool findDescriptor(Tool c, String fileName) { String descriptorType = FilenameUtils.getExtension(fileName); Repository repository = null;//from w ww.jav a 2 s . c o m try { repository = service.getRepository(gitUsername, gitRepository); } catch (IOException e) { LOG.error(gitUsername + ": Repo: {} could not be retrieved", c.getGitUrl()); } if (repository == null) { LOG.info(gitUsername + ": Github repository not found for {}", c.getPath()); } else { LOG.info(gitUsername + ": Github found for: {}", repository.getName()); try { List<RepositoryContents> contents; contents = cService.getContents(repository, fileName); if (!(contents == null || contents.isEmpty())) { String content = extractGitHubContents(contents); // Add for new descriptor types // Grab important metadata from CWL file (expects file to have .cwl extension) if (descriptorType.equals("cwl")) { c = parseCWLContent(c, content); } if (descriptorType.equals("wdl")) { c = parseWDLContent(c, content); } // Currently only can pull name of task? or workflow from WDL // Add this later, should call parseWDLContent and use the existing Broad WDL parser } } catch (IOException ex) { LOG.info(gitUsername + ": Repo: {} has no descriptor file ", repository.getName()); } } return c; }
From source file:com.splunk.shuttl.archiver.importexport.BucketFileCreatorTest.java
@Test(expectedExceptions = { IllegalArgumentException.class }) public void _givenFileWithOtherExtension_throwIllegalArgumentException() { String otherExtension = getExtension() + "x"; File otherExtensionedFile = createTestFileWithName("file." + otherExtension); assertNotEquals(getExtension(), FilenameUtils.getExtension(otherExtensionedFile.getName())); bucketFileCreator.createBucketWithFile(otherExtensionedFile, null); }
From source file:com.seleniumtests.reporter.logger.Snapshot.java
/** * Rename HTML and PNG files so that they do not present an uuid * New name is <test_name>_<step_idx>_<snapshot_idx>_<step_name>_<uuid> * @param testStep/*from w w w . j ava 2s. c o m*/ * @param stepIdx number of this step * @param snapshotIdx number of this snapshot for this step * @param userGivenName name specified by user, rename to this name */ public void rename(final TestStep testStep, final int stepIdx, final int snapshotIdx, final String userGivenName) { String newBaseName; if (userGivenName == null) { newBaseName = String.format("%s_%d-%d_%s-", StringUtility.replaceOddCharsFromFileName(CommonReporter.getTestName(testStep.getTestResult())), stepIdx, snapshotIdx, StringUtility.replaceOddCharsFromFileName(testStep.getName())); } else { newBaseName = StringUtility.replaceOddCharsFromFileName(userGivenName); } if (screenshot.getHtmlSourcePath() != null) { String oldFullPath = screenshot.getFullHtmlPath(); String oldPath = screenshot.getHtmlSourcePath(); File oldFile = new File(oldPath); String folderName = ""; if (oldFile.getParent() != null) { folderName = oldFile.getParent().replace(File.separator, "/") + "/"; } String newName = newBaseName + FilenameUtils.getBaseName(oldFile.getName()); newName = newName.substring(0, Math.min(50, newName.length())) + "." + FilenameUtils.getExtension(oldFile.getName()); // if file cannot be moved, go back to old name try { oldFile = new File(oldFullPath); if (SeleniumTestsContextManager.getGlobalContext().getOptimizeReports()) { screenshot.setHtmlSourcePath(folderName + newName + ".zip"); oldFile = FileUtility.createZipArchiveFromFiles(Arrays.asList(oldFile)); } else { screenshot.setHtmlSourcePath(folderName + newName); } FileUtils.copyFile(oldFile, new File(screenshot.getFullHtmlPath())); new File(oldFullPath).delete(); } catch (IOException e) { screenshot.setHtmlSourcePath(oldPath); } } if (screenshot.getImagePath() != null) { String oldFullPath = screenshot.getFullImagePath(); String oldPath = screenshot.getImagePath(); File oldFile = new File(oldPath); String folderName = ""; if (oldFile.getParent() != null) { folderName = oldFile.getParent().replace(File.separator, "/") + "/"; } String newName = newBaseName + FilenameUtils.getBaseName(oldFile.getName()); newName = newName.substring(0, Math.min(50, newName.length())) + "." + FilenameUtils.getExtension(oldFile.getName()); screenshot.setImagePath(folderName + newName); // if file cannot be moved, go back to old name try { Files.move(Paths.get(oldFullPath), Paths.get(screenshot.getFullImagePath()), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { screenshot.setImagePath(oldPath); } } }
From source file:com.haulmont.cuba.web.filestorage.WebExportDisplay.java
/** * Show/Download resource at client side * * @param dataProvider ExportDataProvider * @param resourceName ResourceName for client side * @see com.haulmont.cuba.gui.export.FileDataProvider * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider *///from w ww. j a va2 s .co m @Override public void show(ExportDataProvider dataProvider, String resourceName) { String extension = FilenameUtils.getExtension(resourceName); ExportFormat format = ExportFormat.getByExtension(extension); show(dataProvider, resourceName, format); }