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:de.uzk.hki.da.grid.IrodsFederatedGridFacade.java

@Override
public boolean put(File file, String address_dest, StoragePolicy sp, String checksum) throws IOException {
    IrodsCommandLineConnector iclc = new IrodsCommandLineConnector();
    if (!address_dest.startsWith("/"))
        address_dest = "/" + address_dest;
    String gridPath = "/" + irodsSystemConnector.getZone() + "/" + WorkArea.AIP + address_dest;
    String destCollection = FilenameUtils.getFullPath(gridPath);

    if (!iclc.exists(destCollection)) {
        logger.debug("creating Coll " + destCollection);
        iclc.mkCollection(destCollection);
    }/*from   w w w  . j  a v  a2 s . c o  m*/

    if (iclc.put(file, gridPath, sp.getCommonStorageRescName())) {
        if (sp.getForbiddenNodes() != null && !sp.getForbiddenNodes().isEmpty())
            iclc.setIMeta(gridPath, "FORBIDDEN_NODES", String.valueOf(sp));
        iclc.setIMeta(gridPath, "MIN_COPIES", String.valueOf(sp.getMinNodes()));
        String checksumAfterPut = iclc.getChecksum(gridPath);

        if (StringUtilities.isNotSet(checksumAfterPut)) {
            throw new IOException("iRODS found no checksum for " + gridPath);
        }

        if (!StringUtilities.isNotSet(checksum)) {
            if (!checksumAfterPut.equals(checksum)) {
                logger.error("Given Checksum of Package has to be " + checksum);
                logger.error("Checksum is " + checksumAfterPut);
                throw new IOException("Checksum not correct on put!");
            }
        }
        iclc.setIMeta(gridPath, "chksum", checksumAfterPut);
        iclc.setIMeta(gridPath, "FEDERATED", "0");
        return true;
    } else {
        logger.debug("Unable to put the aip file to irods");
        return false;
    }
}

From source file:fi.johannes.kata.ocr.utils.structs.Filename.java

private void cacheStrings() {
    fullpath = FilenameUtils.getFullPath(absolutePath.toString());
    name = FilenameUtils.getBaseName(absolutePath.toString());
    extension = FilenameUtils.getExtension(absolutePath.toString());
}

From source file:com.esri.geoevent.test.performance.report.AbstractFileRollOverReportWriter.java

protected void rollOver(String fileName) {
    File target;/*from   w  w  w .j av a 2 s . c o  m*/
    File file;
    boolean renameSucceeded = true;

    if (!new File(fileName).exists()) {
        return;
    }

    // If maxBackups <= 0, then there is no file renaming to be done.
    if (getMaxNumberOfReportFiles() > 0) {
        // Delete the oldest file, to keep Windows happy.
        String ext = FilenameUtils.getExtension(fileName);
        String baseFileName = FilenameUtils.getFullPath(fileName) + FilenameUtils.getBaseName(fileName);

        file = new File(baseFileName + getMaxNumberOfReportFiles() + '.' + ext);
        if (file.exists()) {
            renameSucceeded = file.delete();
        }

        // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
        for (int i = getMaxNumberOfReportFiles() - 1; i >= 1 && renameSucceeded; i--) {
            file = new File(baseFileName + i + "." + ext);
            if (file.exists()) {
                target = new File(baseFileName + (i + 1) + '.' + ext);
                renameSucceeded = file.renameTo(target);
            }
        }

        if (renameSucceeded) {
            // Rename fileName to fileName.1
            target = new File(baseFileName + 1 + "." + ext);
            file = new File(fileName);
            renameSucceeded = file.renameTo(target);
        }
    }
}

From source file:MSUmpire.SeqUtility.FastaParser.java

