List of usage examples for org.apache.commons.io FilenameUtils getPathNoEndSeparator
public static String getPathNoEndSeparator(String filename)
From source file:com.robin.testcase.ApkResigner.java
private static String getUnderLinedPath(final String autFileCanonical) { return FilenameUtils.getPathNoEndSeparator(autFileCanonical).replaceAll("[\\\\/]", "_"); }
From source file:com.sencha.gxt.examples.resources.server.RelativeRemoteServiceServlet.java
/** * This serialization policy implementation loads from a server relative url * rather than from the fully qualified module base url provided by the client. * * @see RemoteServiceServlet#doGetSerializationPolicy(HttpServletRequest, String, String) */// w w w . j av a 2 s. com @Override protected SerializationPolicy doGetSerializationPolicy(HttpServletRequest request, String moduleBaseURL, String strongName) { // extract the module base name, which is always the last portion of the fully qualified url String moduleBaseName = FilenameUtils.getName(FilenameUtils.getPathNoEndSeparator(moduleBaseURL)); // construct a server relative url yes, this is legal: https://en.wikipedia.org/wiki/Uniform_Resource_Locator String moduleRelativeURL = request.getScheme() + ":" + request.getContextPath() + "/" + moduleBaseName + "/"; // load as normal, but using our server relative url instead of the fully qualified url return super.doGetSerializationPolicy(request, moduleRelativeURL, strongName); }
From source file:com.frostwire.search.AlbumCluster.java
/** * Try to extract album and artist from path. * * @param// ww w . ja v a 2 s .c om * @return */ /*public static final Pair<String, String> albumArtistFromPath(String filepath, String defaultAlbum, String defaultArtist) { String album = defaultAlbum; String artist = defaultArtist; if (!filepath.contains("/")) { // does not contain directory parts return ImmutablePair.of(album, artist); } ArrayList<String> dirs = new ArrayList<String>(Arrays.asList(filepath.split("/"))); if (dirs.get(0).equals("")) { dirs.remove(0); } if (dirs.size() > 0) { dirs.remove(dirs.size() - 1); } // strip disc subdirectory from list if (dirs.size() > 0) { String last = dirs.get(dirs.size() - 1); if (last.matches("(?is)(^|\\s)(CD|DVD|Disc)\\s*\\d+(\\s|$)")) { dirs.remove(dirs.size() - 1); } } if (dirs.size() > 0) { // for clustering assume %artist%/%album%/file or %artist% - %album%/file album = dirs.get(dirs.size() - 1); if (album.contains(" - ")) { String[] parts = album.split(" - "); artist = parts[0]; album = parts[1]; } else if (dirs.size() > 1) { artist = dirs.get(dirs.size() - 2); } } return ImmutablePair.of(album, artist); }*/ public LinkedList<TorrentCrawledAlbumSearchResult> detect(TorrentCrawlableSearchResult parent, List<? extends TorrentItemSearchResult> results) { LinkedList<TorrentCrawledAlbumSearchResult> albums = new LinkedList<TorrentCrawledAlbumSearchResult>(); Map<String, LinkedList<TorrentItemSearchResult>> dirs = new HashMap<String, LinkedList<TorrentItemSearchResult>>(); for (TorrentItemSearchResult sr : results) { String path = sr.getFilePath(); String dir = FilenameUtils.getPathNoEndSeparator(path); if (!dirs.containsKey(dir)) { dirs.put(dir, new LinkedList<TorrentItemSearchResult>()); } LinkedList<TorrentItemSearchResult> items = dirs.get(dir); items.add(sr); } for (Map.Entry<String, LinkedList<TorrentItemSearchResult>> kv : dirs.entrySet()) { int numAudio = 0; for (TorrentItemSearchResult sr : kv.getValue()) { String mime = MimeDetector.getMimeType(sr.getFilePath()); if (mime.startsWith("audio")) { numAudio++; } } // if (numAudio >= ALBUM_SIZE_THRESHOLD) { // Pair<String, String> p = albumArtistFromPath(kv.getKey(), "", ""); // TorrentCrawledAlbumSearchResult sr = new TorrentCrawledAlbumSearchResult(parent, p.getRight(), p.getLeft(), kv.getValue()); // System.out.println(sr); // albums.add(sr); // } } return albums; }
From source file:com.splunk.shuttl.archiver.archive.PathResolver.java
private String getParent(String bucketPath) { return FilenameUtils.getPathNoEndSeparator(bucketPath); }
From source file:de.monticore.io.paths.ModelCoordinateImpl.java
@Override public Path getPackagePath() { checkState(qualifiedPath != null, "The qualified path of the ModelCoordinate wasn't set."); return Paths.get(FilenameUtils.getPathNoEndSeparator(qualifiedPath.toString())); }
From source file:eu.chocolatejar.eclipse.plugin.cleaner.model.Artifact.java
private String getArtifactNameVersionAndLocation() { return "'" + getSymbolicName() + " #" + getVersion() + " @" + FilenameUtils.getPathNoEndSeparator(location.getPath()) + "'"; }
From source file:com.opengamma.component.OpenGammaComponentServer.java
/** * Extracts the server name.//from w w w . ja va 2s.c o m * <p> * This examines the first part of the file name and the last directory, * merging these with a dash. * * @param fileName the name to extract from, not null * @return the server name, not null */ protected String extractServerName(String fileName) { if (fileName.contains(":")) { fileName = StringUtils.substringAfter(fileName, ":"); } fileName = FilenameUtils.removeExtension(fileName); String first = FilenameUtils.getName(FilenameUtils.getPathNoEndSeparator(fileName)); String second = FilenameUtils.getName(fileName); if (StringUtils.isEmpty(first) || first.equals(second) || second.startsWith(first + "-")) { return second; } return first + "-" + second; }
From source file:fr.inria.atlanmod.neo4emf.neo4jresolver.runtimes.internal.Neo4JRuntimesManager.java
private String buildPackagesList(File directory) { Set<String> packages = new HashSet<>(); final String SEPARATOR = ", "; StringBuilder builder = new StringBuilder(); if (directory != null && directory.isDirectory()) { for (File file : directory.listFiles(new JarFilter())) { ZipInputStream zipStream = null; try { zipStream = new ZipInputStream(new FileInputStream(file)); ZipEntry entry;/*from w ww .j a va2 s . c om*/ while ((entry = zipStream.getNextEntry()) != null) { if (FilenameUtils.getExtension(entry.getName()).equals("class")) { packages.add(FilenameUtils.getPathNoEndSeparator(entry.getName()).replace('/', '.')); } } } catch (IOException e) { Logger.log(Logger.SEVERITY_ERROR, e); } finally { IOUtils.closeQuietly(zipStream); } } for (String pkg : packages) { builder.append(pkg); builder.append(SEPARATOR); } if (builder.length() >= SEPARATOR.length()) { builder.setLength(builder.length() - SEPARATOR.length()); } return builder.toString(); } else { return null; } }
From source file:org.apache.hive.ptest.execution.JIRAService.java
private static String parseAttachementId(String patch) { if (patch == null) { return ""; }/*from ww w. j a v a 2 s.com*/ String result = FilenameUtils.getPathNoEndSeparator(patch.trim()); if (result == null) { return ""; } result = FilenameUtils.getName(result.trim()); if (result == null) { return ""; } return result.trim(); }
From source file:org.bdval.ConsensusBDVModel.java
/** * Loads the juror models used for consensus. * @param options specific options to use when loading the model * @throws IOException if there is a problem accessing the model * @throws ClassNotFoundException if the type of the model is not recognized *//* w w w. j av a 2 s . c om*/ private void loadJurorModels(final DAVOptions options) throws IOException, ClassNotFoundException { jurorModels.clear(); final String pathToModel = FilenameUtils.getFullPath(modelFilename); final String endpointName = FilenameUtils.getBaseName(FilenameUtils.getPathNoEndSeparator(pathToModel)); if (properties.getBoolean("bdval.consensus.jurors.embedded", false)) { final File tmpdir = File.createTempFile("juror-models", ""); tmpdir.delete(); tmpdir.mkdir(); try { // load juror models from the zip file final ZipFile zipFile = new ZipFile(zipFilename); for (final String jurorPrefix : jurorModelFilenamePrefixes) { // zip files should always use "/" as a separator final String jurorFilename = "models/" + endpointName + "/" + jurorPrefix + ".zip"; LOG.debug("Loading juror model " + jurorFilename); final InputStream jurorStream = zipFile.getInputStream(zipFile.getEntry(jurorFilename)); final File jurorFile = new File(FilenameUtils.concat(tmpdir.getPath(), jurorFilename)); // put the juror model to disk so it can be loaded with existing code IOUtils.copy(jurorStream, FileUtils.openOutputStream(jurorFile)); final BDVModel jurorModel = new BDVModel(jurorFile.getPath()); jurorModel.load(options); jurorModels.add(jurorModel); } } finally { FileUtils.forceDeleteOnExit(tmpdir); } } else { // load juror models from disk final File finalModelPath = new File(pathToModel); final File finalModelParentPath = new File(finalModelPath.getParent()); // assume the model is under a directory "models" at the same level as a models // directory which contains the model components. for (final String jurorPrefix : jurorModelFilenamePrefixes) { final String modelComponentFilename = finalModelParentPath.getParent() + SystemUtils.FILE_SEPARATOR + "models" + SystemUtils.FILE_SEPARATOR + endpointName + SystemUtils.FILE_SEPARATOR + jurorPrefix; LOG.debug("Loading model component " + modelComponentFilename); final BDVModel jurorModel = new BDVModel(modelComponentFilename); jurorModel.load(options); jurorModels.add(jurorModel); } } if (jurorModels.size() < 1) { throw new IllegalStateException("No juror models could be found"); } jurorModelsAreLoaded = true; }