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

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

Introduction

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

Prototype

public static String separatorsToSystem(String path) 

Source Link

Document

Converts all separators to the system separator.

Usage

From source file:org.silverpeas.core.importexport.versioning.DocumentVersion.java

/**
 * Return the path to the document file.
 *
 * @return the path to the document file.
 *//*ww  w  .  java 2s. c om*/
public String getDocumentPath() {
    if (isPhysicalPathAbsolute()) {
        return FilenameUtils.separatorsToSystem(physicalName);
    }
    String directory = FileRepositoryManager.getAbsolutePath(getInstanceId(), new String[] { CONTEXT });
    directory = FilenameUtils.separatorsToSystem(directory);
    if (!directory.endsWith(File.separator)) {
        directory += File.separator;
    }
    return directory + getPhysicalName();
}

From source file:org.sonar.application.PropsTest.java

@Test
public void fail_if_file_does_not_exist() throws Exception {
    Env env = mock(Env.class);
    when(env.file("conf/sonar.properties")).thenReturn(new File("target/not_exist/sonar.properties"));

    try {//ww w  .ja v a2s  .c  om
        Props.create(env);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("File does not exist or can't be open: "
                + FilenameUtils.separatorsToSystem("target/not_exist/sonar.properties"));
    }
}

From source file:org.sonar.java.xml.XmlParserTest.java

@Test
public void empty_xml_file_should_produce_a_nice_warning_log() throws Exception {
    XmlParser.parseXML(new File("src/test/files/xml/empty.xml"));
    assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
    String filename = FilenameUtils.separatorsToSystem("src/test/files/xml/empty.xml");
    assertThat(logTester.logs(LoggerLevel.WARN))
            .contains("File " + filename + " is empty and won't be analyzed.");
}

From source file:org.sonar.java.xml.XmlParserTest.java

@Test
public void should_return_null_when_encountering_parsing_issue() {
    logTester.setLevel(LoggerLevel.DEBUG);
    assertThat(XmlParser.parseXML(new File("src/test/files/xml/parsing-issue.xml"))).isNull();
    String filename = FilenameUtils.separatorsToSystem("src/test/files/xml/parsing-issue.xml");
    assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Unable to parse xml file: " + filename);
    assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1).allSatisfy(s -> s.startsWith(
            "XML file parsing failed because of : org.xml.sax.SAXParseException; systemId: file: "));
}

From source file:org.sonar.java.xml.XmlParserTest.java

@Test
public void should_not_log_debug_info_if_debug_is_disabled() {
    logTester.setLevel(LoggerLevel.INFO);
    assertThat(XmlParser.parseXML(new File("src/test/files/xml/parsing-issue.xml"))).isNull();
    String filename = FilenameUtils.separatorsToSystem("src/test/files/xml/parsing-issue.xml");
    assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Unable to parse xml file: " + filename);
    assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
}

From source file:org.sparkcommerce.cms.file.service.StaticAssetStorageServiceImpl.java

@Transactional("blTransactionManagerAssetStorageInfo")
@Override//w  w  w .jav a  2  s.c  om
public void createStaticAssetStorageFromFile(MultipartFile file, StaticAsset staticAsset) throws IOException {
    if (StorageType.DATABASE.equals(staticAsset.getStorageType())) {
        StaticAssetStorage storage = staticAssetStorageDao.create();
        storage.setStaticAssetId(staticAsset.getId());
        Blob uploadBlob = staticAssetStorageDao.createBlob(file);
        storage.setFileData(uploadBlob);
        staticAssetStorageDao.save(storage);
    } else if (StorageType.FILESYSTEM.equals(staticAsset.getStorageType())) {
        FileWorkArea tempWorkArea = sparkFileService.initializeWorkArea();
        // Convert the given URL from the asset to a system-specific suitable file path
        String destFileName = FilenameUtils.normalize(tempWorkArea.getFilePathLocation() + File.separator
                + FilenameUtils.separatorsToSystem(staticAsset.getFullUrl()));

        InputStream input = file.getInputStream();
        byte[] buffer = new byte[fileBufferSize];

        File destFile = new File(destFileName);
        if (!destFile.getParentFile().exists()) {
            if (!destFile.getParentFile().mkdirs()) {
                if (!destFile.getParentFile().exists()) {
                    throw new RuntimeException("Unable to create parent directories for file: " + destFileName);
                }
            }
        }

        OutputStream output = new FileOutputStream(destFile);
        boolean deleteFile = false;
        try {
            int bytesRead;
            int totalBytesRead = 0;
            while ((bytesRead = input.read(buffer)) != -1) {
                totalBytesRead += bytesRead;
                if (totalBytesRead > maxUploadableFileSize) {
                    deleteFile = true;
                    throw new IOException("Maximum Upload File Size Exceeded");
                }
                output.write(buffer, 0, bytesRead);
            }

            // close the output file stream prior to moving files around

            output.close();
            sparkFileService.addOrUpdateResource(tempWorkArea, destFile, deleteFile);
        } finally {
            IOUtils.closeQuietly(output);
            sparkFileService.closeWorkArea(tempWorkArea);
        }
    }
}

