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

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

Introduction

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

Prototype

public static String concat(String basePath, String fullFilenameToAdd) 

Source Link

Document

Concatenates a filename to a base path using normal command line style rules.

Usage

From source file:edu.kit.dama.staging.services.processor.impl.DownloadZipper.java

@Override
public void performPostTransferProcessing(TransferTaskContainer pContainer) throws StagingProcessorException {
    LOGGER.debug("Zipping data");
    URL generatedFolder = pContainer.getGeneratedUrl();
    LOGGER.debug("Using target folder: {}", generatedFolder);

    try {//  ww  w.j  a  va  2s  . co  m
        String zipFileName = CryptUtil.stringToSHA1(pContainer.getTransferInformation().getDigitalObjectId())
                + ".zip";
        URL targetZip = URLCreator.appendToURL(generatedFolder, zipFileName);
        LOGGER.debug("Zipping all data to file {}", targetZip);
        File targetFile = new File(targetZip.toURI());

        ITransferInformation info = pContainer.getTransferInformation();
        LOGGER.debug("Obtaining local folder for transfer with id {}", info.getTransferId());

        File localFolder = StagingService.getSingleton().getLocalStagingFolder(info,
                StagingService.getSingleton().getContext(info));
        File dataFolder = new File(
                FilenameUtils.concat(localFolder.getAbsolutePath(), Constants.STAGING_DATA_FOLDER_NAME));
        if (!dataFolder.exists()) {
            throw new IOException(
                    "Data folder " + dataFolder.getAbsolutePath() + " does not exist. Aborting zip operation.");
        }

        LOGGER.debug("Start zip operation using data input folder URL {}", dataFolder);
        ZipUtils.zip(new File(dataFolder.toURI()), targetFile);
        LOGGER.debug("Deleting 'data' folder content.");
        for (File f : new File(dataFolder.toURI()).listFiles()) {
            FileUtils.deleteQuietly(f);
        }
        LOGGER.debug("Moving result file {} to 'data' folder.", targetFile);
        FileUtils.moveFileToDirectory(targetFile, new File(dataFolder.toURI()), false);
        LOGGER.debug("Zip operation successfully finished.");
    } catch (IOException | URISyntaxException ex) {
        throw new StagingProcessorException("Failed to zip data", ex);
    }
}

From source file:io.insideout.stanbol.enhancer.nlp.freeling.Freeling.java

/**
 * Create a Freeling instance for the parsed shared resource directory,
 * Analyzer pool size and minimum Analyzer queue size. 
 * @param freelingSharePath the shared resource path
 * @param poolSize the maximum number of Analyzers instantiated for a language
 * @param minQueueSize defines how many instances are created at startup and
 * also when additional Analyzer instances are created. Set to <code>0</code>
 * to deactivate this feature (default=1 ... Two instances at startup and
 * creates additional instances if only 1 instance is left in the queue)
 *//* w  w  w . j av  a  2 s  .  c o m*/
public Freeling(String freelingSharePath, int poolSize, int minQueueSize) {
    this(FilenameUtils.concat(freelingSharePath, DEFAULT_RELATIVE_CONFIGURATION_PATH),
            DEFAULT_CONFIGURATION_FILENAME_SUFFIX, freelingSharePath, DEFAULT_FREELING_LIB_PATH,
            DEFAULT_FREELING_LOCALE, DEFAULT_CONCURRENT_THREADS,
            poolSize <= 0 ? DEFAULT_ANALYZER_POOL_SIZE : poolSize,
            minQueueSize < 0 ? DEFAULT_MIN_ANALYZER_QUEUE_SIZE : minQueueSize);
}

From source file:cop.maven.plugins.AbstractRestToRamlMojo.java

private void checkOutputDirectoryExists() {
    if (out == null)
        out = "docs";
    if (!out.startsWith(project.getBuild().getDirectory()))
        out = FilenameUtils.concat(project.getBuild().getDirectory(), out);
    if (new File(out).mkdirs())
        getLog().debug(String.format("Output directory '%s' created", out));
}

From source file:com.enderville.enderinstaller.util.InstallerConfig.java

