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.cornell.med.icb.goby.readers.sam.TestSamRecordParser.java

/**
 * We had a problem with the target indexes/lengths being written twice in SamToCompact. The second
 * time was wrong. This checks that it is right.
 *
 * @throws java.io.IOException error/*from  ww w  .j a va  2  s  .c  o  m*/
 */
@Test
public void testTestTargetIndexCreation() throws IOException {
    final RoundTripAlignment rtc = new RoundTripAlignment();
    rtc.inputGenomeFilename = TestGobyPaperTop5000s.findMM9();
    rtc.sourceBamFilename = FilenameUtils.concat("test-data/goby-paper-top-5000s", "JRODTYG-5000.sam.gz");
    rtc.destGobyBasename = FilenameUtils.concat(BASE_TEST_OUTPUT_DIR, "JRODTYG-5000");
    rtc.createCompactFromSam();

    final AlignmentReaderImpl gobyReader = new AlignmentReaderImpl(rtc.destGobyBasename);
    gobyReader.readHeader();
    final int[] targetsLengths = gobyReader.getTargetLength();
    final IndexedIdentifier identifiers = gobyReader.getTargetIdentifiers();
    final int chr1Index = identifiers.getInt(new MutableString("chr1"));
    Assert.assertEquals("Incorrect sequence length", 197195432, targetsLengths[chr1Index]);
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractConnectorController.java

private void setImagePath(String rootImageDir, ServiceInstance serviceInstance, MultipartFile logoFile) {
    String serviceInstanceDir = "serviceInstance";
    File file = new File(FilenameUtils.concat(rootImageDir, serviceInstanceDir));
    if (!file.exists()) {
        file.mkdir();//w ww.ja  va  2 s  .  c o  m
    }
    String serviceInstanceAbsoluteDir = FilenameUtils.concat(rootImageDir, serviceInstanceDir);
    String relativeImageDir = FilenameUtils.concat(serviceInstanceDir, serviceInstance.getId().toString());
    File file1 = new File(FilenameUtils.concat(serviceInstanceAbsoluteDir, serviceInstance.getId().toString()));
    if (!file1.exists()) {
        file1.mkdir();
    }

    try {
        if (StringUtils.isNotBlank(logoFile.getOriginalFilename())) {
            String logoFileRelativePath = writeMultiPartFileToLocalFile(rootImageDir, relativeImageDir,
                    logoFile);
            serviceInstance.setImagePath(logoFileRelativePath);
        }
        connectorConfigurationManager.updateServiceInstance(serviceInstance);
    } catch (IOException e) {
        logger.debug("###IO Exception in writing custom image file");
    }
}

From source file:net.sf.jvifm.ui.FileLister.java

private void editFileName() {
    editor = new TableEditor(table);
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;/*  w w w.j av a  2s. co m*/
    editor.minimumWidth = 20;
    Control oldEditor = editor.getEditor();
    if (oldEditor != null)
        oldEditor.dispose();

    TableItem item = table.getItem(currentRow);
    if (item == null)
        return;

    final Text newEditor = new Text(table, SWT.NONE);
    newEditor.setText(item.getText(0));
    newEditor.addFocusListener(new FocusAdapter() {
        public void focusLost(FocusEvent arg0) {
            newEditor.dispose();
        }
    });
    newEditor.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.CR && !newEditor.getText().trim().equals("")) { //$NON-NLS-1$
                TableItem item = table.getItem(currentRow);
                File currentFile = new File(FilenameUtils.concat(pwd, item.getText(0)));
                boolean isSuccess = currentFile
                        .renameTo(new File(FilenameUtils.concat(pwd, newEditor.getText().trim())));
                if (isSuccess) {
                    fileManager.setStatusInfo("rename filename successed."); //$NON-NLS-1$
                } else {
                    fileManager.setStatusInfo("rename filename failed."); //$NON-NLS-1$
                }
                item.setText(newEditor.getText().trim());
                newEditor.dispose();
                table.setFocus();
            }
            if (event.keyCode == SWT.ESC || (event.keyCode == '[' && event.stateMask == SWT.CTRL)) {
                newEditor.dispose();
                table.setFocus();
            }
        }

    });
    newEditor.selectAll();
    newEditor.setFocus();
    editor.setEditor(newEditor, item, 0);
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

