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

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

Introduction

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

Prototype

public static String getPath(String filename) 

Source Link

Document

Gets the path from a full filename, which excludes the prefix.

Usage

From source file:edu.ur.file.db.DefaultFileDatabase.java

/**
 * Set the path of the folder. This makes no changes to the children
 * folders. The path must be a full path and cannot be relative. The path
 * must also include the prefix i.e. C:/ (for windows) or / (for unix).
 * /*from w  w  w.  j  a  v a  2 s. c om*/
 * 
 * This converts the paths to the correct path immediately / for *NIX and \
 * for windows.
 * 
 * @param path
 */
void setPath(String path) {

    path = FilenameUtils.separatorsToSystem(path.trim());

    // add the end separator
    if (path.charAt(path.length() - 1) != IOUtils.DIR_SEPARATOR) {
        path = path + IOUtils.DIR_SEPARATOR;
    }

    // get the prefix
    prefix = FilenameUtils.getPrefix(path).trim();

    // the prefix cannot be null.
    if (prefix == null || prefix.equals("")) {
        throw new IllegalArgumentException("Path must have a prefix");
    }

    this.path = FilenameUtils.getPath(path);

}

From source file:dev.agustin.serializer.MainWindow.java

private void load3dFile() {
    int state = getJFileChooser().showOpenDialog(this);
    if (state == JFileChooser.APPROVE_OPTION) {
        File f = getJFileChooser().getSelectedFile();
        try {//from   w  ww  .ja v  a 2s.  c o m
            BufferedReader br = new BufferedReader(new FileReader(f));
            String fileExtension = FilenameUtils.getExtension(f.getName());
            this.saveDirectory = FilenameUtils.getPath(f.getPath());
            if (fileExtension.compareToIgnoreCase("3ds") == 0) {
                //3ds file, load in the engine
                try {
                    this.objectArray = Loader.load3DS(f.getCanonicalPath(), 1);
                } catch (Exception ex) {
                    System.out.print(ex.getMessage());
                }
            } else if (fileExtension.compareToIgnoreCase("obj") == 0) {
                //obj file
                try {
                    String mtlFile = f.getCanonicalPath().replace(".obj", ".mtl");
                    this.objectArray = Loader.loadOBJ(f.getCanonicalPath(), mtlFile, 1);
                } catch (Exception ex) {
                    System.out.println("ERROR LOADING MATERIAL! trying without material");
                    System.out.print(ex.getMessage());
                    try {
                        this.objectArray = Loader.loadOBJ(f.getCanonicalPath(), null, 1);
                    } catch (Exception ex2) {
                        System.out.println("Error loading object, aborting.");
                        System.out.print(ex.getMessage());
                    }
                }
            } else {
                System.out.println("Error loading file " + f.getName() + " not a 3D Studio (.3DS) file");
            }
            br.close();
            setTitle(title);
            hasChanged = false;
            System.out.println("Now dumping textures names:");
            Enumeration<String> textures = TextureManager.getInstance().getNames();
            while (textures.hasMoreElements()) {
                System.out.println(textures.nextElement());
            }
            System.out.println("Done.");
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:com.iyonger.apm.web.handler.ScriptHandler.java

/**
 * Get the base path of the given path.
 *
 * @param path path
 * @return base path
 */
public String getBasePath(String path) {
    return FilenameUtils.getPath(path);
}

From source file:ch.entwine.weblounge.contentrepository.impl.bundle.WritableBundleContentRepository.java

/**
 * Loads all resources from the bundle and returns their uris as an iterator.
 * //from  www  .  ja  va 2 s  .c  om
 * @return the resource uris
 * @throws ContentRepositoryException
 *           if reading from the repository fails
 */
@SuppressWarnings("unchecked")
protected Iterator<ResourceURI> getResourceURIsFromBundle() throws ContentRepositoryException {

    List<ResourceURI> resourceURIs = new ArrayList<ResourceURI>();

    // For every serializer, try to load the resources
    for (ResourceSerializer<?, ?> serializer : getSerializers()) {
        String resourceDirectory = serializer.getType() + "s";
        String resourcePathPrefix = UrlUtils.concat(bundlePathPrefix, resourceDirectory);
        Enumeration<URL> entries = bundle.findEntries(resourcePathPrefix, "*.xml", true);
        if (entries != null) {
            while (entries.hasMoreElements()) {
                URL entry = entries.nextElement();
                String path = FilenameUtils.getPath(entry.getPath());
                path = path.substring(resourcePathPrefix.length() - 1);
                long v = ResourceUtils.getVersion(FilenameUtils.getBaseName(entry.getPath()));
                ResourceURI resourceURI = new ResourceURIImpl(serializer.getType(), site, path, v);
                resourceURIs.add(resourceURI);
                logger.trace("Found revision '{}' of {} {}", new Object[] { v, resourceURI.getType(), entry });
            }
        }
    }

    return resourceURIs.iterator();
}

From source file:com.frostwire.gui.library.LibraryPlaylistsTableDataLine.java

/**
 * Creates a tool tip for each row of the playlist. Tries to grab any information
 * that was extracted from the Meta-Tag or passed in to the PlaylistItem as 
 * a property map/*from  w w w.ja v a2 s  . com*/
 */
public String[] getToolTipArray(int col) {
    List<String> list = new ArrayList<String>();
    if (!StringUtils.isNullOrEmpty(initializer.getTrackTitle(), true)) {
        list.add(I18n.tr("Title") + ": " + initializer.getTrackTitle());
    }
    if (!StringUtils.isNullOrEmpty(initializer.getTrackNumber(), true)) {
        list.add(I18n.tr("Track") + ": " + initializer.getTrackNumber());
    }

    list.add(I18n.tr("Duration") + ": "
            + LibraryUtils.getSecondsInDDHHMMSS((int) initializer.getTrackDurationInSecs()));

    if (!StringUtils.isNullOrEmpty(initializer.getTrackArtist(), true)) {
        list.add(I18n.tr("Artist") + ": " + initializer.getTrackArtist());
    }
    if (!StringUtils.isNullOrEmpty(initializer.getTrackAlbum(), true)) {
        list.add(I18n.tr("Album") + ": " + initializer.getTrackAlbum());
    }
    if (!StringUtils.isNullOrEmpty(initializer.getTrackGenre(), true)) {
        list.add(I18n.tr("Genre") + ": " + initializer.getTrackGenre());
    }
    if (!StringUtils.isNullOrEmpty(initializer.getTrackYear(), true)) {
        list.add(I18n.tr("Year") + ": " + initializer.getTrackYear());
    }
    if (!StringUtils.isNullOrEmpty(initializer.getTrackComment(), true)) {
        list.add(I18n.tr("Comment") + ": " + initializer.getTrackComment());
    }

    if (list.size() == 1) {
        if (!StringUtils.isNullOrEmpty(initializer.getFileName(), true)) {
            list.add(I18n.tr("File") + ": " + initializer.getFileName());
        }
        if (!StringUtils.isNullOrEmpty(initializer.getFilePath(), true)) {
            list.add(I18n.tr("Folder") + ": " + FilenameUtils.getPath(initializer.getFilePath()));
        }
        if (!StringUtils.isNullOrEmpty(initializer.getTrackBitrate(), true)) {
            list.add(I18n.tr("Bitrate") + ": " + initializer.getTrackBitrate());
        }
    }

    return list.toArray(new String[0]);
}

From source file:com.bt.download.android.gui.Librarian.java

public EphemeralPlaylist createEphemeralPlaylist(FileDescriptor fd) {
    List<FileDescriptor> fds = Librarian.instance().getFiles(Constants.FILE_TYPE_AUDIO,
            FilenameUtils.getPath(fd.filePath), false);

    if (fds.size() == 0) { // just in case
        Log.w(TAG, "Logic error creating ephemeral playlist");
        fds.add(fd);/*from  w  ww  .  ja  v a  2s .c o  m*/
    }

    EphemeralPlaylist playlist = new EphemeralPlaylist(fds);
    playlist.setNextItem(new PlaylistItem(fd));

    return playlist;
}

From source file:com.alibaba.otter.node.etl.load.loader.db.FileLoadAction.java

private void doMove(FileLoadContext context, File rootDir, FileData fileData) throws IOException {
    boolean isLocal = StringUtils.isBlank(fileData.getNameSpace());
    String entryName = null;//  www .ja  v a  2 s . c  o  m
    if (true == isLocal) {
        entryName = FilenameUtils.getPath(fileData.getPath()) + FilenameUtils.getName(fileData.getPath());
    } else {
        entryName = fileData.getNameSpace() + File.separator + fileData.getPath();
    }
    File sourceFile = new File(rootDir, entryName);
    if (true == sourceFile.exists() && false == sourceFile.isDirectory()) {
        if (false == isLocal) {
            throw new LoadException(fileData + " is not support!");
        } else {
            File targetFile = new File(fileData.getPath());
            // copy to product path
            NioUtils.copy(sourceFile, targetFile, retry);
            if (true == targetFile.exists()) {
                // meta?
                fileData.setSize(sourceFile.length());
                fileData.setLastModifiedTime(sourceFile.lastModified());
                context.getProcessedDatas().add(fileData);
            } else {
                throw new LoadException(String.format("copy/rename [%s] to [%s] failed by unknow reason",
                        sourceFile.getPath(), targetFile.getPath()));
            }

        }

        LoadCounter counter = loadStatsTracker.getStat(context.getIdentity()).getStat(fileData.getPairId());
        counter.getFileCount().incrementAndGet();
        counter.getFileSize().addAndGet(fileData.getSize());
    } else if (fileData.getEventType().isDelete()) {
        // 
        if (false == isLocal) {
            throw new LoadException(fileData + " is not support!");
        } else {
            File targetFile = new File(fileData.getPath());
            if (NioUtils.delete(targetFile, retry)) {
                context.getProcessedDatas().add(fileData);
            } else {
                context.getFailedDatas().add(fileData);
            }
        }
    } else {
        context.getFailedDatas().add(fileData);// 
    }

}

From source file:ca.on.oicr.pde.workflows.GATK3WorkflowTest.java

private void validateWorkflow(AbstractWorkflowDataModel w) {

    //check for null string
    for (AbstractJob j : w.getWorkflow().getJobs()) {

        String c = Joiner.on(" ").useForNull("null").join(j.getCommand().getArguments());

        //check for null string
        Assert.assertFalse(c.contains("null"), "Warning: command contains \"null\":\n" + c + "\n");

        // check for missing spaces
        Assert.assertFalse(c.matches("(.*)[^ ]--(.*)"));
    }/*from  w ww.  j  a  va 2s.c  om*/

    //verify bai is located in the correct provision directory
    Map<String, String> bamFileDirectories = new HashMap<>();
    for (SqwFile f : w.getFiles().values()) {
        if (FilenameUtils.isExtension(f.getProvisionedPath(), "bam")) {
            bamFileDirectories.put(FilenameUtils.removeExtension(f.getSourcePath()),
                    FilenameUtils.getPath(f.getProvisionedPath()));
        }
    }
    for (SqwFile f : w.getFiles().values()) {
        //FIXME: bai.getProvisionedPath != bai.getOutputPath ...
        // at least with seqware 1.1.0, setting output path changes where the output file will be stored,
        // but the commonly used get provisioned path will return the incorrect path to the file
        if (FilenameUtils.isExtension(f.getProvisionedPath(), "bai")) {
            //check bai is in the same provision directory its corresponding bam is in
            Assert.assertEquals(FilenameUtils.getPath(f.getOutputPath()),
                    bamFileDirectories.get(FilenameUtils.removeExtension(f.getSourcePath())));
        }
    }

    //check number of parent nodes
    Set<VariantCaller> vc = new HashSet<>();
    for (String s : StringUtils.split(w.getConfigs().get("variant_caller"), ",")) {
        vc.add(VariantCaller.valueOf(StringUtils.upperCase(s)));
    }
    int parallelism = Math.max(1, StringUtils.split(w.getConfigs().get("chr_sizes"), ",").length);
    int expectedParentNodeCount = parallelism * (vc.contains(HAPLOTYPE_CALLER) ? 1 : 0)
            + parallelism * (vc.contains(UNIFIED_GENOTYPER) ? 2 : 0); //ug indels and ug snvs
    int actualParentNodeCount = 0;
    for (AbstractJob j : w.getWorkflow().getJobs()) {
        if (j.getParents().isEmpty()) {
            actualParentNodeCount++;
        }
    }
    Assert.assertEquals(actualParentNodeCount, expectedParentNodeCount);

    //view output files
    for (AbstractJob j : w.getWorkflow().getJobs()) {
        for (SqwFile f : j.getFiles()) {
            if (f.isOutput()) {
                System.out.println(f.getProvisionedPath());
            }
        }
    }
}

From source file:com.iyonger.apm.web.repository.FileEntryRepository.java

String[] getPathFragment(String path) {
    String basePath = FilenameUtils.getPath(path);
    return StringUtils.split(FilenameUtils.separatorsToUnix(basePath), "/");

}

From source file:fr.insalyon.creatis.vip.application.server.business.WorkflowBusiness.java

/**
 *
 * @param user/*www.  j a  v  a  2  s .  c  o m*/
 * @param applicationName
 * @param applicationVersion
 * @return
 * @throws BusinessException
 */
public Descriptor getApplicationDescriptor(User user, String applicationName, String applicationVersion)
        throws BusinessException {

    try {

        AppVersion version = applicationDB.getVersion(applicationName, applicationVersion);
        DataManagerBusiness dmBusiness = new DataManagerBusiness();
        String localDirectory = Server.getInstance().getConfigurationFolder() + "workflows/"
                + FilenameUtils.getPath(version.getLfn()) + "/" + FilenameUtils.getName(version.getLfn());
        String workflowPath = dmBusiness.getRemoteFile(user, version.getLfn(), localDirectory);
        return workflowPath.endsWith(".gwendia") ? new GwendiaParser().parse(workflowPath)
                : new ScuflParser().parse(workflowPath);

    } catch (org.xml.sax.SAXException ex) {
        logger.error(ex);
        throw new BusinessException(ex);
    } catch (fr.insalyon.creatis.vip.core.server.dao.DAOException ex) {
        logger.error(ex);
        throw new BusinessException(ex);
    } catch (java.io.IOException ex) {
        logger.error(ex);
        throw new BusinessException(ex);
    }
}