/**
 * The "mods" folder in the target minecraft installation.
 *
 * @return// w  w w . ja v  a2  s .c o m
 */
public static String getMinecraftModsFolder() {
    return FilenameUtils.normalize(FilenameUtils.concat(getMinecraftFolder(), "mods"));
}

From source file:fr.ippon.wip.config.dao.XMLConfigurationDAO.java

/**
 * Return the file associated to the given configuration name.
 * /*from  ww w  . j av  a 2 s.  c  o m*/
 * @param name
 *            the name of the configuration
 * @param fileType
 *            config (0), clipping (1) or transform (2)
 * @return the file associated to the configuration
 */
public File getConfigurationFile(String name, int fileType) {
    return new File(FilenameUtils.concat(pathConfigFiles, getConfigurationName(name, fileType)));
}

From source file:com.enioka.jqm.tools.LibraryCache.java

private void loadCache(Node node, JobDef jd, EntityManager em) throws JqmPayloadException {
    jqmlogger.debug("Resolving classpath for job definition " + jd.getApplicationName());

    File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath()));
    File jarDir = jarFile.getParentFile();
    File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib"));
    File libDirExtracted = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "libFromJar"));
    File pomFile = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "pom.xml"));

    // POM file should be deleted if it comes from the jar file. Otherwise, it would stay into place and modifications to the internal
    // pom would be ignored.
    boolean pomFromJar = false;

    // 1st: if no pom, no lib dir => find a pom inside the JAR. (& copy it, we will read later)
    if (!pomFile.exists() && !libDir.exists()) {
        jqmlogger.trace("No pom inside jar directory. Checking for a pom inside the jar file");
        InputStream is = null;//www. java 2 s . co  m
        FileOutputStream os = null;

        try {
            ZipFile zf = new ZipFile(jarFile);
            Enumeration<? extends ZipEntry> zes = zf.entries();
            while (zes.hasMoreElements()) {
                ZipEntry ze = zes.nextElement();
                if (ze.getName().endsWith("pom.xml")) {

                    is = zf.getInputStream(ze);
                    os = new FileOutputStream(pomFile);
                    IOUtils.copy(is, os);
                    pomFromJar = true;
                    break;
                }
            }
            zf.close();
        } catch (Exception e) {
            throw new JqmPayloadException("Could not handle pom inside jar", e);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
    }

    // 2nd: no pom, no pom inside jar, no lib dir => find a lib dir inside the jar
    if (!pomFile.exists() && !libDir.exists()) {
        jqmlogger.trace("Checking for a lib directory inside jar");
        InputStream is = null;
        FileOutputStream os = null;
        ZipFile zf = null;
        FileUtils.deleteQuietly(libDirExtracted);

        try {
            zf = new ZipFile(jarFile);
            Enumeration<? extends ZipEntry> zes = zf.entries();
            while (zes.hasMoreElements()) {
                ZipEntry ze = zes.nextElement();
                if (ze.getName().startsWith("lib/") && ze.getName().endsWith(".jar")) {
                    if (!libDirExtracted.isDirectory() && !libDirExtracted.mkdir()) {
                        throw new JqmPayloadException("Could not extract libraries from jar");
                    }

                    is = zf.getInputStream(ze);
                    os = new FileOutputStream(FilenameUtils.concat(libDirExtracted.getAbsolutePath(),
                            FilenameUtils.getName(ze.getName())));
                    IOUtils.copy(is, os);
                    IOUtils.closeQuietly(is);
                    IOUtils.closeQuietly(os);
                }
            }
        } catch (Exception e) {
            throw new JqmPayloadException("Could not handle internal lib directory", e);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
            try {
                zf.close();
            } catch (Exception e) {
                jqmlogger.warn("could not close jar file", e);
            }
        }

        // If libs were extracted, put in cache and return
        if (libDirExtracted.isDirectory()) {
            FileFilter fileFilter = new WildcardFileFilter("*.jar");
            File[] files = libDirExtracted.listFiles(fileFilter);
            URL[] libUrls = new URL[files.length];
            try {
                for (int i = 0; i < files.length; i++) {
                    libUrls[i] = files[i].toURI().toURL();
                }
            } catch (Exception e) {
                throw new JqmPayloadException("Could not handle internal lib directory", e);
            }

            // Put in cache
            putInCache(libUrls, jd.getApplicationName());
            return;
        }
    }

    // 3rd: if pom, use pom!
    if (pomFile.exists() && !libDir.exists()) {
        jqmlogger.trace("Reading a pom file");

        // Retrieve resolver configuration
        List<GlobalParameter> repolist = em
                .createQuery("SELECT gp FROM GlobalParameter gp WHERE gp.key = :repo", GlobalParameter.class)
                .setParameter("repo", "mavenRepo").getResultList();
        List<GlobalParameter> settings = em
                .createQuery("SELECT gp FROM GlobalParameter gp WHERE gp.key = :k", GlobalParameter.class)
                .setParameter("k", "mavenSettingsCL").getResultList();
        List<GlobalParameter> settingFiles = em
                .createQuery("SELECT gp FROM GlobalParameter gp WHERE gp.key = :k", GlobalParameter.class)
                .setParameter("k", "mavenSettingsFile").getResultList();

        boolean withCentral = false;
        String withCustomSettings = null;
        String withCustomSettingsFile = null;
        if (settings.size() == 1 && settingFiles.isEmpty()) {
            jqmlogger.trace("Custom settings file will be used: " + settings.get(0).getValue());
            withCustomSettings = settings.get(0).getValue();
        }
        if (settingFiles.size() == 1) {
            jqmlogger.trace("Custom settings file will be used: " + settingFiles.get(0).getValue());
            withCustomSettingsFile = settingFiles.get(0).getValue();
        }

        // Configure resolver
        ConfigurableMavenResolverSystem resolver = Maven.configureResolver();
        if (withCustomSettings != null && withCustomSettingsFile == null) {
            resolver.fromClassloaderResource(withCustomSettings);
        }
        if (withCustomSettingsFile != null) {
            resolver.fromFile(withCustomSettingsFile);
        }

        for (GlobalParameter gp : repolist) {
            if (gp.getValue().contains("repo1.maven.org")) {
                withCentral = true;
            }
            resolver = resolver.withRemoteRepo(MavenRemoteRepositories
                    .createRemoteRepository(gp.getId().toString(), gp.getValue(), "default")
                    .setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER));
        }
        resolver.withMavenCentralRepo(withCentral);

        // Resolve
        File[] depFiles = null;
        try {
            depFiles = resolver.loadPomFromFile(pomFile).importRuntimeDependencies().resolve()
                    .withTransitivity().asFile();
        } catch (IllegalArgumentException e) {
            // Happens when no dependencies inside pom, which is a weird use of the feature...
            jqmlogger.trace("No dependencies inside pom.xml file - no libs will be used", e);
            depFiles = new File[0];
        }

        // Extract results
        int size = 0;
        for (File artifact : depFiles) {
            if (!"pom".equals(FilenameUtils.getExtension(artifact.getName()))) {
                size++;
            }
        }
        URL[] tmp = new URL[size];
        int i = 0;
        for (File artifact : depFiles) {
            if ("pom".equals(FilenameUtils.getExtension(artifact.getName()))) {
                continue;
            }
            try {
                tmp[i] = artifact.toURI().toURL();
            } catch (MalformedURLException e) {
                throw new JqmPayloadException("Incorrect dependency in POM file", e);
            }
            i++;
        }

        // Put in cache
        putInCache(tmp, jd.getApplicationName());

        // Cleanup
        if (pomFromJar && !pomFile.delete()) {
            jqmlogger.warn("Could not delete the temp pom file extracted from the jar.");
        }
        return;
    }

    // 4: if lib, use lib... (lib has priority over pom)
    if (libDir.exists()) {
        jqmlogger.trace(
                "Using the lib directory " + libDir.getAbsolutePath() + " as the source for dependencies");
        FileFilter fileFilter = new WildcardFileFilter("*.jar");
        File[] files = libDir.listFiles(fileFilter);
        URL[] tmp = new URL[files.length];
        for (int i = 0; i < files.length; i++) {
            try {
                tmp[i] = files[i].toURI().toURL();
            } catch (MalformedURLException e) {
                throw new JqmPayloadException("incorrect file inside lib directory", e);
            }
        }

        // Put in cache
        putInCache(tmp, jd.getApplicationName());
        return;
    }

    throw new JqmPayloadException(
            "There is no lib dir or no pom.xml inside the directory containing the jar or inside the jar. The jar cannot be launched.");
}