public static FastaParser FasterSerialzationRead(String Filename) throws FileNotFoundException {

    if (!new File(FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer")
            .exists()) {//  ww w  .j ava  2 s.  c om
        return null;
    }
    FastaParser fastareader = null;
    try {
        org.apache.log4j.Logger.getRootLogger().info("Loading fasta serialization to file:"
                + FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer..");
        FileInputStream fileIn = new FileInputStream(
                FilenameUtils.getFullPath(Filename) + FilenameUtils.getBaseName(Filename) + ".FastaSer");
        FSTObjectInput in = new FSTObjectInput(fileIn);
        fastareader = (FastaParser) in.readObject();
        in.close();
        fileIn.close();
    } catch (Exception ex) {
        org.apache.log4j.Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
        return null;
    }

    return fastareader;
}

From source file:edu.ur.ir.ir_export.service.DefaultContributorTypeExportService.java

/** 
 * Create the xml file for the set of collections.
 * // www.j  ava 2  s. c  om
 * @param xmlFile - file to write the xml to
 * @param contributor types - set of contributor types to export
 * 
 * @throws IOException - if writing to the file fails.
 */
public void createXmlFile(File xmlFile, Collection<ContributorType> contributorTypes) throws IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;

    String path = FilenameUtils.getPath(xmlFile.getCanonicalPath());
    if (!path.equals("")) {
        File pathOnly = new File(FilenameUtils.getFullPath(xmlFile.getCanonicalPath()));
        FileUtils.forceMkdir(pathOnly);
    }

    if (!xmlFile.exists()) {
        if (!xmlFile.createNewFile()) {
            throw new IllegalStateException("could not create file");
        }
    }

    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }

    DOMImplementation impl = builder.getDOMImplementation();
    DOMImplementationLS domLs = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSSerializer serializer = domLs.createLSSerializer();
    LSOutput lsOut = domLs.createLSOutput();

    Document doc = impl.createDocument(null, "contributor_types", null);
    Element root = doc.getDocumentElement();

    FileOutputStream fos;
    OutputStreamWriter outputStreamWriter;
    BufferedWriter writer;

    try {
        fos = new FileOutputStream(xmlFile);

        try {
            outputStreamWriter = new OutputStreamWriter(fos, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e);
        }
        writer = new BufferedWriter(outputStreamWriter);
        lsOut.setCharacterStream(writer);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
    }

    // create XML for the child collections
    for (ContributorType ct : contributorTypes) {
        Element contributorType = doc.createElement("contributor_type");

        this.addIdElement(contributorType, ct.getId().toString(), doc);
        this.addNameElement(contributorType, ct.getName(), doc);
        this.addDescription(contributorType, ct.getDescription(), doc);
        this.addSystemCode(contributorType, ct.getUniqueSystemCode(), doc);
    }
    serializer.write(root, lsOut);

    try {
        fos.close();
        writer.close();
        outputStreamWriter.close();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }

}

From source file:exifIndexer.MetadataReader.java

public static void walk(String path, boolean is_recursive) {

    File root = new File(path);
    File[] list = root.listFiles();
    String filePath;/*  w w  w .  j  a  v a  2s.  c  o m*/
    String fileName;
    String fileExt;
    String valueName;
    String tagName;
    String catName;
    Metadata metadata;
    long fileSize;
    long fileLastModified;
    java.util.Date utilDate;
    java.sql.Date sqlDate;

    String sql = "{ ? = call INSERTIMAGE(?,?,?,?,?) }";
    String sqlMetaData = "{ call INSERTMETADATA (?,?,?,?) }";

    CallableStatement statement;
    CallableStatement statementMeta;
    long result;

    if (list == null) {
        return;
    }

    for (File f : list) {
        if (f.isDirectory() && is_recursive) {
            walk(f.getAbsolutePath(), true);
        } else {

            filePath = FilenameUtils.getFullPath(f.getAbsolutePath());
            fileName = FilenameUtils.getBaseName(f.getName());
            fileExt = FilenameUtils.getExtension(f.getName());
            utilDate = new java.util.Date(f.lastModified());
            sqlDate = new java.sql.Date(utilDate.getTime());

            fileSize = f.length();

            try {
                metadata = ImageMetadataReader.readMetadata(f.getAbsoluteFile());
                try {
                    DBHandler db = new DBHandler();
                    db.openConnection();
                    Connection con = db.getCon();
                    // llamada al metodo insertar imagen SQL con (filePath,fileName,fileExtension,fileSize, fileLastModified)
                    statement = con.prepareCall(sql);
                    statement.setString(2, filePath);
                    statement.setString(3, fileName);
                    statement.setString(4, fileExt);
                    statement.setLong(5, fileSize);
                    statement.setDate(6, sqlDate);
                    statement.registerOutParameter(1, java.sql.Types.NUMERIC);
                    statement.execute();
                    result = statement.getLong(1);

                    // llamada al metodo insertar metadatos SQL con (idImg,valueName, tagName, catName)
                    for (Directory directory : metadata.getDirectories()) {
                        for (Tag tag : directory.getTags()) {

                            valueName = tag.getDescription();
                            tagName = tag.getTagName();
                            catName = directory.getName();

                            if (isNull(valueName) || isNull(tagName) || isNull(catName) || valueName.equals("")
                                    || tagName.equals("") || catName.equals("") || valueName.length() > 250
                                    || tagName.length() > 250 || catName.length() > 500) {
                                System.out.println("Exif row omitted.");
                                System.out.println("Omitting: [" + catName + "] " + tagName + " " + valueName);
                            } else {
                                statementMeta = con.prepareCall(sqlMetaData);
                                statementMeta.setLong(1, result);
                                statementMeta.setString(2, valueName);
                                statementMeta.setString(3, tagName);
                                statementMeta.setString(4, catName);
                                statementMeta.executeUpdate();
                            }
                        }
                    }
                    db.closeConnection();
                } catch (SQLException ex) {
                    System.err.println("Error with SQL command. \n" + ex);
                }
            } catch (ImageProcessingException e) {
                System.out.println("ImageProcessingException " + e);
            } catch (IOException e) {
                System.out.println("IOException " + e);
            }

        }

    }

}

