List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:de.dentrassi.pm.aspect.common.CoreAspectFactory.java
private static void makeMetadata(final Extractor.Context context, final Map<String, String> metadata) throws IOException { metadata.put(KEY_NAME, context.getName()); metadata.put(KEY_EXT, FilenameUtils.getExtension(context.getName())); metadata.put(KEY_BASENAME, FilenameUtils.getBaseName(context.getName())); metadata.put(KEY_ISO_TIMESTAMP, context.getCreationTimestamp().toString()); metadata.put(KEY_TIMESTAMP,/*from w w w. j a va 2 s. c o m*/ TIMESTAMP_FORMATTER.format(context.getCreationTimestamp().atOffset(ZoneOffset.UTC))); }
From source file:hudson.plugins.simpleupdatesite.Plugin.java
private String getExcerpt(File hpiFile) { try {/*from w w w . j a v a 2s.com*/ String baseName = FilenameUtils.getBaseName(hpiFile.getName()); File exceptFile = new File(hpiFile.getParent(), baseName + ".info"); if (exceptFile.exists()) { return FileUtils.readFileToString(exceptFile, "UTF-8"); } else { return ""; } } catch (Exception e) { return ""; } }
From source file:com.intuit.tank.script.TestUploadBean.java
/** * Saves the script in the database./* ww w . jav a2 s . c om*/ */ public String save() { UploadedFile item = getFile(); try { String fileName = item.getFileName(); fileName = FilenameUtils.getBaseName(fileName) + "-" + UUID.randomUUID().toString() + "." + FilenameUtils.getExtension(fileName); File parent = new File("uploads"); parent.mkdirs(); File f = new File(parent, fileName); LOG.info("Writing file to " + f.getAbsolutePath()); FileUtils.writeByteArrayToFile(f, item.getContents()); messages.info("Wrote file to " + f.getAbsolutePath()); } catch (Exception e) { messages.error(e.getMessage()); } return null; }
From source file:info.bonjean.beluga.util.ResourcesUtil.java
public static Image getSVGImage(String resource) throws IOException { SVGUniverse universe = SVGCache.getSVGUniverse(); URI uri = universe.loadSVG(Notification.class.getResourceAsStream(resource), SVG_NAME_PREFIX + FilenameUtils.getBaseName(resource)); return new Drawing(universe.getDiagram(uri, true)); }
From source file:it.attocchi.utils.HttpClientUtils.java
/** * /* w w w . j a v a 2 s . co m*/ * @param url * un url dove scaricare il file * @param urlFileNameParam * specifica il parametro nell'url che definisce il nome del * file, se non specificato il nome corrisponde al nome nell'url * @param dest * dove salvare il file, se non specificato crea un file * temporaneo * @return * @throws ClientProtocolException * @throws IOException */ public static File getFile(String url, String urlFileNameParam, File dest) throws ClientProtocolException, IOException { DefaultHttpClient httpclient = null; HttpGet httpget = null; HttpResponse response = null; HttpEntity entity = null; try { httpclient = new DefaultHttpClient(); url = url.trim(); /* Per prima cosa creiamo il File */ String name = getFileNameFromUrl(url, urlFileNameParam); String baseName = FilenameUtils.getBaseName(name); String extension = FilenameUtils.getExtension(name); if (dest == null) dest = File.createTempFile(baseName + "_", "." + extension); /* Procediamo con il Download */ httpget = new HttpGet(url); response = httpclient.execute(httpget); entity = response.getEntity(); if (entity != null) { OutputStream fos = null; try { // var fos = new // java.io.FileOutputStream('c:\\temp\\myfile.ext'); fos = new java.io.FileOutputStream(dest); entity.writeTo(fos); } finally { if (fos != null) fos.close(); } logger.debug(fos); } } catch (Exception ex) { logger.error(ex); } finally { // org.apache.http.client.utils.HttpClientUtils.closeQuietly(httpClient); // if (entity != null) // EntityUtils.consume(entity); // try { if (httpclient != null) httpclient.getConnectionManager().shutdown(); } catch (Exception ex) { logger.error(ex); } } return dest; }
From source file:com.streamsets.pipeline.stage.origin.spooldir.TestOffsetUtil.java
private static Map<String, String> removeAbsolutePaths(Map<String, String> offsetV2) { Map<String, String> resultMap = new HashMap<>(); for (Map.Entry<String, String> entry : offsetV2.entrySet()) { if (entry.getKey().contains(PATH_SEPARATOR)) { String filename = new StringJoiner(".").add(FilenameUtils.getBaseName(entry.getKey())) .add(FilenameUtils.getExtension(entry.getKey())).toString(); resultMap.put(filename, entry.getValue()); } else {//from www .j av a2 s.c om resultMap.put(entry.getKey(), entry.getValue()); } } return resultMap; }
From source file:fr.tpt.atlanalyser.tests.generic.GenericExecTest.java
@Test public void test() throws IOException { File atlOutputFile = new File(atlOutputDir, FilenameUtils.getBaseName(inputModel.getPath()) + "_atl.xmi"); Resource atlOutput = applyAtlTransformation(inputModel.getPath(), atlOutputFile.getPath()); File henshinOutputFile = new File(henshinOutputDir, FilenameUtils.getBaseName(inputModel.getPath()) + "_henshin.xmi"); Resource henshinOutput = applyHenshinTransformation(inputModel.getPath(), henshinOutputFile.getPath()); compareModels(atlOutput, henshinOutput); }
From source file:cu.uci.uengine.comparators.DataSetFileComparator.java
@Override public int compare(File fileA, File fileB) { int fileANumber, fileBNumber; try {/* ww w. j a va2s. co m*/ fileANumber = RegexUtils.getDataSetNumber(fileA); } catch (InvalidDataSetNameException ex) { log.error(String.format("Invalid dataSet Name: %s. %s", fileA.getAbsolutePath(), ex.getMessage())); fileANumber = Integer.MAX_VALUE;//Max value push filename to the end } try { fileBNumber = RegexUtils.getDataSetNumber(fileB); } catch (InvalidDataSetNameException ex) { log.error(String.format("Invalid dataSets Name: %s. %s", fileB.getAbsolutePath(), ex.getMessage())); if (fileANumber == Integer.MAX_VALUE) { //If both filename are wrong sort by estndar lexicografical order return FilenameUtils.getBaseName(fileA.getName()) .compareTo(FilenameUtils.getBaseName(fileB.getName())); } else { fileBNumber = Integer.MAX_VALUE; } } return fileANumber - fileBNumber;//Max value push filename to the end }
From source file:com.sisrni.managedbean.EditorImages.java
public void uploadListener(FileUploadEvent event) { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); String fileName = FilenameUtils.getName(event.getFile().getFileName()); String fileNamePrefix = FilenameUtils.getBaseName(fileName) + "_"; String fileNameSuffix = "." + FilenameUtils.getExtension(fileName); File uploadFolder = new File("/var/webapp/uploads"); try {/*from www . ja va 2 s .co m*/ File result = File.createTempFile(fileNamePrefix, fileNameSuffix, uploadFolder); FileOutputStream fileOutputStream = new FileOutputStream(result); byte[] buffer = new byte[1024]; int bulk; InputStream inputStream = event.getFile().getInputstream(); while (true) { bulk = inputStream.read(buffer); if (bulk < 0) { break; } fileOutputStream.write(buffer, 0, bulk); fileOutputStream.flush(); } fileOutputStream.close(); inputStream.close(); String value = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap() .get("editor_input"); setText(value + "<img src=\"/rais/uploads/" + result.getName() + "\" />"); RequestContext.getCurrentInstance().update("editor_input"); FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded."); FacesContext.getCurrentInstance().addMessage(null, msg); } catch (IOException e) { e.printStackTrace(); FacesMessage error = new FacesMessage("The files were not uploaded!"); FacesContext.getCurrentInstance().addMessage(null, error); } }
From source file:com.frostwire.search.academictorrents.AcademicTorrentsCrawledSearchResult.java
public AcademicTorrentsCrawledSearchResult(AcademicTorrentsSearchResult sr, AcademicTorrentsFile file) { super(sr);// www . j a v a 2 s . c o m this.filename = file.filename; this.displayName = FilenameUtils.getBaseName(filename) + " (" + sr.getDisplayName() + ")"; this.downloadUrl = String.format(Locale.US, DOWNLOAD_URL, sr.getDomainName(), sr.getIdentifier(), filename); this.size = calcSize(file); }