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

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

Introduction

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

Prototype

public static String getExtension(String filename) 

Source Link

Document

Gets the extension of a filename.

Usage

From source file:de.uzk.hki.da.convert.PublishCLIConversionStrategy.java

@Override
public List<Event> convertFile(WorkArea wa, ConversionInstruction ci

) throws FileNotFoundException {
    if (pkg == null)
        throw new IllegalStateException("Package not set");

    List<Event> results = new ArrayList<Event>();

    for (String audience : audiences) {

        String audience_lc = audience.toLowerCase();
        String repName = WorkArea.TMP_PIPS + "/" + audience_lc;

        Path.make(wa.dataPath(), repName, ci.getTarget_folder()).toFile().mkdirs();

        String[] commandAsArray = assemble(wa, ci, repName);
        if (!cliConnector.execute(commandAsArray))
            throw new RuntimeException("convert did not succeed");

        String targetSuffix = ci.getConversion_routine().getTarget_suffix();
        if (targetSuffix.equals("*"))
            targetSuffix = FilenameUtils.getExtension(wa.toFile(ci.getSource_file()).getAbsolutePath());
        DAFile result = new DAFile(repName,
                ci.getTarget_folder() + "/"
                        + FilenameUtils.removeExtension(Matcher.quoteReplacement(
                                FilenameUtils.getName(wa.toFile(ci.getSource_file()).getAbsolutePath())))
                        + "." + targetSuffix);

        Event e = new Event();
        e.setType("CONVERT");
        e.setDetail(StringUtilities.createString(commandAsArray));
        e.setSource_file(ci.getSource_file());
        e.setTarget_file(result);/*www .j  a v a 2s .co  m*/
        e.setDate(new Date());

        results.add(e);

    }

    return results;

}

From source file:models.charroi.Car.java

public void saveDocs(File doc1, File doc2, File doc3, File doc4, File doc5) {
    if (doc1 != null) {
        String ext = "." + FilenameUtils.getExtension(doc1.getAbsolutePath());
        new File(Car.DOC_DIR + "doc1-" + this.id + ext).delete();
        doc1.renameTo(new File(Car.DOC_DIR + "doc1-" + this.id + ext));
        this.doc1 = true;
        this.doc1Ext = ext;
    }/*w  w  w . ja  v  a2s  .  co m*/

    if (doc2 != null) {
        String ext = "." + FilenameUtils.getExtension(doc2.getAbsolutePath());
        new File(Car.DOC_DIR + "doc2-" + this.id + ext).delete();
        doc2.renameTo(new File(Car.DOC_DIR + "doc2-" + this.id + ext));
        this.doc2 = true;
        this.doc2Ext = ext;
    }

    if (doc3 != null) {
        String ext = "." + FilenameUtils.getExtension(doc3.getAbsolutePath());
        new File(Car.DOC_DIR + "doc3-" + this.id + ext).delete();
        doc3.renameTo(new File(Car.DOC_DIR + "doc3-" + this.id + ext));
        this.doc3 = true;
        this.doc3Ext = ext;
    }

    if (doc4 != null) {
        String ext = "." + FilenameUtils.getExtension(doc4.getAbsolutePath());
        new File(Car.DOC_DIR + "doc4-" + this.id + ext).delete();
        doc4.renameTo(new File(Car.DOC_DIR + "doc4-" + this.id + ext));
        this.doc4 = true;
        this.doc4Ext = ext;
    }

    if (doc5 != null) {
        String ext = "." + FilenameUtils.getExtension(doc5.getAbsolutePath());
        new File(Car.DOC_DIR + "doc5-" + this.id + ext).delete();
        doc5.renameTo(new File(Car.DOC_DIR + "doc5-" + this.id + ext));
        this.doc5 = true;
        this.doc5Ext = ext;
    }

}

From source file:net.grinder.util.GrinderClassPathUtils.java

private static boolean isPatchJar(String jarFilename) {
    if ("jar".equals(FilenameUtils.getExtension(jarFilename))) {
        for (String jarName : PATCH_JAR_LIST) {
            if (jarFilename.contains(jarName)) {
                return true;
            }/*from  w  w w  .j  a  v a 2  s.com*/
        }
    }
    return false;
}