From source file:edu.cornell.med.icb.goby.alignments.TestReadWriteAlignments.java

@Test
public void readWriteHeader102() throws IOException {
    final IndexedIdentifier queryIds = new IndexedIdentifier();
    queryIds.put(new MutableString("query:1"), 1);
    queryIds.put(new MutableString("query:2"), 2);

    final IndexedIdentifier targetIds = new IndexedIdentifier();
    targetIds.put(new MutableString("target:1"), 1);

    final AlignmentWriter writer = new AlignmentWriterImpl(FilenameUtils.concat(BASE_TEST_DIR, "align-102"));

    assertNotNull(queryIds.keySet());/*from  w ww  .ja v a 2 s . c  om*/
    writer.setQueryIdentifiers(queryIds);
    writer.setTargetIdentifiers(targetIds);
    writer.close();

    final AlignmentReaderImpl reader = new AlignmentReaderImpl(
            FilenameUtils.concat(BASE_TEST_DIR, "align-102"));
    reader.readHeader();
    assertEquals(1, reader.getQueryIdentifiers().getInt(new MutableString("query:1")));
    assertEquals(-1, reader.getTargetIdentifiers().getInt(new MutableString("query:1")));
    assertEquals(1, reader.getTargetIdentifiers().getInt(new MutableString("target:1")));
    assertEquals(-1, reader.getTargetIdentifiers().getInt(new MutableString("target:2")));
}

