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:com.mbrlabs.mundus.assets.FbxConv.java

public FbxConvResult execute() {
    FbxConvResult result = new FbxConvResult();
    if (input == null || output == null) {
        result.setSuccess(false);// ww  w .j a  v  a 2  s  .co m
        result.setResultCode(FbxConvResult.RESULT_CODE_PARAM_ERROR);
        Log.error(TAG, "FbxCov input or output not defined");
        return result;
    }

    if (!input.endsWith("fbx")) {
        result.setSuccess(false);
        result.setResultCode(FbxConvResult.RESULT_CODE_WRONG_INPUT_FORMAT);
        Log.error(TAG, "FbxCov input format not supported");
    }

    // build arguments
    String outputFilename = FilenameUtils.getBaseName(input);
    List<String> args = new ArrayList<String>(6);
    if (flipTexture)
        args.add("-f");
    if (verbose)
        args.add("-v");
    if (outputFormat == OUTPUT_FORMAT_G3DJ) {
        args.add("-o");
        args.add("g3dj");
        outputFilename += ".g3dj";
    } else {
        outputFilename += ".g3db";
    }

    args.add(input);
    String path = FilenameUtils.concat(output, outputFilename);
    args.add(path);
    Log.debug("FbxConv", "Command: " + args);
    pb.command().addAll(args);

    // execute fbx-conv process
    try {
        Process process = pb.start();
        int exitCode = process.waitFor();
        String log = IOUtils.toString(process.getInputStream());

        if (exitCode == 0 && !log.contains("ERROR")) {
            result.setSuccess(true);
            result.setOutputFile(path);
        }
        result.setLog(log);

    } catch (IOException e) {
        e.printStackTrace();
        result.setSuccess(false);
        result.setResultCode(FbxConvResult.RESULT_CODE_IO_ERROR);
    } catch (InterruptedException e) {
        e.printStackTrace();
        result.setSuccess(false);
        result.setResultCode(FbxConvResult.RESULT_CODE_INTERRUPTED);
    }

    return result;
}

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

@Test
public void test_1_9_5_IndexIssueExtraTests() throws IOException {

    int[] targetLengths = new int[] { 100, 50, 20, 10, 5 };
    final String basename1 = FilenameUtils.concat(BASE_TEST_DIR, "align-index-error-2");
    final AlignmentWriterImpl writer = new AlignmentWriterImpl(basename1);
    writer.setTargetLengths(targetLengths);
    writer.setNumAlignmentEntriesPerChunk(1);
    writer.setSorted(true);/*from  w  w  w.j  a va 2  s.c  om*/
    int queryIndex = 0;

    writer.setAlignmentEntry(queryIndex++, 0, 99, 30, false, constantQueryLength);
    writer.appendEntry();
    writer.setAlignmentEntry(queryIndex++, 1, 0, 30, false, constantQueryLength);
    writer.appendEntry();
    writer.setAlignmentEntry(queryIndex++, 1, 1, 30, false, constantQueryLength);
    writer.appendEntry();
    writer.close();

    AlignmentReaderImpl reader = new AlignmentReaderImpl(basename1);
    reader.reposition(1, 0); // will be (0,99) because reposition goes one chunk before. The previous chunk
    // will have the indexed entry as first entry, plus some other entry, possibly including an entry with
    // position equal to the reposition argument. Repositioning to the chunk before garantees that skipTo will
    // not miss these entries, and appropriately filter the beginning of the chunk with position before (1,0).

    Alignments.AlignmentEntry entry = reader.next();
    assertEquals(0, entry.getTargetIndex());
    assertEquals(99, entry.getPosition());
    entry = reader.next();
    assertEquals(1, entry.getTargetIndex());
    assertEquals(0, entry.getPosition());
    entry = reader.next();
    assertEquals(1, entry.getTargetIndex());
    assertEquals(1, entry.getPosition());
    assertFalse(reader.hasNext());
    // Now check that the locations were stored in the index and can be decoded correctly:
    ObjectList<ReferenceLocation> locations = reader.getLocations(1);
    assertEquals(0, locations.get(0).targetIndex);
    assertEquals(99, locations.get(0).position);
    assertEquals(1, locations.get(1).targetIndex);
    assertEquals(0, locations.get(1).position);
    assertEquals(1, locations.get(2).targetIndex);
    assertEquals(1, locations.get(2).position);

    assertEquals("with modulo=1, must recover three locations.", 3, locations.size());

    reader = new AlignmentReaderImpl(basename1);

    entry = reader.skipTo(1, 1);
    assertEquals(1, entry.getTargetIndex());
    assertEquals(1, entry.getPosition());
    assertFalse(reader.hasNext());
}

From source file:edu.cornell.med.icb.goby.stats.TestStatsWriter.java

