List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:eu.eexcess.domaindetection.wordnet.XwndReader.java
public void read(File file) throws IOException { String domain = FilenameUtils.getBaseName(file.getName()); File cacheFile = new File(file.getPath() + ".cache"); if (!cacheFile.exists()) { BinaryOutputStream bos = new BinaryOutputStream(new FileOutputStream(cacheFile)); System.out.println("Read in the Extended WordNet Domains file: " + file); LineIterator iterator = new LineIterator(new FileReader(file)); while (iterator.hasNext()) { String line = iterator.nextLine(); String[] tokens = line.split("\t"); String synset = tokens[0]; double weight = Double.parseDouble(tokens[1]); String[] ssid = synset.split("-"); int nr = Integer.parseInt(ssid[0]); POS pos = POS.getPOSForKey(ssid[1]); bos.writeInt(nr);//from w w w . j a v a2 s.c o m bos.writeSmallInt(pos.getId()); bos.writeInt(Float.floatToIntBits((float) weight)); } iterator.close(); bos.close(); } System.out.println("Read in the Extended WordNet Domains cache file: " + file); FileInputStream fStream = new FileInputStream(cacheFile); BinaryInputStream bis = new BinaryInputStream(fStream); while (bis.available() > 0) { int nr = bis.readInt(); int key = bis.readSmallInt(); POS pos = POS.getPOSForId(key); String synset = String.format("%08d-%s", nr, pos.getKey()); double weight = Float.intBitsToFloat(bis.readInt()); DomainAssignment assignment = new DomainAssignment(domain, weight); Set<DomainAssignment> domains = synsetToDomains.get(synset); if (domains == null) { domains = new TreeSet<DomainAssignment>(); synsetToDomains.put(synset, domains); } domains.add(assignment); } fStream.close(); bis.close(); }
From source file:ch.cyberduck.ui.cocoa.CreateSymlinkController.java
public CreateSymlinkController(final BrowserController parent, final Cache<Path> cache) { super(parent, cache, NSAlert.alert(LocaleFactory.localizedString("Create new symbolic link", "File"), StringUtils.EMPTY, LocaleFactory.localizedString("Create", "File"), null, LocaleFactory.localizedString("Cancel", "File"))); alert.setIcon(IconCacheFactory.<NSImage>get().aliasIcon(null, 64)); final Path selected = this.getSelected(); inputField.setStringValue(FilenameUtils.getBaseName(selected.getName())); this.setMessage(MessageFormat.format( LocaleFactory.localizedString("Enter the name for the new symbolic link for {0}:", "File"), selected.getName()));/* w w w .ja va2s . c om*/ }
From source file:com.frostwire.search.youtube.YouTubeCrawledSearchResult.java
YouTubeCrawledSearchResult(YouTubeSearchResult sr, LinkInfo video, LinkInfo audio) { super(sr);//w ww . j a v a 2 s . c o m this.video = video; this.audio = audio; this.filename = buildFilename(video, audio); this.displayName = FilenameUtils.getBaseName(this.filename); this.creationTime = audio != null ? audio.date.getTime() : video.date.getTime(); this.size = buildSize((int) sr.getSize(), video, audio); this.downloadUrl = buildDownloadUrl(video, audio); this.source = "YouTube - " + (audio != null ? audio.user : video.user); }
From source file:de.mpg.imeji.logic.storage.util.MediaUtils.java
/** * User imagemagick to convert any image into a jpeg * // w w w . jav a 2s.co m * @param bytes * @param extension * @throws IOException * @throws URISyntaxException * @throws InterruptedException * @throws IM4JavaException */ public static byte[] convertToJPEG(File tmp, String extension) throws IOException, URISyntaxException, InterruptedException, IM4JavaException { // In case the file is made of many frames, (for instance videos), generate only the frames from 0 to 48 to // avoid high memory consumption String path = tmp.getAbsolutePath() + "[0-48]"; ConvertCmd cmd = getConvert(); // create the operation, add images and operators/options IMOperation op = new IMOperation(); if (isImage(extension)) op.colorspace(findColorSpace(tmp)); op.strip(); op.flatten(); op.addImage(path); // op.colorspace("RGB"); File jpeg = File.createTempFile("uploadMagick", ".jpg"); try { op.addImage(jpeg.getAbsolutePath()); cmd.run(op); int frame = getNonBlankFrame(jpeg.getAbsolutePath()); if (frame >= 0) { File f = new File(FilenameUtils.getFullPath(jpeg.getAbsolutePath()) + FilenameUtils.getBaseName(jpeg.getAbsolutePath()) + "-" + frame + ".jpg"); return FileUtils.readFileToByteArray(f); } return FileUtils.readFileToByteArray(jpeg); } finally { removeFilesCreatedByImageMagick(jpeg.getAbsolutePath()); FileUtils.deleteQuietly(jpeg); } }
From source file:gobblin.util.recordcount.LateFileRecordCountProvider.java
/** * Construct filename for a late file. If the file does not exists in the output dir, retain the original name. * Otherwise, append a LATE_COMPONENT{RandomInteger} to the original file name. * For example, if file "part1.123.avro" exists in dir "/a/b/", the returned path will be "/a/b/part1.123.late12345.avro". *//*from ww w. ja va 2s.c o m*/ public Path constructLateFilePath(String originalFilename, FileSystem fs, Path outputDir) throws IOException { if (!fs.exists(new Path(outputDir, originalFilename))) { return new Path(outputDir, originalFilename); } return constructLateFilePath(FilenameUtils.getBaseName(originalFilename) + LATE_COMPONENT + new Random().nextInt(Integer.MAX_VALUE) + SEPARATOR + FilenameUtils.getExtension(originalFilename), fs, outputDir); }
From source file:com.esofthead.mycollab.module.file.servlet.UserAvatarHttpServletRequestHandler.java
@Override protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!StorageFactory.getInstance().isFileStorage()) { throw new MyCollabException("This servlet support file system setting only"); }/* www.j a v a 2 s. com*/ String path = request.getPathInfo(); if (path != null) { path = FilenameUtils.getBaseName(path); int lastIndex = path.lastIndexOf("_"); if (lastIndex > 0) { String username = path.substring(0, lastIndex); int size = Integer.valueOf(path.substring(lastIndex + 1, path.length())); FileStorage fileStorage = (FileStorage) StorageFactory.getInstance(); File avatarFile = fileStorage.getAvatarFile(username, size); InputStream avatarInputStream; if (avatarFile != null) { avatarInputStream = new FileInputStream(avatarFile); } else { String userAvatarPath = String.format("assets/icons/default_user_avatar_%d.png", size); avatarInputStream = UserAvatarHttpServletRequestHandler.class.getClassLoader() .getResourceAsStream(userAvatarPath); if (avatarInputStream == null) { LOG.error("Error to get avatar", new MyCollabException("Invalid request for avatar " + path)); return; } } response.setHeader("Content-Type", "image/png"); response.setHeader("Content-Length", String.valueOf(avatarInputStream.available())); try (BufferedInputStream input = new BufferedInputStream(avatarInputStream); BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream())) { byte[] buffer = new byte[8192]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } } else { LOG.error("Invalid path " + path); } } }
From source file:com.piketec.jenkins.plugins.tpt.Publish.java
/** * Publish the Junits results, it creates an XML file and write the results on it. * // w w w. j a v a 2s . c o m * @param jenkinsConfig * The configuration to which the TPT test resuklt should be tranformed to JUnit * @param testDataDir * The directory where TPT test data should be searched * @param jUnitOutputDir * The directory where the transformed results should be written to. * @param logger * to display the information * @param logLevel * the threshold for the severity of the log messages * @return the number of testcases . * @throws IOException * if an error occured while parsing TPT test data or writing the JUnit xml files * @throws InterruptedException * If the job was interrupted */ public static int publishJUnitResults(JenkinsConfiguration jenkinsConfig, FilePath testDataDir, FilePath jUnitOutputDir, TptLogger logger, LogLevel logLevel) throws IOException, InterruptedException { XmlStreamWriter xmlPub = null; try { String classname = FilenameUtils.getBaseName(jenkinsConfig.getTptFile()); FilePath jUnitXMLFile = new FilePath(jUnitOutputDir, classname + "." + jenkinsConfig.getConfigurationWithUnderscore() + ".xml"); xmlPub = new XmlStreamWriter(); xmlPub.initalize(jUnitXMLFile); xmlPub.writeTestsuite(classname); List<Testcase> testdata = getTestcases(testDataDir, logger); logger.info("Found " + testdata.size() + " test results."); for (Testcase tc : testdata) { if (tc.getLogEntries(LogLevel.ERROR).isEmpty() && "SUCCESS".equals(tc.getResult())) { xmlPub.writeTestcase(classname, tc.getQualifiedName(), tc.getExecDuration()); } else { StringBuilder log = new StringBuilder(); for (LogEntry entry : tc.getLogEntries(logLevel)) { if (log.length() > 0) { log.append('\n'); } log.append('[').append(entry.level.name()).append("] ").append(entry.message); } xmlPub.writeTestcaseError(classname, tc.getQualifiedName(), tc.getExecDuration(), log.toString()); } } return testdata.size(); } catch (XMLStreamException e) { throw new IOException("XML stream error: " + e.getMessage()); } catch (FactoryConfigurationError e) { throw new IOException("XML configuration error: " + e.getMessage()); } finally { if (xmlPub != null) { xmlPub.close(); } } }
From source file:MSUmpire.SpectrumParser.DIA_Setting.java
public void WriteDIASettingSerialization(String mzXMLFileName) { try {/* w w w.j av a2s. c om*/ Logger.getRootLogger().info("Writing DIA setting to file:" + FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser..."); FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser", false); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(this); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } }
From source file:com.legstar.cobc.AbstractTest.java
/** * This is our chance to remove reference files that are no longer used by a * test case. This happens when test cases are renamed or removed. *///w ww . j ava 2 s . co m protected void cleanOldReferences() { if (!getReferenceFolder().exists()) { return; } Method[] methods = getClass().getDeclaredMethods(); for (File refFile : FileUtils.listFiles(getReferenceFolder(), new String[] { REF_FILE_EXT }, false)) { boolean found = false; for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(FilenameUtils.getBaseName(refFile.getName()))) { found = true; break; } } if (!found) { refFile.delete(); } } }
From source file:dk.magenta.libreoffice.online.LOOLCheckFileInfoWebScript.java
public String getBaseFileName(NodeRef nodeRef) { String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); if (name != null) { return FilenameUtils.getBaseName(name); } else {/*w w w .j a v a 2 s.c om*/ return ""; } }