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.gui.library.DeviceUploadTask.java

@Override
public void run() {
    if (!isRunning()) {
        return;/*from w w  w  .j ava  2  s  .c o  m*/
    }

    try {
        setProgress(0);

        totalBytes = getTotalBytes();
        totalWritten = 0;

        for (int i = 0; i < fds.length; i++) {
            if (!isRunning()) {
                return;
            }

            currentFD = fds[i];
            final String name = FilenameUtils.getName(currentFD.filePath);

            GUIMediator.safeInvokeLater(new Runnable() {
                public void run() {
                    LibraryMediator.instance().getLibrarySearch().pushStatus(
                            String.format("%s to %s - %s", I18n.tr("Uploading"), device.getName(), name));
                }
            });

            device.upload(new File(currentFD.filePath), token, new ProgressFileEntityListener() {
                public void onWrite(ProgressFileEntity progressFileEntity, int written) {
                    totalWritten += written;
                    setProgress((int) ((totalWritten * 100) / totalBytes));

                    if (getProgress() % 5 == 0) {
                        GUIMediator.safeInvokeLater(new Runnable() {
                            public void run() {
                                String status = String.format("%d%% %s to %s - %s", getProgress(),
                                        I18n.tr("Uploading"), device.getName(), name);
                                LibraryMediator.instance().getLibrarySearch().pushStatus(status);
                            }
                        });
                    }
                }

                public boolean isRunning() {
                    return DeviceUploadTask.this.isRunning();
                }
            });
        }

        setProgress(100);
    } catch (Throwable e) {
        onError(e);
    } finally {
        GUIMediator.safeInvokeLater(new Runnable() {
            public void run() {
                LibraryMediator.instance().getLibrarySearch().revertStatus();
            }
        });
    }

    stop();
}

From source file:com.atlassian.theplugin.idea.ui.tree.file.BambooFileNode.java

public BambooFileNode(BambooFileInfo file, AtlassianClickAction action, PsiFile psiFile) {
    super(FilenameUtils.getName(file.getFileDescriptor().getUrl()), action);
    this.file = file;
    this.psiFile = psiFile;
}

From source file:de.uzk.hki.da.pkg.ZipArchiveBuilder.java

/**
 * WARN this is actually implemented with /usr/bin/jar instead of /usr/bin/unzip.
 * See implementation notes at {@link de.uzk.hki.da.pkg.ArchiveBuilder#unarchiveFolder(File, File)}.
 */// w w w.ja v  a 2 s. co  m
public void unarchiveFolder(File srcTar, File destFolder) throws Exception {

    logger.debug("moving {} to folder {}", srcTar, destFolder);
    FileUtils.copyFileToDirectory(srcTar, destFolder, false);

    ProcessInformation pi = new CommandLineConnector().runCmdSynchronously(
            new String[] { "/usr/bin/jar", "-xf", FilenameUtils.getName(srcTar.getAbsolutePath()) }, destFolder,
            0);

    if ((pi == null) || (pi.getExitValue() != 0)) {
        if (pi != null)
            logger.error(pi.getStdErr());
        throw new RuntimeException("Couldnt unpack package");
    }

    new File(destFolder.getAbsolutePath() + "/" + FilenameUtils.getName(srcTar.getAbsolutePath())).delete();
}

From source file:com.cognifide.cq.cqsm.core.models.FileModel.java

public FileModel(Script script) {
    this.fileName = FilenameUtils.getName(script.getPath());
    this.author = script.getAuthor();
    this.path = script.getPath();
    this.valid = script.isValid();

    this.lastModified = script.getLastModified();
    this.lastExecuted = script.getExecutionLast();
    this.dryRunSuccessful = script.isDryRunSuccessful();
    this.dryRunExecuted = script.isDryRunExecuted();
    this.executionMode = script.getExecutionMode().name();
    this.executionEnabled = script.isExecutionEnabled();
    this.executionSchedule = script.getExecutionSchedule();
}