@Test
public void testVCFFormat2() throws IOException {

    final String file = FilenameUtils.concat(BASE_TEST_DIR, "format-2.vcf");

    VCFWriter writer = new VCFWriter(new PrintWriter(new FileWriter(file)));

    int fieldC = writer.defineField("FORMAT", "GT", 1, ColumnType.String, "Desc GT");
    int fieldD = writer.defineField("FORMAT", "GQ", 1, ColumnType.String, "Desc GQ");
    String samples[] = { "sample-id-1", "sample-id-2", "sample-id-3" };

    writer.defineSamples(samples);/*from  ww w  .  ja v a 2 s  .co m*/
    writer.writeHeader();
    writer.setSampleValue(fieldC, 0, "A");
    writer.setSampleValue(fieldD, 0, "B");
    writer.writeRecord();
    //      writer.setSampleValue(fieldC, 1, "A");
    //       writer.setSampleValue(fieldD, 1, "B");
    // writer.writeRecord();
    writer.setSampleValue(fieldC, 2, "A");
    writer.setSampleValue(fieldD, 2, "B");
    writer.writeRecord();
    writer.close();

    assertEquals(new File("test-data/stats-writer/expected-format-2.vcf"),
            new File("test-results/stats-writer/format-2.vcf"));
}

From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java

public VideoThumbnailPlugin(final BundleContext bundleContext) throws IOException {
    final String bundledFFmpegBinaryPath = getBundledFFmpegBinaryPath();
    final String ffmpegBinaryName = StringUtils.substringAfterLast(bundledFFmpegBinaryPath, "/");
    final String ffmpegFolderPath = FilenameUtils.concat(System.getProperty("ddf.home"),
            "bin_third_party/ffmpeg");
    ffmpegPath = FilenameUtils.concat(ffmpegFolderPath, ffmpegBinaryName);

    try (final InputStream inputStream = bundleContext.getBundle().getEntry(bundledFFmpegBinaryPath)
            .openStream()) {/*from  www .j av  a 2 s  .  co m*/
        copyFFmpegBinary(inputStream);
    }

    limitFFmpegProcessesSemaphore = new Semaphore(MAX_FFMPEG_PROCESSES, true);
}

From source file:edu.kit.dama.ui.repo.staging.DataZipCreator.java

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

    try {//from   ww w . java 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("Adding zip file {} to container.", targetFile);
        pContainer.addGeneratedFile(targetFile);
        LOGGER.debug("Zip operation successfully finished.");
    } catch (IOException | URISyntaxException ex) {
        throw new StagingProcessorException("Failed to zip data", ex);
    }
}

From source file:edu.kit.dama.staging.handlers.impl.DownloadPreparationHandler.java

@Override
public final void prepareEnvironment(TransferClientProperties pProperties,
        IAuthorizationContext pSecurityContext) throws TransferPreparationException {
    LOGGER.debug("Preparing data download tree");
    LOGGER.debug(" - Obtaining AccessPoint");
    AbstractStagingAccessPoint accessPoint = StagingConfigurationManager.getSingleton()
            .getAccessPointById(pProperties.getStagingAccessPointId());
    LOGGER.debug(" - Getting access URL");
    URL accessUrl = accessPoint.getAccessUrl(getTransferInformation(), pSecurityContext);
    LOGGER.debug(" - Access URL: {}. Getting local staging folder.", accessUrl);
    File localStagingFolder = accessPoint.getLocalPathForUrl(accessUrl, pSecurityContext);
    LOGGER.debug(" - Local staging folder: {}", localStagingFolder);
    File localSettingsFolder = AbstractStagingAccessPoint.getSettingsFolder(localStagingFolder);
    LOGGER.debug(" - Local settings folder: {}. Obtaining file tree destination file.", localSettingsFolder);
    String treeFile = FilenameUtils.concat(localSettingsFolder.getPath(), DATA_FILENAME);

    if (new File(treeFile).exists()
            && !StagingService.getSingleton().isTransferDeleted(getTransferInformation())) {
        throw new TransferPreparationException(
                "Download for this object is still in preparation. Please try again later");
    }//from   w w  w  .j a  va  2 s  .  com
    LOGGER.debug("Writing tree data to {}", treeFile);
    DataOrganizationUtils.writeTreeToFile(treeToDownload, new File(treeFile));

    if (pProperties.isSendMailNotification()) {
        LOGGER.debug("Writing mail notification information to file");
        MailNotificationHelper.storeProperties(localSettingsFolder, pProperties.getReceiverMail());
    }
    LOGGER.debug("Storing access point properties.");
    Properties props = TransferClientPropertiesUtils.propertiesToProperties(pProperties);
    FileOutputStream fout = null;
    try {
        fout = new FileOutputStream(
                new File(localSettingsFolder, pProperties.getStagingAccessPointId() + ".properties"));
        props.store(fout, null);
    } catch (IOException ioe) {
        LOGGER.error("Failed to store access point properies", ioe);
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ex) {
            }
        }
    }

    LOGGER.debug("Environment preparation successfully finished");
}

