Example usage for org.apache.commons.io FilenameUtils getName

List of usage examples for org.apache.commons.io FilenameUtils getName

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getName.

Prototype

public static String getName(String filename) 

Source Link

Document

Gets the name minus the path from a full filename.

Usage

From source file:com.frostwire.search.ScrapedTorrentFileSearchResult.java

public ScrapedTorrentFileSearchResult(T parent, String filePath, long fileSize, String referrerUrl,
        String cookie) {//w  ww  .  jav a  2  s  . c o  m
    super(parent);
    this.filePath = filePath;
    this.filename = FilenameUtils.getName(this.filePath);
    this.displayName = FilenameUtils.getBaseName(this.filename);
    this.referrerUrl = referrerUrl;
    this.cookie = cookie;
    this.size = fileSize;
}

From source file:me.kartikarora.transfersh.activities.DownloadActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_download);

    final CoordinatorLayout layout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
    Intent intent = getIntent();//from   w w  w.ja  v  a  2 s. c  om
    url = intent.getData().toString();
    name = FilenameUtils.getName(url);
    type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url));
    TransferApplication application = (TransferApplication) getApplication();
    mTracker = application.getDefaultTracker();

    new AlertDialog.Builder(DownloadActivity.this)
            .setMessage(getString(R.string.download_file) + " " + getString(R.string.app_name) + "?")
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    checkForDownload(name, type, url, layout);
                    finish();
                }
            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                }
            }).create().show();

    mTracker.send(new HitBuilders.EventBuilder().setCategory("Activity : " + this.getClass().getSimpleName())
            .setAction("Launched").build());

}

From source file:com.iyonger.apm.web.model.FileEntry.java

public String getFileName() {
    return FilenameUtils.getName(checkNotEmpty(getPath()));
}

From source file:com.gitpitch.services.ImageService.java

public String buildBackgroundOffline(String md) {

    try {/*  w  ww.  ja  v  a  2  s .c  o m*/

        String frag = md.substring(MarkdownModel.MD_IMAGE_OPEN.length());
        String fragUrl = frag.substring(0, frag.indexOf("\""));
        String imageName = FilenameUtils.getName(fragUrl);
        String imageUrl = IMG_OFFLINE_DIR + imageName;

        return md.replace(fragUrl, imageUrl);
    } catch (Exception bex) {
    }

    return md;
}

From source file:com.frostwire.search.monova.MonovaSearchResult.java

public MonovaSearchResult(String detailsUrl, SearchMatcher matcher) {
    /*// w w  w. ja v a  2  s.co  m
     * Matcher groups cheatsheet
     * 1 -> .torrent URL
     * 2 -> infoHash
     * 3 -> seeds
     * 4 -> SIZE (B|KiB|MiBGiB)
     */
    this.detailsUrl = detailsUrl;
    this.filename = parseFileName(FilenameUtils.getName(matcher.group(1)));
    this.displayName = parseDisplayName(
            HtmlManipulator.replaceHtmlEntities(FilenameUtils.getBaseName(filename)));
    this.infoHash = matcher.group(5);
    this.creationTime = parseCreationTime(matcher.group(2));
    this.size = parseSize(matcher.group(4));
    this.seeds = parseSeeds(matcher.group(3));

    // Monova can't handle direct download of torrents without some sort of cookie
    //the torcache url wont resolve into direct .torrent
    this.torrentUrl = "magnet:?xt=urn:btih:" + infoHash;
}

From source file:ch.cyberduck.core.manta.MantaListService.java

@Override
public AttributedList<Path> list(final Path directory, final ListProgressListener listener)
        throws BackgroundException {
    final AttributedList<Path> children = new AttributedList<>();
    final Iterator<MantaObject> objectsIter;
    try {/*from  w w  w. j a va2  s. c  o  m*/
        objectsIter = session.getClient().listObjects(directory.getAbsolute()).iterator();
    } catch (MantaObjectException e) {
        throw new MantaExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (MantaClientHttpResponseException e) {
        throw new MantaHttpExceptionMappingService().map("Listing directory {0} failed", e, directory);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map("Listing directory {0} failed", e);
    }
    final MantaObjectAttributeAdapter adapter = new MantaObjectAttributeAdapter(session);
    while (objectsIter.hasNext()) {
        MantaObject o = objectsIter.next();
        final Path file = new Path(directory, FilenameUtils.getName(o.getPath()),
                EnumSet.of(o.isDirectory() ? Path.Type.directory : Path.Type.file), adapter.convert(o));
        children.add(file);
        listener.chunk(directory, children);
    }
    return children;
}

From source file:by.iharkaratkou.TestServlet.java

public String processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String filenameTimestamp = "";

    try {/*from  ww w  . j ava2  s  .  c om*/
        boolean ismultipart = ServletFileUpload.isMultipartContent(request);
        if (!ismultipart) {
            System.out.println("ismultipart is false");
        } else {
            System.out.println("ismultipart is true");
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;

            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);
                    System.out.println(filename);
                    File f = checkExist(filename);
                    item.write(f);
                    if (f.getName().contains(".xlsx")) {
                        filenameTimestamp = f.getName();
                    }
                }
            }
        }

    } catch (Exception e) {

    } finally {
        out.close();
    }
    return filenameTimestamp;
}