From source file:com.GTDF.server.Transxchange2GoogleTransitServiceImpl.java

public String transxchange2GoogleTransit_transform(String inArgs) {

    String rootDirectory = getServletConfig().getInitParameter("TRANSFORM_HOME");
    String workDirectory = getServletConfig().getInitParameter("TRANSFORM_DIR");
    int maxargs = 5;
    String[] args = new String[maxargs];
    int argv = 0;
    String result = "";
    TransxchangeHandler handler = null;// w w  w .  ja va  2s.  c  om

    /*
    * Parse input string to extract arguments (similar command line arguments)
    */
    StringTokenizer st = new StringTokenizer(inArgs, " ");
    while (st.hasMoreTokens() && argv < maxargs) {
        args[argv] = st.nextToken();
        argv++;
    }
    if (argv < maxargs) // Don't let in if too few arguments
        return "Not enough arguments. Required: <url> <timezone> <default route type> <output-directory>";

    String outdir = "";
    if (argv == 5)
        outdir = args[4];

    /*
       * Parse transxchange input file
       */
    String fileName = FilenameUtils.getName(args[0]);

    try {
        handler = new TransxchangeHandler();
        handler.parse(rootDirectory + workDirectory + '/' + outdir + '/' + fileName, args[1], args[2], args[3],
                rootDirectory, workDirectory + '/' + outdir);
    } catch (Exception e) {
        return e.getMessage();
    }

    /*
     * Create Google Transit output files
     */
    try {
        result = handler.writeOutput(rootDirectory, workDirectory + '/' + outdir);
    } catch (Exception e) {
        return e.getMessage();
    }

    /*
     * Success - create return message
     */
    String hostedOn = getServletConfig().getInitParameter("HOSTED_ON");
    return "Created Google Transit Data Feed Spec archive at: " + hostedOn + result;
}

From source file:net.sf.zekr.engine.server.DefaultHttpServer.java

public void run() {
    try {/*from w  w  w.  ja  va 2  s.c  o  m*/
        logger.info("Starting HTTP server...");
        final boolean denyRemoteAccess = props.getBoolean("server.http.denyRemoteAccess", true);
        httpFacade = new NanoHttpd(getServerPort(), denyRemoteAccess) {
            public Response serve(String uri, String method, Properties header, Properties parms) {
                if (!hasAccessPermission(uri)) {
                    return new Response(HTTP_FORBIDDEN, MIME_PLAINTEXT, "Access denied.");
                }
                if (Boolean.valueOf(props.getString("server.http.log")).booleanValue())
                    logger.debug("serving URI: " + uri);
                String path = toRealPath(uri.substring(1));
                if (!new File(path).exists())
                    return new Response(HTTP_NOTFOUND, MIME_PLAINTEXT, "File not found.");
                String baseDir = FilenameUtils.getFullPath(path);
                String fileName = FilenameUtils.getName(path);
                return serveFile(fileName, header, new File(baseDir), false);
            }

            private boolean hasAccessPermission(String uri) {
                if (denyRemoteAccess) {
                    return true;
                } else {
                    return isAllowedUri(uri);
                }
            }

            private boolean isAllowedUri(String uri) {
                return (uri.indexOf("..") == -1) && (uri.indexOf(":/") == -1) && (uri.indexOf(":\\") == -1);
            }
        };
        logger.info("HTTP server is listening on: " + getUrl());
    } catch (IOException ioe) {
        logger.error("HTTP server cannot be started due to the next error.");
        logger.implicitLog(ioe);
        return;
    }
    //      while (true) {
    //         try {
    //            // do nothing, there is a separate waiting thread for each request.
    //            Thread.sleep(1000);
    //         } catch (InterruptedException e) {
    //            logger.info("HTTP Server terminated.");
    //         }
    //      }
}

From source file:com.github.cbismuth.fdupes.collect.PathAnalyser.java