From source file:edu.cornell.med.icb.goby.counts.TestReadWriteCounts.java

@Test
@SuppressWarnings("deprecation") // We are intentionally testing a deprecated method here
public void testReadWrite2() throws IOException {
    final String basename = FilenameUtils.concat(BASE_TEST_DIR, "counts-102.bin");
    final CountsWriterI writerI = new CountsWriter(new FileOutputStream(basename), 0);

    final int lengthA = 5;
    final int lengthB = 100000;
    final int lengthC = 10;
    final int lengthD = 1;

    writerI.appendCount(10, lengthA);/*from  w w w . j  ava  2 s . c om*/
    writerI.appendCount(11, lengthB);
    writerI.appendCount(12, lengthC);

    writerI.appendCount(10, lengthD);
    writerI.close();

    final CountsReader reader = new CountsReader(new FileInputStream(basename));

    for (int index = 0; index < lengthA; index++) {
        assertTrue(reader.hasNextPosition());
        assertEquals(10, reader.nextCountAtPosition());
    }
    for (int index = 0; index < lengthB; index++) {
        assertTrue(reader.hasNextPosition());
        assertEquals(11, reader.nextCountAtPosition());
    }
    for (int index = 0; index < lengthC; index++) {
        assertTrue(reader.hasNextPosition());
        assertEquals(12, reader.nextCountAtPosition());
    }
    for (int index = 0; index < lengthD; index++) {
        assertTrue(reader.hasNextPosition());
        assertEquals(10, reader.nextCountAtPosition());
    }
    assertFalse(reader.hasNextPosition());
}

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

@Test
public void testThreeSlice() throws IOException {
    final String basename = "align-position-slices-3";
    buildAlignment(basename);//w w  w  .j  a va2s  . c  om

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

        check(reader, 1, 13);
        check(reader, 1, 13);
        check(reader, 1, 13);
        check(reader, 2, 123);
        assertFalse(reader.hasNext());
        reader.close();
    }
}

From source file:edu.cornell.med.icb.goby.counts.TestCountsArchive.java

@Test
public void testIndices() throws IOException {
    final String basename = FilenameUtils.concat(BASE_TEST_DIR, "102.bin");
    final CountsArchiveWriter writer = new CountsArchiveWriter(basename);
    CountsWriterI cw = writer.newCountWriter(0);
    writer.returnWriter(cw);//w  ww.j  a va  2  s.  c  o  m

    cw = writer.newCountWriter(1);

    writer.returnWriter(cw);
    writer.close();
    final CountsArchiveReader reader = new CountsArchiveReader(basename);
    assertEquals(2, reader.getNumberOfIndices());
    assertEquals(2, reader.getIndices().size());
    assertNotNull(reader.getCountReader(0));
    assertNotNull(reader.getCountReader(1));
}

From source file:edu.kit.dama.staging.util.StagingUtils.java

/**
 * Get the temporary directory of the transfer associated with the provided
 * transfer container. This directory is located in the user home directory
 * under ~/.lsdf/&lt;TID&gt;, where &lt;TID&gt; stands for the transfer ID of this
 * transfer. To avoid problems with invalid pathnames, the TID gets UTF-8
 * URL-encoded. Within the temporary directory the transfer can store status
 * information or checkpoint data to be able to resume failed transfers.
 *
 * @param pContainer The transfer container for which the temp dir should be
 * returned./*from  ww  w.  j  a  va 2s . c  o m*/
 *
 * @return The transfer's temporary directory
 *
 * @throws IOException If there was not set any TID for this transfer or if
 * there are problems getting the users home directory
 */
public static String getTempDir(TransferTaskContainer pContainer) throws IOException {
    if (pContainer != null) {
        LOGGER.debug("Determining transfer tmp directory.");
        File userHome = SystemUtils.getUserHome();
        if (!isAccessibleDirectory(userHome)) {
            //user home not usable (maybe no home directory available). Try system temp dir...
            userHome = SystemUtils.getJavaIoTmpDir();
            if (!isAccessibleDirectory(userHome)) {
                throw new IOException("Failed to obtain valid temp directory. UserHome ("
                        + SystemUtils.getUserHome() + ") and TmpDir (" + userHome + ") are not usable.");
            } else {
                LOGGER.debug("Using tmp directory.");
            }
        } else {
            LOGGER.debug("Using user home directory.");
        }

        return FilenameUtils.concat(FilenameUtils.concat(userHome.getCanonicalPath(), ".lsdf"),
                URLEncoder.encode(pContainer.getUniqueTransferIdentifier(), "UTF-8"));
    } else {
        throw new IOException(
                "Failed to obtain temporary transfer directory. Transfer container must not be 'null'");
    }
}