From source file:ch.cyberduck.CreateFileController.java

protected void createFile(final Path workdir, final String filename, final boolean edit) {
    final BrowserController c = (BrowserController) parent;

    c.background(new BrowserBackgroundAction(c) {
        final Path file = PathFactory.createPath(this.getSession(), workdir.getAbsolute(),
                LocalFactory.createLocal(Preferences.instance().getProperty("tmp.dir"), filename));

        public void run() {
            int no = 0;
            while (file.getLocal().exists()) {
                no++;/*from w w  w .  ja v  a2  s.  com*/
                String proposal = FilenameUtils.getBaseName(filename) + "-" + no;
                if (StringUtils.isNotBlank(FilenameUtils.getExtension(filename))) {
                    proposal += "." + FilenameUtils.getExtension(filename);
                }
                file.setLocal(
                        LocalFactory.createLocal(Preferences.instance().getProperty("tmp.dir"), proposal));
            }
            file.getLocal().touch();
            TransferOptions options = new TransferOptions();
            options.closeSession = false;
            try {
                UploadTransfer upload = new UploadTransfer(file);
                upload.start(new TransferPrompt() {
                    public TransferAction prompt() {
                        return TransferAction.ACTION_OVERWRITE;
                    }
                }, options);
                file.getParent().invalidate();
            } finally {
                file.getLocal().delete(false);
            }
            if (file.exists()) {
                //                    if(edit) {
                //                        Editor editor = EditorFactory.createEditor(c, file);
                //                        editor.open();
                //                    }
            }
        }

        @Override
        public String getActivity() {
            return MessageFormat.format(Locale.localizedString("Uploading {0}", "Status"), file.getName());
        }

        @Override
        public void cleanup() {
            if (filename.charAt(0) == '.') {
                c.setShowHiddenFiles(true);
            }
            c.reloadData(Collections.singletonList(file));
        }
    });
}

From source file:bboss.org.artofsolving.jodconverter.OfficeDocumentConverter.java

public void convert(File inputFile, File outputFile) throws OfficeException {
    String outputExtension = FilenameUtils.getExtension(outputFile.getName());
    DocumentFormat outputFormat = formatRegistry.getFormatByExtension(outputExtension);
    convert(inputFile, outputFile, outputFormat);
}

From source file:br.ufrn.fonoweb.service.ArquivoService.java

