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

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

Introduction

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

Prototype

public static String getFullPath(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path.

Usage

From source file:FeatureExtraction.FeatureExtractorOOXMLStructuralPaths.java

private void ExtractStructuralFeaturesInMemory(String filePath, Map<String, Integer> structuralPaths) {
    String path;//from   w w  w. j  ava  2s  .  c o m
    String directoryPath;
    String fileExtension;
    try {
        ZipFile zipFile = new ZipFile(filePath);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(
                String.format("Error extracting OOXML structural features from file: %s", filePath), ex);
    }
}

From source file:DIA_Umpire_To_Skyline.FileThread.java

public void GenerateSkylineFiles() {
    try {//from w  ww . j a v a 2  s  . co  m
        long time = System.currentTimeMillis();

        DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs);
        if (!new File(FilenameUtils.getFullPath(DiaFile.Filename) + DiaFile.GetQ1Name() + ".mzXML").exists()
                | !new File(FilenameUtils.getFullPath(DiaFile.Filename) + DiaFile.GetQ2Name() + ".mzXML")
                        .exists()
                | !new File(FilenameUtils.getFullPath(DiaFile.Filename) + DiaFile.GetQ3Name() + ".mzXML")
                        .exists()) {
            throw new RuntimeException();
        }
        Logger.getRootLogger().info(
                "=================================================================================================");
        Logger.getRootLogger().info("Processing " + mzXMLFile);

        if (!DiaFile.RawMGFExist()) {
            if (!DiaFile.LoadDIASetting()) {
                Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete");
                System.exit(1);
            }
            if (!DiaFile.LoadParams()) {
                Logger.getRootLogger().info("Loading parameters failed, job is incomplete");
                System.exit(1);
            }
            DiaFile.BuildStructure();
            if (!DiaFile.MS1FeatureMap.ReadPeakCluster()) {
                Logger.getRootLogger().info("Loading peak and structure failed, job is incomplete");
                System.exit(1);
            }
            DiaFile.CreateSkylingImportFolder();
            DiaFile.GenerateRawMGF();
            DiaFile.ClearStructure();
        }

        DiaFile.ConvertRawMGF(msconvertpath);
        ChangeScanTitlePepXML();
        DiaFile = null;
        System.gc();
        time = System.currentTimeMillis() - time;
        Logger.getRootLogger()
                .info(mzXMLFile + " processed time:"
                        + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time),
                                TimeUnit.MILLISECONDS.toMinutes(time)
                                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),
                                TimeUnit.MILLISECONDS.toSeconds(time)
                                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))));
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

From source file:de.mpg.imeji.logic.storage.util.MediaUtils.java

/**
 * User imagemagick to convert any image into a jpeg
 * // w  ww .ja v a  2  s .c  o  m
 * @param bytes
 * @param extension
 * @throws IOException
 * @throws URISyntaxException
 * @throws InterruptedException
 * @throws IM4JavaException
 */
public static byte[] convertToJPEG(File tmp, String extension)
        throws IOException, URISyntaxException, InterruptedException, IM4JavaException {
    // In case the file is made of many frames, (for instance videos), generate only the frames from 0 to 48 to
    // avoid high memory consumption
    String path = tmp.getAbsolutePath() + "[0-48]";
    ConvertCmd cmd = getConvert();
    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    if (isImage(extension))
        op.colorspace(findColorSpace(tmp));
    op.strip();
    op.flatten();
    op.addImage(path);
    // op.colorspace("RGB");
    File jpeg = File.createTempFile("uploadMagick", ".jpg");
    try {
        op.addImage(jpeg.getAbsolutePath());
        cmd.run(op);
        int frame = getNonBlankFrame(jpeg.getAbsolutePath());
        if (frame >= 0) {
            File f = new File(FilenameUtils.getFullPath(jpeg.getAbsolutePath())
                    + FilenameUtils.getBaseName(jpeg.getAbsolutePath()) + "-" + frame + ".jpg");
            return FileUtils.readFileToByteArray(f);
        }
        return FileUtils.readFileToByteArray(jpeg);
    } finally {
        removeFilesCreatedByImageMagick(jpeg.getAbsolutePath());
        FileUtils.deleteQuietly(jpeg);
    }
}

From source file:com.tomdoel.mpg2dcm.EndoscopicFileProcessor.java

/**
 * Creates the EndoscopicFileProcessor that will parse the XML file
 * @param xmlFile the XML file to be processed
 * @throws ParserConfigurationException/*from   w  w w  .  j  ava 2s .  c  om*/
 * @throws SAXException
 * @throws IOException
 */