From source file:de.thischwa.pmcms.tool.image.ImageTool.java

public File getDialogPreview(final File srcImageFile, final Dimension previewDimension) {
    if (srcImageFile == null)
        return null;
    File destImageFile = new File(Constants.TEMP_DIR, "swt_dialog_preview".concat(File.separator)
            .concat(FilenameUtils.getName(srcImageFile.getAbsolutePath())));
    if (!destImageFile.getParentFile().exists())
        destImageFile.getParentFile().mkdirs();

    try {//  w w  w.jav a  2  s.  c  om
        if (destImageFile.exists())
            destImageFile.delete();
        imageManipulation.resize(srcImageFile, destImageFile, previewDimension);
    } catch (Exception e) {
        throw new FatalException("Error while resizing image!", e);
    }
    return destImageFile;
}

From source file:com.splunk.shuttl.archiver.archive.ArchiveConfigurationTest.java

public void getArchivingRoot_givenUriInMBean_childToTheUri() {
    String uriString = "valid:/uri";
    when(mBean.getArchiverRootURI()).thenReturn(uriString);
    URI actualUri = createConfiguration().getArchivingRoot();
    String childName = FilenameUtils.getName(actualUri.getPath());
    URI expectedUri = URI.create(uriString + "/" + childName);
    assertEquals(expectedUri, actualUri);
}

From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java

/**
 * Se encarga del proceso de exportacin de una refactorizacin dinmica.
 * //from  ww  w .  j a  v  a 2 s  . co m
 * @param destination
 *            directorio a donde se quiere exportar la refactorizacin.
 * @param definition
 *            ruta del fichero con la definicin de la refactorizacin.
 * @param createFolders
 *            indica si los ficheros .class se copian en al carpeta raz o
 *            si se genera la estructura de carpetas correspondiente.
 * @throws IOException
 *             IOException.
 * @throws XMLRefactoringReaderException
 *             XMLRefactoringReaderException.
 */
public static void exportRefactoring(String destination, String definition, boolean createFolders)
        throws IOException, XMLRefactoringReaderException {
    String folder = new File(definition).getParent();
    FileManager.copyFolder(folder, destination);
    String refactoringName = FilenameUtils.getName(folder);
    DynamicRefactoringDefinition refact = new JDOMXMLRefactoringReaderImp()
            .getDynamicRefactoringDefinition(new File(definition));

    FileManager.copyFile(new File(RefactoringConstants.DTD_PATH),
            new File(destination + "/" + refactoringName + "/"//$NON-NLS-1$
                    + new File(RefactoringConstants.DTD_PATH).getName()));

    for (RefactoringMechanismInstance mecanismo : refact.getAllMechanisms()) {

        String rule = PluginStringUtils.getMechanismFullyQualifiedName(mecanismo.getType(),
                mecanismo.getClassName());
        final String className = mecanismo.getClassName(); //$NON-NLS-1$

        String rulePath = rule.replace('.', File.separatorChar);

        File currentFile = new File(
                RefactoringConstants.REFACTORING_CLASSES_DIR + File.separatorChar + rulePath + ".class"); //$NON-NLS-1$
        File destinationFile = new File(
                destination + File.separatorChar + refactoringName + File.separatorChar + className + ".class"); //$NON-NLS-1$
        File destinationFolder = new File(destination);
        File newFolder = new File(
                destinationFolder.getParent() + File.separatorChar + new File(rulePath).getParent());
        File newFile = new File(new File(destination).getParent() + File.separatorChar + rulePath + ".class"); //$NON-NLS-1$

        // Si no existe el destino y si el actual
        if (!destinationFile.exists() && currentFile.exists()) {
            if (!createFolders) {
                FileManager.copyFile(currentFile, destinationFile);
            } else {
                if (!newFolder.exists()) {
                    newFolder.mkdirs();
                }
                FileManager.copyFile(currentFile, newFile);
            }
        } else {
            if (!currentFile.exists()) {
                // falta algn fichero .class necesario en esta
                // refactorizacin
                // En este caso se borra la carpeta generada en destino ya
                // que no estar completa
                FileManager.emptyDirectories(destination + File.separatorChar + refactoringName);
                FileManager.deleteDirectories(destination + File.separatorChar + refactoringName, true);
                throw new IOException(Messages.ExportImportUtilities_ClassesNotFound + currentFile.getPath());
            }

        }

    }

}