public String getEncodedFileName(String originalFile, byte[] contents) {
    MessageDigest md = null;//  w w w  .j  a  va2s . com
    String result = null;
    try {
        md = MessageDigest.getInstance("SHA-256");
        md.update(contents);
        result = new BigInteger(1, md.digest()).toString(16);
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(ArquivoService.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
    result = result.concat(".").concat(FilenameUtils.getExtension(originalFile));
    return result;
}

From source file:de.renew.workflow.connector.internal.cases.ScenarioCompatibilityHelper.java

public static boolean ensureBackwardsCompatibility(final ScenarioHandlingProjectNature nature) {
    // FIXME: this is dirty fix only for this release 2.3
    // should be implemented in other way, we just do not have any time now
    try {/* w w  w. ja  va2 s .  c  o m*/
        if (nature == null
                || !nature.getProject().hasNature("org.kalypso.kalypso1d2d.pjt.Kalypso1D2DProjectNature")) //$NON-NLS-1$
            return true;

        // FIXME: the whole code here does not belong to this place -> this is a hidden dependency to 1d2d: bad!
        // TODO: instead implement an extension point mechanism
        final ProjectTemplate[] lTemplate = EclipsePlatformContributionsExtensions
                .getProjectTemplates("org.kalypso.kalypso1d2d.pjt.projectTemplate"); //$NON-NLS-1$
        try {
            // FIXME: this very probably does not work correctly or any more at all!

            /* Unpack project from template */
            final File destinationDir = nature.getProject().getLocation().toFile();
            final URL data = lTemplate[0].getData();
            final String location = data.toString();
            final String extension = FilenameUtils.getExtension(location);
            if ("zip".equalsIgnoreCase(extension)) //$NON-NLS-1$
            {
                // TODO: this completely overwrite the old project content, is this intended?
                ZipUtilities.unzip(data.openStream(), destinationDir, false);
            } else {
                final URL fileURL = FileLocator.toFileURL(data);
                final File dataDir = FileUtils.toFile(fileURL);
                if (dataDir == null) {
                    return false;
                }

                // FIXME: this only fixes the basic scenario, is this intended?

                final IOFileFilter lFileFilter = new WildcardFileFilter(new String[] { "wind.gml" }); //$NON-NLS-1$
                final IOFileFilter lDirFilter = TrueFileFilter.INSTANCE;
                final Collection<?> windFiles = FileUtils.listFiles(destinationDir, lFileFilter, lDirFilter);

                if (dataDir.isDirectory() && (windFiles == null || windFiles.size() == 0)) {
                    final WildcardFileFilter lCopyFilter = new WildcardFileFilter(
                            new String[] { "*asis", "models", "wind.gml" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    FileUtils.copyDirectory(dataDir, destinationDir, lCopyFilter);
                } else {
                    return true;
                }
            }
        } catch (final Throwable t) {
            t.printStackTrace();
            return false;
        }

        nature.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (final CoreException e) {
        // FIXME: this is no error handling; the users are not informed and will stumble over following errors caued by
        // this problem

        WorkflowConnectorPlugin.getDefault().getLog().log(e.getStatus());
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:de.spektrakel.sling.email.impl.DataSourceSlingResolverImpl.java

@Override
public DataSource resolve(String url, boolean isLenient) throws IOException {

    try {//from  w w w .j a  va  2 s.c o m
        if (isSlingUrl(url)) {
            String path = url.substring(PREFIX.length());

            Resource resource = resourceResolver.getResource(path);
            if (resource == null) {
                throw new ResourceNotFoundException("Resource not found, path=" + path);
            }

            InputStream inputStream = resource.adaptTo(InputStream.class);
            if (inputStream == null) {
                throw new ResourceNotFoundException("Cannot adapt resource to input stream, path=" + path);
            }

            String name = resource.getName();

            String mimeType = resource.getValueMap().get(JCR_MIMETYPE, String.class);
            if (StringUtils.isBlank(mimeType) && mimeTypeService != null) {
                mimeType = mimeTypeService.getMimeType(FilenameUtils.getExtension(name));
            }

            return new SlingResourceDataSource(resource, name, mimeType);
        }

    } catch (Exception e) {
        if (isLenient) {
            return null;
        } else {
            throw new IOException(e);
        }
    }

    return null;
}

From source file:com.skynetcomputing.connection.ConnectionMgr.java

/**
 * Save the received file in the job directory.
 *
 * @param aFile File that was send by the server.
 * @param extension Extension of the file.
 * @return True if saved./*from  ww  w.  ja va  2 s  .co m*/
 * @throws IOException
 */
public boolean saveFileLocal(File aFile) throws IOException {
    Logger.getLogger(ConnectionMgr.class.getName()).log(Level.INFO, "File received: {0}", aFile.getName());
    String extension = FilenameUtils.getExtension(aFile.getAbsolutePath());
    switch (extension) {
    case "jar":
        workMgr.onJarReceived(aFile);
        return true;
    case "task":
        workMgr.onTaskReceived(aFile);
        return true;
    case "data":
        workMgr.onDataReceived(aFile);
        return true;
    default:
        return false;
    }
}

From source file:io.ecarf.core.compress.NxGzipProcessor.java

/**
 * @param inputFile// w  ww  . j  av  a 2 s  .  c o  m
 * @param outputFile
 */
public NxGzipProcessor(String inputFile, String outputFile) {
    super();
    this.inputFile = inputFile;

    // no output file is provided, then workout a suitable filename
    if (StringUtils.isBlank(outputFile)) {
        // get the file name before the ext
        String ext = FilenameUtils.getExtension(inputFile);
        // construct an output file in the format inputfile_out.ext
        this.outputFile = StringUtils.removeEnd(inputFile, "." + ext);
        this.outputFile = this.outputFile + Constants.OUT_FILE_SUFFIX + ext;

    } else {
        this.outputFile = outputFile;
    }
}