List of usage examples for org.apache.commons.io FilenameUtils getName
public static String getName(String filename)
From source file:com.github.dokandev.dokanjava.samples.memoryfs.MemFileInfo.java
Win32FindData toWin32FindData() { return new Win32FindData(fileAttribute, creationTime, lastAccessTime, lastWriteTime, getFileSize(), 0, 0, FilenameUtils.getName(fileName), Utils.toShortName(fileName)); }
From source file:au.edu.uws.eresearch.cr8it.TransformationHandler.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *///from w w w . j av a 2 s .c om @Transformer public Message<String> handleFile(final Message<File> inputMessage) { final File inputFile = inputMessage.getPayload(); final String filename = inputFile.getName(); final String fileExtension = FilenameUtils.getExtension(filename); //populate this with json-ld data final String inputAsString; String finalString = ""; if ("zip".equals(fileExtension)) { inputAsString = getJsonData(inputFile, FilenameUtils.getName(filename)); try { finalString = getJsonMapping(inputAsString); } catch (IOException | ParseException e) { e.printStackTrace(); } if (finalString.length() > 0) { final Message<String> message = MessageBuilder.withPayload(finalString) .setHeader(FileHeaders.FILENAME, FilenameUtils.getBaseName(filename) + ".json") .setHeader(FileHeaders.ORIGINAL_FILE, inputFile) .setHeader("file_size", finalString.length()).setHeader("file_extension", "json").build(); return message; } else { System.out.println("Empty json string."); return null; } } else { System.out.println("Invalid file format"); return null; } }
From source file:jease.cms.web.content.editor.TransitEditor.java
private void pathSelected() { String pathname = (String) uri.getValue(); if (StringUtils.isNotBlank(pathname)) { String name = FilenameUtils.getName(pathname); if (StringUtils.isEmpty(id.getValue())) { id.setText(name);// ww w. ja v a2 s .c o m } if (StringUtils.isEmpty(title.getValue())) { title.setText(FilenameUtils.removeExtension(name)); } } }
From source file:brooklyn.entity.salt.SaltBashCommands.java
/** * Same as {@link #downloadAndExpandFormula(String, String)} with no formula name. * <p>//from www . j a va 2 s. co m * Equivalent to the following command, but substituting the given {@code sourceUrl}. * <pre>{@code * curl -f -L https://github.com/saltstack-formulas/nginx-formula/archive/master.tar.gz | tar xvz * }</pre> */ public static final String downloadAndExpandFormula(String sourceUrl) { String ext = Files.getFileExtension(sourceUrl); if ("tar".equalsIgnoreCase(ext)) return downloadToStdout(sourceUrl) + " | tar xv"; if ("tgz".equalsIgnoreCase(ext) || sourceUrl.toLowerCase().endsWith(".tar.gz")) return downloadToStdout(sourceUrl) + " | tar xvz"; String target = FilenameUtils.getName(sourceUrl); if (target == null) target = ""; else target = target.trim(); target += "_" + Strings.makeRandomId(4); if ("zip".equalsIgnoreCase(ext) || "tar.gz".equalsIgnoreCase(ext)) return BashCommands.chain(BashCommands.commandToDownloadUrlAs(sourceUrl, target), "unzip " + target, "rm " + target); throw new UnsupportedOperationException("No way to expand " + sourceUrl + " (yet)"); }
From source file:com.atlassian.theplugin.util.CodeNavigationUtil.java
/** * Get files from the provided collection which absolute path contains provided filePath * * @param filePath searched file path//from w ww . j av a2 s . c o m * @param psiFiles collection of files to search for filePath * @return collection of files matching provided filePath */ static Collection<PsiFile> getMatchingFiles(String filePath, final PsiFile[] psiFiles) { filePath = filePath.replace('\\', '/'); Collection<PsiFile> match = new ArrayList<PsiFile>(); if (psiFiles == null) { return match; } for (PsiFile psiFile : psiFiles) { String absolutePath = psiFile.getVirtualFile().getUrl(); absolutePath = absolutePath.replace('\\', '/'); if (absolutePath == null) { continue; } if (absolutePath.endsWith(FilenameUtils.getName(filePath)) && absolutePath.contains(filePath)) { match.add(psiFile); } } return match; }
From source file:control.UploadFile.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from w w w . j a v a 2s .c om boolean ismultipart = ServletFileUpload.isMultipartContent(request); if (!ismultipart) { } else { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; System.out.println(request); try { items = upload.parseRequest(request); } catch (Exception e) { } Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()) { } else { String itemname = item.getName(); if (itemname == null || itemname.equals("")) { continue; } String filename = FilenameUtils.getName(itemname); File f = checkExist(filename); item.write(f); request.getRequestDispatcher("/ideaCreated.jsp").forward(request, response); } } } } catch (Exception e) { } finally { out.close(); } }
From source file:WebstartLauncher.java
private String getLocalName(String jnlpUrl) { try {//w ww .jav a 2 s . c o m URL url = new File(System.getProperty("java.io.tmpdir") + "/" + FilenameUtils.getName(jnlpUrl)).toURL(); return url.getPath(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:edu.ku.brc.specify.rstools.ExportToFile.java
public void processDataList(List<?> data, Properties reqParams) throws Exception { DataExport exporter = buildExporter(reqParams); if (exporter != null) { final String name = FilenameUtils.getName(exporter.getConfig().getFileName()); final String msgKey = reqParams.getProperty("statusmsgkey") == null ? "EXPORTING_TO" : reqParams.getProperty("statusmsgkey"); final String doneMsgKey = reqParams.getProperty("statusdonemsgkey") == null ? "EXPORTING_DONE" : reqParams.getProperty("statusdonemsgkey"); final JStatusBar statusBar = UIRegistry.getStatusBar(); if (statusBar != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { statusBar.setText(/*from w ww . ja v a2 s. c o m*/ String.format(UIRegistry.getResourceString(msgKey), new Object[] { name })); } }); } try { exporter.writeData(data); if (statusBar != null) { SwingUtilities.invokeLater(new Runnable() { public void run() { statusBar.setText( String.format(UIRegistry.getResourceString(doneMsgKey), new Object[] { name })); } }); } } catch (IOException e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ExportToFile.class, e); throw (e); } } }
From source file:com.logsniffer.model.h2.H2SourceProvider.java
@Test public void testPersistence() throws IOException { final WildcardLogsSource source1 = new WildcardLogsSource(); source1.setName("Source 1"); source1.setPattern(new File("src/test/resources/logs", "log*.test").getPath()); Assert.assertEquals(1, source1.getLogs().size()); Assert.assertEquals("log1.test", FilenameUtils.getName(source1.getLogs().get(0).getPath())); final long id = sourceProvider.createSource(source1); Assert.assertEquals(true, id > 0); LogSource<LogRawAccess<?>> sourceCheck = sourceProvider.getSourceById(id); Assert.assertEquals(source1.getName(), sourceCheck.getName()); Assert.assertEquals(id, sourceCheck.getId()); Assert.assertEquals(1, sourceCheck.getLogs().size()); Assert.assertEquals("log1.test", FilenameUtils.getName(sourceCheck.getLogs().get(0).getPath())); source1.setName("Source 1x"); source1.setId(id);/*from ww w. j a v a 2 s . c om*/ sourceProvider.updateSource(source1); sourceCheck = sourceProvider.getSourceById(id); Assert.assertEquals("Source 1x", sourceCheck.getName()); }
From source file:de.mpg.imeji.logic.item.ItemController.java
@Override public List<Item> createBatch(List<Item> l, User user) throws ImejiException { Set<String> collectionIds = new HashSet<>(); for (final Item item : l) { if (!collectionIds.contains(item.getCollection().toString())) { // check if the collection exists. new CollectionService().retrieve(item.getCollection(), user); collectionIds.add(item.getCollection().toString()); }/*from ww w .j av a 2s . c o m*/ prepareCreate(item, user); item.setFilename(FilenameUtils.getName(item.getFilename())); } cleanItem(l); createMissingStatement(l); validateMetadata(l, Method.CREATE); WRITER.create(J2JHelper.cast2ObjectList(l), user); return null; }