From source file:com.norconex.jefmon.model.ConfigurationDAO.java

public static void saveConfig(JEFMonConfig config) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Saving JEF config to: " + CONFIG_FILE);
    }/*from   w  w  w .  j  a v a 2s .  c  om*/

    if (!CONFIG_FILE.exists()) {
        File configDir = new File(FilenameUtils.getFullPath(CONFIG_FILE.getAbsolutePath()));
        if (!configDir.exists()) {
            LOG.debug("Creating JEF Monitor config directory for: " + CONFIG_FILE);
            configDir.mkdirs();
        }
    }

    OutputStream out = new FileOutputStream(CONFIG_FILE);
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    try {
        XMLStreamWriter xml = factory.createXMLStreamWriter(out);
        xml.writeStartDocument();
        xml.writeStartElement("jefmon-config");

        xml.writeStartElement("instance-name");
        xml.writeCharacters(config.getInstanceName());
        xml.writeEndElement();

        xml.writeStartElement("default-refresh-interval");
        xml.writeCharacters(Integer.toString(config.getDefaultRefreshInterval()));
        xml.writeEndElement();

        saveRemoteUrls(xml, config.getRemoteInstanceUrls());
        saveMonitoredPaths(xml, config.getMonitoredPaths());
        saveJobActions(xml, config.getJobActions());

        xml.writeEndElement();
        xml.writeEndDocument();
        xml.flush();
        xml.close();
    } catch (XMLStreamException e) {
        throw new IOException("Cannot save as XML.", e);
    }
    out.close();
}

From source file:com.abiquo.api.util.snapshot.SnapshotUtils.java

/**
 * Returns the destination path where a snapshot of a certain {@link VirtualMachineTemplate}
 * must be stored./*from w  w w  .j  ava  2s. co m*/
 * 
 * @param template The {@link VirtualMachineTemplate} to consider
 * @return The destination path
 */
public static String formatSnapshotPath(final VirtualMachineTemplate template) {
    String filename = template.getPath();

    if (!template.isMaster()) {
        filename = template.getMaster().getPath();
    }

    return FilenameUtils.getFullPath(filename);
}

From source file:MSUmpire.DIA.RTMappingExtLib.java

public void GenerateModel() throws IOException {

    XYPointCollection points = new XYPointCollection();
    XYSeries series = new XYSeries("Peptide ions");
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();

    FileWriter writer = new FileWriter(FilenameUtils.getFullPath(TargetLCMS.mzXMLFileName) + "/"
            + FilenameUtils.getBaseName(TargetLCMS.mzXMLFileName) + "_" + libManager.LibID
            + "_RTMapPoints.txt");

    for (String pepkey : libManager.PeptideFragmentLib.keySet()) {
        if (TargetLCMS.GetPepIonList().containsKey(pepkey)) {
            PepFragmentLib peplib = libManager.GetFragmentLib(pepkey);
            for (float rt : peplib.RetentionTime) {
                float y = TargetLCMS.GetPepIonList().get(pepkey).GetRT();
                points.AddPoint(rt, y);/*from   ww w .  j  ava 2s. c  om*/
                series.add(new XYDataItem(rt, y));
                writer.write(rt + "\t" + y + "\n");
            }
        }
    }
    writer.close();
    regression = new PiecewiseRegression(parameter.MaxCurveRTRange, parameter.MaxCurveRTRange);
    regression.SetData(points);
    float R2 = regression.GetR2();
    Logger.getRootLogger()
            .info("Retention time prediction model:(" + FilenameUtils.getBaseName(TargetLCMS.mzXMLFileName)
                    + "..R2=" + R2 + "(No. of commonly identified peptide ions=" + points.PointCount() + ")");

    GenerateRTMapPNG(xySeriesCollection, series, R2);
}

From source file:aurelienribon.gdxsetupui.Helper.java

public static String getSource(List<String> files, String file) {
    String path = FilenameUtils.getFullPath(file);
    String name = FilenameUtils.getBaseName(file);
    String ext = FilenameUtils.getExtension(file);

    if (files.contains(path + name + "-source." + ext))
        return path + name + "-source." + ext;
    if (files.contains(path + name + "-sources." + ext))
        return path + name + "-sources." + ext;
    if (files.contains(path + name + "-src." + ext))
        return path + name + "-src." + ext;
    return null;/* w  w w .j  av  a 2s. c  o  m*/
}