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.utils.FbxConv.java

public FbxConvResult execute() {
    FbxConvResult result = new FbxConvResult();
    if (input == null || output == null) {
        result.setSuccess(false);/*from   w  ww  .  j  a v a2s .  c  o m*/
        result.setResultCode(FbxConvResult.RESULT_CODE_PARAM_ERROR);
        Log.error("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("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.TestPositionSlices.java

@Test
public void testTwoSlice() throws IOException {
    final String basename = "align-position-slices-2";
    buildAlignment(basename);//from   w ww  . j a v  a  2s  .c  om

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

        check(reader, 1, 12);

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

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

/**
 * Text or basic HTML to initially display, saved at config/init_text.txt
 *
 * @return//from   w ww.  j  av a 2s. c  o m
 */
public static String getInitTextFile() {
    return FilenameUtils.concat(installerDir, "config/init_text.txt");
}

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

@Test
public void testMergeWithTargetIds() throws IOException {
    final Merge merger = new Merge(3);

    final List<File> inputFiles = new ArrayList<File>();
    inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-105")));

    final String outputFile = FilenameUtils.concat(BASE_TEST_DIR, "out-105-merged");
    merger.setK(2);/*from w w  w.  j  a v  a  2s  .  c  om*/
    merger.merge(inputFiles, outputFile);

    // With k=2 and a single input file, the merge should keep only the best score for each query:
    final String basename = outputFile;
    final int count = countAlignmentEntries(basename);
    assertEquals(numQueries101, count);

}

From source file:es.urjc.mctwp.bbeans.research.image.AbstractViewImages.java

/**
 * It prepares a valid thumbnail for JSF from a valid ImageDate. 
 * It writes the thumbnail image into a file contained in the 
 * user session dir./*w w w  . ja va2  s .com*/
 * 
 * @param image
 * @return
 * @throws IOException
 * @throws SQLException
 * @throws FileNotFoundException
 */
protected ThumbSelectItem getThumbnailContent(ImageData image)
        throws IOException, SQLException, FileNotFoundException {
    String base = getSession().getAbsoluteThumbDir();
    String name = image.getImageId() + FilenameUtils.EXTENSION_SEPARATOR_STR + ThumbNail.TBN_EXT;
    int length = image.getThumbnailSize();

    //Create file for thumbnail and get output stream to write it
    File file = new File(FilenameUtils.concat(base, name));
    FileOutputStream fos = new FileOutputStream(file);

    //write thumbnail content into file
    byte[] thContent = new byte[length];
    image.getThumbnailStream().read(thContent, 0, length);
    fos.write(thContent);
    fos.close();

    //Create thumbnail and view layer thumbnail. It is neccesary to
    //reference the thumbnail from a relative path in order to work
    //into view
    base = getSession().getRelativeThumbDir();
    file = new File(FilenameUtils.concat(base, name));
    ThumbNail tn = new ThumbNail();
    tn.setContent(file);
    tn.setId(image.getImageId());

    ThumbSelectItem tsi = new ThumbSelectItem();
    tsi.setThumbId(tn.getId());
    tsi.setPath(tn.getContent().getPath());
    tsi.setImageId(image.getCode());
    return tsi;
}

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

@Test
public void testLoadTwoAdjustFalse() throws IOException {
    final int count;

    final ConcatAlignmentReader concatReader = new ConcatAlignmentReader(false, outputBasename2,
            outputBasename1);/*from  w  ww  . j  a  v  a  2  s .  co  m*/
    count = countAlignmentEntries(concatReader);
    assertEquals(count101 + count102, count);
    concatReader.readHeader();
    System.out.println(concatReader.getSmallestSplitQueryIndex());
    System.out.println(concatReader.getLargestSplitQueryIndex());
    // since both input alignments have permutations and distinct query indices, the total number of query index is
    // the sum of the two:
    assertEquals(numQueries101 + numQueries102, concatReader.getNumberOfQueries());

    concatReader.close();
    final ConcatAlignmentReader reader = new ConcatAlignmentReader(false, outputBasename2, outputBasename1);

    final String globalPermBasename = FilenameUtils.concat(BASE_TEST_DIR, "concatenated-permutation");

    concatReader.getConcatPerm().concatenate(globalPermBasename);
    PermutationReader permReader = new PermutationReader(globalPermBasename);

    while (concatReader.hasNext()) {
        final Alignments.AlignmentEntry alignmentEntry = reader.next();
        final int smallIndex = alignmentEntry.getQueryIndex();
        int queryIndex = permReader.getQueryIndex(smallIndex);
        final boolean score = alignmentEntry.getScore() == 30;
        if (score) {

            assertTrue(queryIndex >= 2000 && queryIndex <= 2010);
        }
        if (alignmentEntry.getScore() == 50) {

            assertTrue(queryIndex >= 1000 && queryIndex <= 1013);
        }

    }

    assertEquals(numTargets, concatReader.getNumberOfTargets());

}

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

/**
 * Attempts to create a temporary directory in the installer folder to
 * unpack the jar./*  w  ww .  j  av a2s  .co  m*/
 *
 * @return
 * @throws IOException
 */
private static File getTempDir() throws IOException {
    Random rand = new Random();
    String hex = Integer.toHexString(rand.nextInt(Integer.MAX_VALUE));
    File tmp = new File(FilenameUtils.concat(InstallerConfig.getInstallerDir(), hex + "/"));
    int t = 0;
    while (tmp.exists() && t < 10) {
        hex = Integer.toHexString(rand.nextInt(Integer.MAX_VALUE));
        tmp = new File(FilenameUtils.normalize("./" + hex + "/"));
        t++;
    }
    if (tmp.exists()) {
        throw new IOException("Error creating temporary folder. Too many failures.");
    }
    return tmp;
}

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

@Test
public void writeEmptyIds() throws IOException {
    final AlignmentWriter writer = new AlignmentWriterImpl(
            FilenameUtils.concat(BASE_TEST_DIR, "align-emptyids"));
    final IndexedIdentifier queryIds = new IndexedIdentifier();
    assertNotNull(queryIds.keySet());/*from ww  w  .j a v  a 2  s.com*/
    writer.setQueryIdentifiers(queryIds);
    writer.setTargetIdentifiers(queryIds);
    writer.close();

    // TODO: assert something here
}

From source file:ie.deri.unlp.javaservices.topicextraction.topicextractor.gate.TopicExtractorGate.java

public void initGate() throws GateException {
    if (!gateInitialised) {
        logger.info("Initializing GATE");
        try {/* ww w. ja  va  2 s. c  o  m*/
            URI url = getClass().getResource("/gate").toURI();
            logger.info("URL to GATE resources: " + url);

            File gateHome;
            if (url.isOpaque()) {
                /*
                 * GATE only has an interface for File objects, which means the files have to be on the filesystem.
                 * If we're running from a JAR we first have to extract the gate/ folder from the JAR. 
                 */

                logger.info("Unpacking GATE resources from JAR");
                String tempDirectoryPath = FileUtils.getTempDirectoryPath();
                //Delete any existing directory
                String gateResource = "gate";
                FileUtils.deleteDirectory(new File(FilenameUtils.concat(tempDirectoryPath, gateResource)));
                String gateHomePath = extractDirectoryFromClasspathJAR(getClass(), gateResource,
                        tempDirectoryPath);
                gateHome = new File(gateHomePath);

            } else {
                gateHome = new File(url);
            }

            Gate.setGateHome(gateHome);
            Gate.setSiteConfigFile(new File(gateHome, "gate-site.xml"));
            Gate.setUserConfigFile(new File(gateHome, "gate-user.xml"));
            // Gate.setUserSessionFile(new File(gateHome, GATE_SESSION));

            Gate.setPluginsHome(new File(gateHome, "plugins/"));

            Gate.init();

            Iterator<URL> pluginItr = Gate.getKnownPlugins().iterator();
            while (pluginItr.hasNext()) {
                URL pluginURL = pluginItr.next();
                Gate.getCreoleRegister().registerDirectories(pluginURL);
            }

            logger.log(Level.INFO, "configuring GATE processor pool..");

            gateProcessorPool = GateProcessorPool.getInstance();

            gateInitialised = true;

        } catch (IOException | URISyntaxException | GateException exn) {
            throw new GateException("Exception while initializing GATE resources", exn);
        }
        logger.info("GATE Initialized");
    }
}

From source file:com.enioka.jqm.api.ServiceSimple.java

@GET
@Path("stderr")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public InputStream getLogErr(@QueryParam("id") int id) {
    res.setHeader("Content-Disposition", "attachment; filename=" + id + ".stderr.txt");
    return getFile(FilenameUtils.concat("./logs", StringUtils.leftPad("" + id, 10, "0") + ".stderr.log"));
}