private String exportFile(String importedBasename, String genomePath) throws IOException {
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR,
            "round-trip-output" + counterSam++ + ".sam");

    CompactToSAMMode exporter = new CompactToSAMMode();
    exporter.setInputBasename(importedBasename);
    exporter.setOutput(outputFilename);//www .j  a v a2  s .co  m
    if (genomePath != null) {
        exporter.setGenome(new PicardFastaIndexedSequence(genomePath));

    } else {

        RandomAccessSequenceInterface genomeTestSupport = new RandomAccessSequenceInterface() {

            @Override
            public char get(int referenceIndex, int position) {
                return 'A';
            }

            @Override
            public int getLength(int targetIndex) {
                return Integer.MAX_VALUE;
            }

            @Override
            public void getRange(int referenceIndex, int position, int length, MutableString bases) {
                bases.setLength(0);
                for (int i = 0; i < length; i++) {
                    bases.append('A');
                }
            }

            @Override
            public int getReferenceIndex(String referenceId) {
                return 0;
            }

            @Override
            public String getReferenceName(int index) {
                return "ref-id";
            }

            @Override
            public int size() {
                return 5;
            }
        };

        exporter.setGenome(genomeTestSupport);
    }
    exporter.execute();
    return outputFilename;
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

private String importFile(String filename, boolean preserveSoftClips, boolean preserveAllReadQuals)
        throws IOException {
    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile(filename);/*from w  w  w.j a  va 2s  . co m*/
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR,
            "round-trip-input-alignment-" + counterGoby++);
    importer.setOutputFile(outputFilename);
    importer.setPreserveReadName(true);
    importer.setPreserveSoftClips(preserveSoftClips);
    //  importer.setPropagateTargetIds(true);
    importer.setPreserveReadQualityScores(true);
    importer.setPreserveAllTags(true);

    importer.execute();
    return outputFilename;
}

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractSubscriptionController.java

@RequestMapping(value = { "/{customPageTag}/{serviceInstanceUuid}/{resourceType}" }, method = RequestMethod.GET)
@ResponseBody// w  w w  . j  ava2  s . co m
public void getCustomSelector(@PathVariable String serviceInstanceUuid, @PathVariable String resourceType,
        @PathVariable String customPageTag, ModelMap map, HttpServletResponse response) {
    FileInputStream fileinputstream = null;
    try {
        Service service = connectorConfigurationManager.getInstance(serviceInstanceUuid).getService();
        ServiceResourceType selectedResourceType = null;
        for (ServiceResourceType serviceResourceType : service.getServiceResourceTypes()) {
            if (serviceResourceType.getResourceTypeName().equals(resourceType)) {
                selectedResourceType = serviceResourceType;
                break;
            }
        }
        String jspPath = "";
        String cssdkFilesDirectory = FilenameUtils.concat(
                config.getValue(Names.com_citrix_cpbm_portal_settings_services_datapath),
                service.getServiceName() + "_" + service.getVendorVersion());
        if (selectedResourceType != null) {
            if (customPageTag.equalsIgnoreCase("customComponentSelector")) {
                jspPath = selectedResourceType.getComponentSelector();
            } else if (customPageTag.equalsIgnoreCase("customEditorTag")) {
                jspPath = selectedResourceType.getEditor();
            }
            if (jspPath != null && !jspPath.trim().equals("")) {
                String absoluteJspPath = FilenameUtils.concat(cssdkFilesDirectory, jspPath);
                fileinputstream = new FileInputStream(absoluteJspPath);
                if (fileinputstream != null) {
                    int numberBytes = fileinputstream.available();
                    byte bytearray[] = new byte[numberBytes];
                    fileinputstream.read(bytearray);
                    response.setContentType("text/html");
                    OutputStream outputStream = response.getOutputStream();
                    response.setContentLength(numberBytes);
                    outputStream.write(bytearray);
                    outputStream.flush();
                    outputStream.close();
                    fileinputstream.close();
                    return;
                }
            }
        }
    } catch (FileNotFoundException e) {
        logger.debug("###File not found in retrieving custom ui contribution.");
    } catch (IOException e) {
        logger.debug("###IO Error in retrieving custom ui contribution.");
    }
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private NewTargetFile getNewTargetFileObject(int storeId, String parentPath, String name, boolean overwrite)
        throws FileSystemException, WTException {
    String newPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parentPath, name));

    if (overwrite) {
        return new NewTargetFile(newPath, getTargetFileObject(storeId, newPath));
    } else {/*from  w  ww.j a  v a  2  s .co m*/
        FileObject newFo = getTargetFileObject(storeId, newPath);
        if (!newFo.exists()) {
            return new NewTargetFile(newPath, newFo);
        } else {
            String ext = FilenameUtils.getExtension(name);
            String suffix = StringUtils.isBlank(ext) ? "" : "." + ext;
            String baseName = FilenameUtils.getBaseName(name);
            int i = 0;
            do {
                i++;
                final String newName = baseName + " (" + i + ")" + suffix;
                newPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(parentPath, newName));
                newFo = getTargetFileObject(storeId, newPath);
            } while (newFo.exists());
            return new NewTargetFile(newPath, newFo);
        }
    }
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private String doRenameStoreFile(int storeId, String path, String newName)
        throws FileSystemException, SQLException, DAOException, WTException {
    SharingLinkDAO dao = SharingLinkDAO.getInstance();
    FileObject tfo = null, ntfo = null;
    Connection con = null;/*from ww  w .j a va  2 s .c  o  m*/

    try {
        tfo = getTargetFileObject(storeId, path);
        String newPath = FilenameUtils
                .separatorsToUnix(FilenameUtils.concat(FilenameUtils.getFullPath(path), newName));
        ntfo = getTargetFileObject(storeId, newPath);

        logger.debug("Renaming store file [{}, {} -> {}]", storeId, path, newPath);
        try {
            con = WT.getConnection(SERVICE_ID, false);

            dao.deleteByStorePath(con, storeId, path);
            tfo.moveTo(ntfo);
            DbUtils.commitQuietly(con);

        } catch (FileSystemException ex1) {
            DbUtils.rollbackQuietly(con);
            throw ex1;
        } finally {
            DbUtils.closeQuietly(con);
        }
        return newPath;

    } finally {
        IOUtils.closeQuietly(tfo);
        IOUtils.closeQuietly(ntfo);
    }
}

