List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:com.cognifide.cq.cqsm.core.scripts.ScriptUtils.java
public static String toJson(List<Script> scripts) { final List<Map<String, Object>> results = new ArrayList<>(); for (final Script script : scripts) { final HashMap<String, Object> result = new HashMap<>(); result.put("name", FilenameUtils.getBaseName(script.getPath())); result.put("path", script.getPath()); result.put("verified", script.isValid()); result.put("executionEnabled", script.isExecutionEnabled()); result.put("executionMode", script.getExecutionMode()); result.put("executionSchedule", script.getExecutionSchedule()); results.add(result);/*from w w w . j a va 2 s. co m*/ } return GSON.toJson(results); }
From source file:com.mycollab.module.file.servlet.UserAvatarHttpServletRequestHandler.java
@Override protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (SiteConfiguration.isDemandEdition()) { throw new MyCollabException("This servlet support file system setting only"); }/* w w w .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)); throw new ResourceNotFoundException("Invalid path " + path); } } 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 { throw new ResourceNotFoundException("Invalid path " + path); } } }
From source file:com.googlecode.dex2jar.tools.JarRemap.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();//from w w w . j a va2 s.com return; } File jar = new File(remainingArgs[0]); if (!jar.exists()) { System.err.println(jar + " is not exists"); usage(); return; } if (output == null) { if (jar.isDirectory()) { output = new File(jar.getName() + "-remap.jar"); } else { output = new File(FilenameUtils.getBaseName(jar.getName()) + "-remap.jar"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } System.out.println("remap " + jar + " -> " + output); new Renamer().from(jar).withConfig(config).to(output); }
From source file:ch.cyberduck.core.transfer.upload.RenameFilter.java
@Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if (status.isExists()) { final String filename = file.getName(); int no = 0; do {//from w ww . jav a 2s .c o m String proposal = String.format("%s-%d", FilenameUtils.getBaseName(filename), ++no); if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) { proposal += String.format(".%s", FilenameUtils.getExtension(filename)); } if (parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, proposal, file.getType())); } else { status.rename(new Path(file.getParent(), proposal, file.getType())); } } while (find.find(status.getRename().remote)); if (log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } if (log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } else { if (parent.getRename().remote != null) { status.rename(new Path(parent.getRename().remote, file.getName(), file.getType())); } if (log.isInfoEnabled()) { log.info(String.format("Changed upload target from %s to %s", file, status.getRename().remote)); } } return status; }
From source file:com.frostwire.search.limetorrents.LimeTorrentsSearchResult.java
LimeTorrentsSearchResult(String detailsUrl, SearchMatcher matcher) { this.detailsUrl = detailsUrl; this.infoHash = matcher.group("torrentid"); this.filename = parseFileName(matcher.group("filename")); this.size = parseSize(matcher.group("filesize") + " " + matcher.group("unit")); this.creationTime = parseCreationTime(matcher.group("time")); this.seeds = parseSeeds(matcher.group("seeds")); this.torrentUrl = "magnet:" + matcher.group("magnet_part"); this.displayName = HtmlManipulator.replaceHtmlEntities(FilenameUtils.getBaseName(filename)); }
From source file:mx.eersya.beans.CreateItemBean.java
public void savePicture() { try {/*from ww w. j a v a 2 s . c o m*/ Path path = Paths.get("/home/eersya/Projects/W/"); String filename = FilenameUtils.getBaseName(picture.getFileName()); String extension = FilenameUtils.getExtension(picture.getFileName()); Path file = Files.createTempFile(path, filename, "." + extension); picturePath = file.toString(); try (InputStream in = picture.getInputstream()) { Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING); } catch (IOException exa) { System.err.println(exa); } picturePath = file.toString(); System.out.println("Picture:" + picturePath); } catch (IOException ex) { System.err.println(ex); } }
From source file:com.kamike.misc.FsNameUtils.java
public static String getAttributeName(String prefix, String disk, String date, String name, String readableName, String fid, String uid, String extension) { String escapedName = FilenameUtils.getBaseName(name); StringBuffer buffer = new StringBuffer(); buffer.append(prefix);/* w w w .j av a 2 s . co m*/ buffer.append(disk); buffer.append('/'); buffer.append(uid); buffer.append('/'); buffer.append(date); buffer.append('/'); buffer.append(fid); buffer.append("/["); //?idid buffer.append(escapedName); buffer.append(']'); buffer.append(readableName); return buffer.toString(); }
From source file:com.googlecode.dex2jar.tools.Jar2Dex.java
@Override protected void doCommandLine() throws Exception { if (remainingArgs.length != 1) { usage();/* ww w. ja v a 2 s . co m*/ return; } File jar = new File(remainingArgs[0]); if (!jar.exists()) { System.err.println(jar + " is not exists"); usage(); return; } if (output == null) { if (jar.isDirectory()) { output = new File(jar.getName() + "-jar2dex.dex"); } else { output = new File(FilenameUtils.getBaseName(jar.getName()) + "-jar2dex.dex"); } } if (output.exists() && !forceOverwrite) { System.err.println(output + " exists, use --force to overwrite"); usage(); return; } File realJar; if (jar.isDirectory()) { realJar = File.createTempFile("d2j", ".jar"); realJar.deleteOnExit(); System.out.println("zipping " + jar + " -> " + realJar); OutHandler out = FileOut.create(realJar, true); try { new FileWalker().withStreamHandler(new OutAdapter(out)).walk(jar); } finally { IOUtils.closeQuietly(out); } } else { realJar = jar; } System.out.println("jar2dex " + realJar + " -> " + output); Class<?> c = Class.forName("com.android.dx.command.Main"); Method m = c.getMethod("main", String[].class); List<String> ps = new ArrayList<String>(); ps.addAll(Arrays.asList("--dex", "--no-strict", "--output=" + output.getCanonicalPath(), realJar.getCanonicalPath())); System.out.println("call com.android.dx.command.Main.main" + ps); m.invoke(null, new Object[] { ps.toArray(new String[0]) }); }
From source file:it.geosolutions.geobatch.settings.GBSettingsDAOXStreamImpl.java
public List<String> getIds() { List<String> ret = new ArrayList<String>(); final Iterator<File> it = FileUtils.iterateFiles(settingsDir, new String[] { ".xml" }, false); while (it.hasNext()) { File file = it.next();//from w ww . jav a 2s . co m String name = FilenameUtils.getBaseName(file.getName()); ret.add(name); } return ret; }
From source file:annis.administration.BinaryImportHelper.java
public BinaryImportHelper(File f, File dataDir, String toplevelCorpusName, long corpusRef, Map<String, String> mimeTypeMapping) { this.fileSource = f; // create a file-name in the form of "filename_toplevelcorpus_UUID.ending", thus we // need to split the file name into its components String baseName = FilenameUtils.getBaseName(fileSource.getName()); String extension = FilenameUtils.getExtension(fileSource.getName()); UUID uuid = UUID.randomUUID(); String outputName = ""; if (toplevelCorpusName == null) { outputName = baseName + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } else {//from w w w. jav a 2s.c o m outputName = baseName + "_" + CommonHelper.getSafeFileName(toplevelCorpusName) + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } fileDestination = new File(dataDir, outputName); String fileEnding = FilenameUtils.getExtension(f.getName()); if (mimeTypeMapping.containsKey(fileEnding)) { this.mimeType = mimeTypeMapping.get(fileEnding); } else { this.mimeType = new MimetypesFileTypeMap().getContentType(fileSource); } this.corpusRef = corpusRef; }