public Optional<Path> getTimestampPath(final Path destination, final Path path) {
    final Optional<Path> result;

    final String name = FilenameUtils.getName(path.toString());

    final Matcher matcher_1 = PATTERN_1.matcher(name);
    if (matcher_1.matches()) {
        result = Optional.of(onMatch(destination, matcher_1));
    } else {//from   w ww.ja v a2 s.co m
        final Matcher matcher_2 = PATTERN_2.matcher(name);
        if (matcher_2.matches()) {
            result = Optional.of(onMatch(destination, matcher_2));
        } else {
            LOGGER.warn("File [{}] doesn't match pattern", path);

            result = Optional.empty();
        }
    }

    return result;
}

From source file:ldn.cInicio.java

public String traePostInicio(int id) {
    String src = "";
    BD.cDatos sql = new BD.cDatos(bd);
    try {/*from w ww .j a  v a  2s  . c o m*/
        sql.conectar();
        ResultSet gatito = sql.consulta("call _traepostinicio(" + id + ");");
        while (gatito.next()) {
            src += "<div class=\"container containerPub\" data-regis='" + gatito.getString("idCuenta") + "'>";
            src += "<div>";

            src += "<span id='spName'>Usuario: " + gatito.getString("usuario") + "</span><br /><br />";
            src += "<span id='imgSrc'><img src=\"" + gatito.getString("foto")
                    + "\" width=\"50\" height=\"50\"></span><br /><br />";
            src += "<span id='spInte'>Interes: " + gatito.getString("interes") + "</span><br /><br />";

            src += "<span id='spTit'>" + gatito.getString("titulo") + "</span><br /><br />";
            src += "<span id='spTxt'>" + gatito.getString("texto") + "</span><br />";
            if (!reformat(gatito.getString("imagenpost")).isEmpty())
                src += "<div class=\"apart\"><img width=10% height=10% src=\"" + gatito.getString("imagenpost")
                        + "\"><br /><span id='spCab'>" + gatito.getString("cabeceraimagenpost")
                        + "</span></div><br />"; //+gatito.getString("cabeceraaudiopost")+

            if (!reformat(gatito.getString("audiopost")).isEmpty())
                src += "<div class=\"apart\"><a id='audio' href=\"" + gatito.getString("audiopost")
                        + "\" download=\"" + FilenameUtils.getName(gatito.getString("audiopost"))
                        + "\"><button id='cabAudio' class='seguir' >Descargar archivo adjunto</button></div></a></br>";
            src += "<button id='verPerfil' class='seguir' onclick='verPerfil(this)' >Ver perfil</button>";

            src += "</div></div><br /><br />";
        }
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        this.error = sw.toString();
    }
    return src;
}

From source file:net.sf.jvifm.control.CopyCommand.java

protected void doFileOperator(String src, String dst, String fileName) throws Exception {
    if (Thread.currentThread().isInterrupted())
        return;//from   www.  ja  va2 s .c om
    String baseName = FilenameUtils.getName(src);
    updateStatusInfo("copying file " + baseName);
    // if is same file, make a copy
    if (fileModelManager.isSameFile(src, dst)) {
        dst = FilenameUtils.concat(dst,
                FilenameUtils.getBaseName(src) + "(1)." + FilenameUtils.getExtension(src));
        new File(dst).createNewFile();
    }
    fileModelManager.cp(src, dst);
}

From source file:com.frostwire.android.gui.transfers.DesktopTransfer.java

DesktopTransfer(TransferManager manager, DesktopUploadRequest dur, FileDescriptor fd) {
    this.manager = manager;
    this.dur = dur;
    this.fd = fd;
    this.dateCreated = new Date();

    this.savePath = new File(SystemUtils.getDesktopFilesirectory(), FilenameUtils.getName(fd.filePath));
    this.items = new ArrayList<DesktopTransferItem>();

    addFileDescriptor(fd);//  w w  w . ja  v a  2  s  . c  om

    status = STATUS_TRANSFERRING;
}