From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java

public ModelAsset createModelAsset(ModelImporter.ImportedModel model) throws IOException {
    String modelFilename = model.g3dbFile.name();
    String metaFilename = modelFilename + ".meta";

    // create meta file
    String metaPath = FilenameUtils.concat(rootFolder.path(), metaFilename);
    MetaFile meta = createNewMetaFile(new FileHandle(metaPath), AssetType.MODEL);

    // copy model file
    FileHandle assetFile = new FileHandle(FilenameUtils.concat(rootFolder.path(), modelFilename));
    model.g3dbFile.copyTo(assetFile);/* w  ww . j  av  a 2s .co m*/

    // load & return asset
    ModelAsset asset = new ModelAsset(meta, assetFile);
    asset.load();
    addAsset(asset);

    return asset;
}

From source file:com.cloudant.sync.datastore.BasicDatastore.java

public BasicDatastore(String dir, String name) throws SQLException, IOException {
    Preconditions.checkNotNull(dir);/*from   w  w w .  j  a v  a2  s  .com*/
    Preconditions.checkNotNull(name);

    this.datastoreDir = dir;
    this.datastoreName = name;
    this.extensionsDir = FilenameUtils.concat(this.datastoreDir, "extensions");
    String dbFilename = FilenameUtils.concat(this.datastoreDir, DB_FILE_NAME);
    this.sqlDb = SQLDatabaseFactory.openSqlDatabase(dbFilename);
    this.updateSchema();
    this.eventBus = new EventBus();
    this.attachmentManager = new AttachmentManager(this);
}

From source file:edu.cornell.med.icb.goby.alignments.TestPositionSlices.java

@Test
public void testFourSlice() throws IOException {
    final String basename = "align-position-slices-4";
    buildAlignment(basename);//from   w  w  w  .j ava  2  s . c o m

    {// check that we can read everything only between 1 13 and 1 13:
        final AlignmentReader reader = new AlignmentReaderImpl(FilenameUtils.concat(BASE_TEST_DIR, basename), 1,
                13, 1, 13);

        check(reader, 1, 13);
        check(reader, 1, 13);
        check(reader, 1, 13);

        assertFalse(reader.hasNext());
        reader.close();
    }
}