From source file:net.pms.medialibrary.commons.helpers.FileImportHelper.java

/**
 * Cleans the received fileName according to the rules defined in filename_replace_expressions.txt
 * @param fileName the name to clean/*from w w  w  .  j a  v  a2 s. c  om*/
 * @return the cleaned name
 */
private static String getCleanName(String fileName) {
    File configFile = new File(FilenameUtils.concat(PMS.getConfiguration().getProfileDirectory(),
            "filename_replace_expressions.txt"));

    String res = fileName;
    Scanner scanner = null;
    try {
        scanner = new Scanner(new FileInputStream(configFile.getAbsolutePath()), "UTF-8");
        String regex;
        String replaceText;
        while (scanner.hasNextLine()) {
            regex = scanner.nextLine();
            if (scanner.hasNextLine()) {
                replaceText = scanner.nextLine();
            } else {
                break;
            }
            res = res.replaceAll(regex, replaceText);
        }
    } catch (FileNotFoundException e) {
        if (log.isDebugEnabled())
            log.debug(String.format("File '%s' not found. Ignore file name cleaning",
                    configFile.getAbsolutePath()));
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }

    res = res.trim();
    if (!res.equals(fileName)) {
        if (log.isInfoEnabled())
            log.info(String.format("Cleaned up file '%s' to '%s'", fileName, res));
    }
    return res;
}

From source file:com.ms.commons.test.BaseTestCase.java

protected void initOnBeforeEveryTestCase() {
    log.debug("=========================> BaseTestCase.initOnBeforeEveryTestCase() init db data");
    String basePath = getClassBasePath();
    if (basePath.contains("com.mountainminds.eclemma.core")) { // if run in eclemma
        System.err.println("Run in eclemma we try to change base path!");
        String userDir = IntlTestGlobalConstants.USER_DIR;

        if (new File(FilenameUtils.concat(userDir, "src/java")).exists()) {
            basePath = getFinalClassBasePath(userDir + "/src/java.test/");
        } else if (new File(FilenameUtils.concat(userDir, "src/main")).exists()) {
            basePath = getFinalClassBasePath(userDir + "/src/test/java");
        } else {/*  ww w.j  a  va  2  s  .co m*/
            System.err.println("Oh, we cannot detect is antx or maven.");
        }
    }
    log.info("Base path set to `" + basePath + "`.");
    BaseReaderUtil.setBasePath(basePath);

    initMemoryDatabaseOnBeforeEveryTestCase();
}