From source file:org.sugarcrm.voodoodriver.EventLoop.java

private WebElement filefieldEvent(VDDHash event, WebElement parent) {
    boolean required = true;
    WebElement element = null;/*www .  ja  v  a 2 s.c  o m*/

    this.report.Log("FileField event Started.");
    this.resetThreadTime();

    if (event.containsKey("required")) {
        required = this.clickToBool(event.get("required").toString());
    }

    try {
        element = this.findElement(event, parent, required);
        if (element == null) {
            this.report.Log("FileField event finished.");
            return element;
        }

        this.firePlugin(element, Elements.FILEFIELD, PluginEvent.AFTERFOUND);

        this.checkDisabled(event, element);

        if (event.containsKey("set")) {
            String setvalue = event.get("set").toString();
            setvalue = this.replaceString(setvalue);
            setvalue = FilenameUtils.separatorsToSystem(setvalue);
            setvalue = (new File(setvalue)).getAbsolutePath();
            this.report.Log(String.format("Setting filefield to: '%s'.", setvalue));
            element.sendKeys(setvalue);
            this.report.Log("Finished set.");
        }

        String value = element.getAttribute("value");
        handleVars(value, event);

    } catch (ElementNotVisibleException exp) {
        logElementNotVisible(required, event);
    } catch (Exception exp) {
        element = null;
        this.report.ReportException(exp);
    }

    this.report.Log("FileField event finished..");
    this.resetThreadTime();
    return element;
}

From source file:org.sugarcrm.voodoodriver.Reporter.java

/**
 * Instantiate a Reporter object./*from  w  ww .  j  av  a 2 s. c  om*/
 *
 * @param reportName
 * @param resultDir
 */

public Reporter(String reportName, String resultDir, VDDHash config) {
    Date now = new Date();
    String frac = String.format("%1$tN", now);
    String date_str = String.format("%1$tm-%1$td-%1$tY-%1$tI-%1$tM-%1$tS", now);
    frac = frac.subSequence(0, 3).toString();
    date_str += String.format("-%s", frac);

    this.LineSeparator = System.getProperty("line.separator");

    if (resultDir != null) {
        File dir = new File(resultDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        this.resultDir = resultDir;
    } else {
        this.resultDir = System.getProperty("user.dir");
    }

    reportLog = this.resultDir + "/" + reportName + "-" + date_str + ".log";
    reportLog = FilenameUtils.separatorsToSystem(reportLog);
    System.out.printf("ReportFile: %s\n", reportLog);

    try {
        reportFD = new FileOutputStream(reportLog);
    } catch (java.io.FileNotFoundException e) {
        System.err.println("(!)Unable to create report file: " + e);
    }

    /* Initialize screenshot and savehtml events */
    String ssEvents[] = { "warning", "error", "assertfail", "exception", "watchdog" };
    this.saveHtmlOn = new VDDHash();
    this.screenshotOn = new VDDHash();
    for (String ssEvent : ssEvents) {
        this.saveHtmlOn.put(ssEvent, false);
        this.screenshotOn.put(ssEvent, false);
    }

    this.haltOnFailure = (Boolean) config.get("haltOnFailure");
}

From source file:org.sugarcrm.voodoodriver.Reporter.java

/**
 * Create a file name./*from   ww  w.j  a va  2s. c o m*/
 *
 * Use the specified directory, file name root, and file index to
 * create the filename.  The directory is assumed to be relative to
 * resultDir.
 *
 * @param dir   the directory in which to create the file name
 * @param file  the file name root
 * @param idx   one-up index of this file
 * @param ext   file extension
 * @return path and file name
 */

private String makeFilename(String dir, String file, int idx, String ext) {
    String test = "";

    String outfile = this.resultDir + "/" + dir;

    File checkDir = new File(outfile);
    if (!checkDir.exists()) {
        checkDir.mkdir();
    }

    if (this.testName != null) {
        File tmp = new File(this.testName);
        test = tmp.getName();
        test = String.format("%s-", test.substring(0, test.length() - 4));
    }

    outfile += String.format("/%s%s-%d.%s", test, file, idx, ext);

    return FilenameUtils.separatorsToSystem(outfile);
}

From source file:org.sugarcrm.voodoodriver.Utils.java

/**
 * Reads a text file into a String object.
 *
 * @param filename  the file to read in.
 * @return {@link String} containing the contents of the file
 *
 *//*  ww  w . j a  v a 2s .co m*/

public static String FileToStr(String filename) throws java.io.FileNotFoundException, java.io.IOException {
    String result = "";
    BufferedReader reader = null;

    filename = FilenameUtils.separatorsToSystem(filename);
    reader = new BufferedReader(new FileReader(filename));
    String line = "";
    while ((line = reader.readLine()) != null) {
        result = result.concat(line + "\n");
    }
    reader.close();

    return result;
}