public EndoscopicFileProcessor(final File xmlFile)
        throws ParserConfigurationException, SAXException, IOException, ParseException {

    // Parse the XML file to get the tags and video filenames
    EndoscopicXmlParser parser = parseEndoscopicXmlFile(xmlFile);

    // Convert the tags to Dicom tags
    dicomAttributes = convertEndoscopicXmlToDicomAttributes(parser.getTagMap());

    // Get full paths for each video file
    final String path = FilenameUtils.getFullPath(xmlFile.getAbsolutePath());
    for (final String fileName : parser.getVideoFilenames()) {
        fullVideoFileNames.add(new File(path, fileName));
    }
    for (final String fileName : parser.getPictureFilenames()) {
        fullPictureFileNames.add(new File(path, fileName));
    }

    for (final String fileName : parser.getSoundFilenames()) {
        fullSoundFileNames.add(new File(path, fileName));
    }
}

From source file:ee.ioc.cs.vsle.vclass.VPackage.java

public VPackage(String pathToXml) {
    this.pathToXml = pathToXml;
    this.packageDir = FilenameUtils.getFullPath(pathToXml);
}

From source file:MSUmpire.SpectrumParser.DIA_Setting.java

public void WriteDIASettingSerialization(String mzXMLFileName) {
    try {/*  w w w.  ja v a2 s.  c  o  m*/
        Logger.getRootLogger().info("Writing DIA setting to file:" + FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser...");
        FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName)
                + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser", false);
        ObjectOutputStream oos = new ObjectOutputStream(fout);
        oos.writeObject(this);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
    }
}

From source file:ch.cyberduck.cli.GlobTransferItemFinder.java

@Override
public Set<TransferItem> find(final CommandLine input, final TerminalAction action, final Path remote)
        throws AccessDeniedException {
    if (input.getOptionValues(action.name()).length == 2) {
        final String path = input.getOptionValues(action.name())[1];
        // This only applies to a shell where the glob is not already expanded into multiple arguments
        if (StringUtils.containsAny(path, '*', '?')) {
            final Local directory = LocalFactory.get(FilenameUtils.getFullPath(path));
            if (directory.isDirectory()) {
                final PathMatcher matcher = FileSystems.getDefault()
                        .getPathMatcher(String.format("glob:%s", FilenameUtils.getName(path)));
                final Set<TransferItem> items = new HashSet<TransferItem>();
                for (Local file : directory.list(new NullFilter<String>() {
                    @Override/*from w ww.j  av  a 2  s .  c o  m*/
                    public boolean accept(final String file) {
                        try {
                            return matcher.matches(Paths.get(file));
                        } catch (InvalidPathException e) {
                            log.warn(String.format("Failure obtaining path for file %s", file));
                        }
                        return false;
                    }
                })) {
                    items.add(new TransferItem(new Path(remote, file.getName(), EnumSet.of(Path.Type.file)),
                            file));
                }
                return items;
            }
        }
    }
    return new SingleTransferItemFinder().find(input, action, remote);
}

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

public void run() {
    try {/* ww w.ja  v  a 2 s  . com*/
        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:edu.scripps.fl.pubchem.app.cids.WriteSDFStage.java

public File newOutputFile(int index) {
    String outputFile = getOutputFile();
    outputFile = new File(outputFile).getAbsoluteFile().toString();
    String path = FilenameUtils.getFullPath(outputFile);
    String name = FilenameUtils.getBaseName(outputFile);
    String ext = FilenameUtils.getExtension(outputFile);
    File file = new File(path, name + "-" + index + "." + ext);
    return file;/*from w w w . j  av a2 s .co m*/
}

From source file:FeatureExtraction.FeatureExtractorOOXMLStructuralPathsInputStream.java

private void ExtractStructuralFeaturesInMemory(InputStream fileInputStream,
        Map<String, Integer> structuralPaths) {
    String path;//from w w w .  jav a2s.c  o  m
    String directoryPath;
    String fileExtension;
    try {
        File file = new File(fileInputStream.hashCode() + "");
        try (FileOutputStream fos = new FileOutputStream(file)) {
            IOUtils.copy(fileInputStream, fos);
        }

        ZipFile zipFile = new ZipFile(file);

        for (Enumeration e = zipFile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            path = entry.getName();
            directoryPath = FilenameUtils.getFullPath(path);
            fileExtension = FilenameUtils.getExtension(path);

            AddStructuralPath(directoryPath, structuralPaths);
            AddStructuralPath(path, structuralPaths);

            if (fileExtension.equals("rels") || fileExtension.equals("xml")) {
                AddXMLStructuralPaths(zipFile.getInputStream(entry), path, structuralPaths);
            }
        }
    } catch (IOException ex) {
        Console.PrintException(String.format("Error extracting OOXML structural features from file in memory"),
                ex);
    }
}