Example usage for org.apache.commons.io IOUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.io IOUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.io IOUtils LINE_SEPARATOR.

Click Source Link

Document

The system line separator string.

Usage

From source file:jatoo.maven.plugin.set_license.SetLicenseHeaderMojo.java

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();

    final String licenseHeaderText;

    if (license == null) {

        if (licenseHeader == null) {
            throw new MojoExecutionException("both parameters 'license' and 'licenseHeader' are missing");
        }//  ww  w  . jav  a  2  s. c o m

        try {
            licenseHeaderText = FileUtils.readFileToString(licenseHeader).trim();
        } catch (IOException e) {
            throw new MojoExecutionException("error reading license header file (" + licenseHeader + ")", e);
        }
    }

    else {

        if (copyright == null) {
            throw new MojoExecutionException("the parameter 'copyright' is missing");
        }

        try {
            licenseHeaderText = IOUtils.toString(getClass().getResource("licenses/" + license + "/HEADER"))
                    .replaceAll("\\$\\{copyright\\}", copyright).trim();
        } catch (IOException e) {
            throw new MojoExecutionException("error reading license (" + license + ") header", e);
        }
    }

    log.info("license header text: " + IOUtils.LINE_SEPARATOR + licenseHeaderText);

    final DirectoryScanner directoryScanner = new DirectoryScanner();
    directoryScanner.setIncludes(includes);
    directoryScanner.setBasedir(project.getBasedir());
    directoryScanner.scan();

    log.info("setting license header text on files:");

    for (String file : directoryScanner.getIncludedFiles()) {
        log.info(file);

        try {

            String fileContent = FileUtils.readFileToString(new File(project.getBasedir(), file));
            int index = fileContent.indexOf("package ");

            int indexComments = fileContent.indexOf("/**");
            if (indexComments >= 0 && indexComments <= index) {
                index = indexComments;
            }

            fileContent = fileContent.substring(index);

            File targetFolder = new File(project.getBuild().getDirectory());
            if (!targetFolder.exists() && !targetFolder.mkdirs()) {
                throw new MojoExecutionException("error creating target folder");
            }

            FileUtils.write(new File(project.getBasedir(), file),
                    licenseHeaderText + IOUtils.LINE_SEPARATOR + IOUtils.LINE_SEPARATOR + fileContent);
        }

        catch (IOException e) {
            throw new MojoExecutionException("error writing license header in " + file, e);
        }

    }
}

From source file:net.mikaboshi.intra_mart.tools.log_stats.parser.ExceptionLogParserV7.java

public ExceptionLog parse(String string) {

    if (string == null) {
        return null;
    }// ww w  .jav a  2  s .c  o m

    String[] lines = LogStringUtil.lines(string);

    if (lines.length < 9) {
        warn("invalid exception log");
        this.parameter.getErrorCounter().increment();
        return null;
    }

    ExceptionLog log = new ExceptionLog();

    log.groupingType = this.parameter.getExceptionGroupingType();

    try {
        log.date = dateFormat.parse(getValue(lines[0]));

    } catch (ParseException e) {
        warn("invalid date : " + lines[0]);
        this.parameter.getErrorCounter().increment();
        return null;
    }

    if (!isInRange(log)) {
        return null;
    }

    log.level = Level.toEnum(getValue(lines[1]));

    log.logger = getValue(lines[2]);

    log.logId = getValue(lines[3]);

    log.thread = getValue(lines[4]);

    log.logThreadGroup = getValue(lines[5]);

    log.message = getValue(lines[6]);

    for (int i = 7; i < lines.length; i++) {

        if (lines[i].length() == 0 && i < lines.length - 1
                && STACKTRACE_BIGIN_PATTERN.matcher(lines[i + 1]).find()) {

            // ??????? => ???
            log.stackTrace = StringUtils.join(ArrayUtils.subarray(lines, i + 1, lines.length - 1),
                    IOUtils.LINE_SEPARATOR);
            break;

        } else {
            // ???
            log.message += IOUtils.LINE_SEPARATOR + lines[i];
        }
    }

    return log;
}

From source file:com.ss.language.model.gibblda.Document.java

/**
 * ?// w ww . j a va2  s  .  c om
 * 
 * @param words
 */
private void storeDoc(Vector<Integer> words) {
    if (words.size() > 0) {
        docId = nextDocId();
        StringBuilder wordIds = new StringBuilder();
        Map<Integer, Integer> maps = new LinkedHashMap<Integer, Integer>();
        for (Integer wordId : words) {
            if (wordId != null) {
                wordIds.append(wordId);
                wordIds.append(",");
                Integer times = maps.get(wordId);
                if (times == null) {
                    times = 1;
                } else {
                    times += 1;
                }
                maps.put(wordId, times);
            }
        }
        LuceneDataAccess.save(DOC_PRE + docId, wordIds.substring(0, wordIds.length() - 1));
        // ???
        LDACmdOption option = LDACmdOption.curOption.get();
        File file = null;
        if (option.eachwords != null && option.eachwords.trim().length() > 0) {
            file = new File(option.dir + File.separator + option.eachwords);
            StringBuffer sb = new StringBuffer();
            for (Integer wordId : maps.keySet()) {
                sb.append(wordId);
                sb.append(":");
                sb.append(maps.get(wordId));
                sb.append(", ");
            }
            String line = sb.length() > 0 ? sb.substring(0, sb.length() - 2) : sb.toString();
            line += IOUtils.LINE_SEPARATOR;
            try {
                FileUtils.write(file, line, "UTF-8", true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:es.caib.sgtsic.xml.XmlManager.java

public String generateFlatXmlString(List<T> items) throws JAXBException {

    StringBuilder mensajes = new StringBuilder();
    for (T item : items) {
        mensajes.append(generateFlatXmlString(item));
        mensajes.append(IOUtils.LINE_SEPARATOR);
    }// ww w.  j  a v a  2  s  .c o m
    return mensajes.toString();

}

From source file:com.ss.language.model.gibblda.Estimator.java

/**
 * ???//from  w  w  w. ja  v  a 2s. co m
 * 
 * @param docs
 */
private void writeEachwordsEachWord(Document[] docs) {
    if (docs != null && docs.length > 0) {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(
                    new FileInputStream(trnModel.data.localDict.getWordIdsFile()), "UTF-8"));
            for (String wordId = br.readLine(); wordId != null; wordId = br.readLine()) {
                wordId = wordId == null ? "" : wordId.trim();
                if (wordId.isEmpty()) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for (Document doc : docs) {
                    String[] words = doc.getAllWords();
                    if (words != null && words.length > 0) {
                        int times = 0;
                        for (String w : words) {
                            if (wordId.equals(w)) {
                                times += 1;
                            }
                        }
                        if (times > 0) {
                            sb.append("(");
                            sb.append(doc.getDocId());
                            sb.append(":");
                            sb.append(times);
                            sb.append("),");
                        }
                    }
                }
                // ???
                if (sb.length() > 0) {
                    File file = new File(
                            option.dir + File.separator + option.wordMapFileName + "-statistic.txt");
                    sb.insert(0, "[");
                    sb.insert(sb.length() - 1, "]");
                    FileUtils.write(file, sb.subSequence(0, sb.length() - 1) + IOUtils.LINE_SEPARATOR, "UTF-8",
                            true);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                }
            }
        }
    }
}

From source file:com.perceptive.epm.perkolcentral.action.ImageNowLicenseAction.java

public String executeImageNowLicenseRequestView() throws ExceptionWrapper {
    try {/*w  w  w  .j  a  va2  s  . c  o m*/
        rallyGroups = groupsBL.getAllRallyGroups();
        getSpecificGroupsThatRequireINLicense();
        if (StringUtils.isNotEmpty(dupsub)) {
            errorMessage = errorMessage
                    + "* You are trying to re-submit a form that you have already submitted.Please wait for some time."
                    + IOUtils.LINE_SEPARATOR;
        }
    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return SUCCESS;
}

From source file:croche.maven.plugin.android.manifestv.CopyManifestMojo.java

/**
 * {@inheritDoc}/*from w  w  w  .  ja  v a2s.  c  om*/
 * @see org.apache.maven.plugin.Mojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    File sourceManifest = new File(this.manifestPath);
    if (!sourceManifest.canRead()) {
        throw new MojoFailureException("The manifest file: " + this.manifestPath
                + " set via the manifestPath configuration could not be read.");
    }
    File targetDir = new File(this.targetPath);
    if (!targetDir.canRead() && !targetDir.mkdirs()) {
        throw new MojoFailureException("The manifest targetPath: " + this.targetPath
                + " set via the targetPath configuration could not be read.");
    }

    File targetManifest = new File(targetDir, sourceManifest.getName());
    OutputStream os = null;
    try {
        os = new BufferedOutputStream(new FileOutputStream(targetManifest, false));
        LineIterator it = FileUtils.lineIterator(sourceManifest, this.encoding);
        Set<String> propNames = this.session.getExecutionProperties().stringPropertyNames();
        Properties props = this.session.getExecutionProperties();
        while (it.hasNext()) {
            String line = it.nextLine();
            // substitute any properies
            if (line.indexOf("${") > 0) {
                for (String propName : propNames) {
                    line = line.replace("${" + propName + "}", props.getProperty(propName));
                    if (line.indexOf("${") == -1) {
                        break;
                    }
                }
            }
            // special handling of the manifest version code
            String origVersionCode = "android:versionCode=\"" + this.replaceVersionCode + "\"";
            if (line.indexOf(origVersionCode) > -1) {
                String newVersionCode = this.session.getExecutionProperties()
                        .getProperty("manifestVersionCode");
                if (newVersionCode != null && newVersionCode.trim().length() > 0) {
                    line = line.replace(origVersionCode, "android:versionCode=\"" + newVersionCode + "\"");
                }
            }

            // write line out to output file
            os.write(line.toString().getBytes(this.encoding));
            os.write(IOUtils.LINE_SEPARATOR.getBytes(this.encoding));

        }
    } catch (IOException ex) {
        throw new MojoFailureException(
                "Failed to iterate over the content of the manifest file: " + sourceManifest.getAbsolutePath(),
                ex);
    } finally {
        if (os != null) {
            try {
                os.flush();
            } catch (IOException ex) {
                throw new MojoFailureException("The target manifest targetManifest: "
                        + targetManifest.getAbsolutePath() + " could not written to due to an io error.", ex);
            } finally {
                IOUtils.closeQuietly(os);
            }
        }
    }

}

From source file:com.shigengyu.hyperion.core.WorkflowInstance.java

public String debugString() {
    return "Workflow Instance <" + workflowDefinition.getName() + ">" + IOUtils.LINE_SEPARATOR + "ID = "
            + workflowInstanceId + IOUtils.LINE_SEPARATOR + "State = " + workflowStateSet;
}

From source file:edu.emory.bmi.aiw.i2b2export.output.HeaderRowOutputFormatterTest.java

@Test
public void testFormatHeader() throws IOException, SQLException {
    OutputConfigurationEntity config = new OutputConfigurationEntity();
    config.setName("foo");
    config.setUsername("i2b2");
    config.setRowDimension(RowDimension.PATIENT);
    config.setSeparator(",");
    config.setMissingValue("(NULL)");
    config.setWhitespaceReplacement("_");
    config.setColumnConfigs(new ArrayList<OutputColumnConfigurationEntity>());

    OutputColumnConfigurationEntity colConfig1 = new OutputColumnConfigurationEntity();
    colConfig1.setOutputConfig(config);//from w  w w . j  a  va 2  s  . co m
    colConfig1.setColumnOrder(1);
    colConfig1.setColumnName("Concept FOO");
    colConfig1.setDisplayFormat(DisplayFormat.EXISTENCE);

    OutputColumnConfigurationEntity colConfig2 = new OutputColumnConfigurationEntity();
    colConfig2.setOutputConfig(config);
    colConfig2.setColumnOrder(2);
    colConfig2.setColumnName("Concept BAR 1");
    colConfig2.setDisplayFormat(DisplayFormat.VALUE);
    colConfig2.setHowMany(3);
    colConfig2.setIncludeTimeRange(true);
    colConfig2.setIncludeUnits(true);

    OutputColumnConfigurationEntity colConfig3 = new OutputColumnConfigurationEntity();
    colConfig3.setOutputConfig(config);
    colConfig3.setColumnOrder(3);
    colConfig3.setColumnName("ConceptAgg");
    colConfig3.setDisplayFormat(DisplayFormat.AGGREGATION);
    colConfig3.setAggregation(AggregationType.MAX);
    colConfig3.setIncludeUnits(true);

    OutputColumnConfigurationEntity colConfig4 = new OutputColumnConfigurationEntity();
    colConfig4.setOutputConfig(config);
    colConfig4.setColumnOrder(4);
    colConfig4.setColumnName("Concept BAZ");
    colConfig4.setDisplayFormat(DisplayFormat.VALUE);
    colConfig4.setHowMany(1);
    colConfig4.setIncludeUnits(false);
    colConfig4.setIncludeTimeRange(false);

    OutputColumnConfigurationEntity colConfig5 = new OutputColumnConfigurationEntity();
    colConfig5.setOutputConfig(config);
    colConfig5.setColumnOrder(5);
    colConfig5.setColumnName("ConceptAgg2");
    colConfig5.setDisplayFormat(DisplayFormat.AGGREGATION);
    colConfig5.setAggregation(AggregationType.AVG);
    colConfig5.setIncludeUnits(false);

    OutputColumnConfigurationEntity colConfig6 = new OutputColumnConfigurationEntity();
    colConfig6.setOutputConfig(config);
    colConfig6.setColumnOrder(6);
    colConfig6.setColumnName("Concept QUUX");
    colConfig6.setDisplayFormat(DisplayFormat.VALUE);
    colConfig6.setHowMany(1);
    colConfig6.setIncludeUnits(false);
    colConfig6.setIncludeTimeRange(true);

    config.getColumnConfigs().add(colConfig1);
    config.getColumnConfigs().add(colConfig3);
    config.getColumnConfigs().add(colConfig4);
    config.getColumnConfigs().add(colConfig5);
    config.getColumnConfigs().add(colConfig6);
    config.getColumnConfigs().add(colConfig2);

    HeaderRowOutputFormatter formatter = new HeaderRowOutputFormatter(config);
    Assert.assertEquals(
            "Patient_id,Concept_FOO,Concept_BAR_1_value,Concept_BAR_1_units,Concept_BAR_1_start,Concept_BAR_1_end,Concept_BAR_1_value,Concept_BAR_1_units,Concept_BAR_1_start,Concept_BAR_1_end,Concept_BAR_1_value,Concept_BAR_1_units,Concept_BAR_1_start,Concept_BAR_1_end,"
                    + "ConceptAgg_max,ConceptAgg_units,Concept_BAZ_value,ConceptAgg2_avg,Concept_QUUX_value,Concept_QUUX_start,Concept_QUUX_end"
                    + IOUtils.LINE_SEPARATOR,
            formatString(formatter));
}

From source file:edu.emory.bmi.aiw.i2b2export.output.HeaderRowOutputFormatter.java

/**
 * Formats the header row according to the instance's output configuration.
 * The row is returned as an array of strings that will be joined later
 * using the correct delimiter./*from ww  w.j av a  2s. com*/
 *
 * @param writer the stream to which the results will go.
 * @throws java.io.IOException if an error occurred writing the results.
 */
@Override
public void format(BufferedWriter writer) throws IOException {
    int colNum = 0;
    switch (outputConfiguration.getRowDimension()) {
    case PROVIDER:
        write("Provider_name", writer, colNum++);
        break;
    case VISIT:
        write("Patient_id", writer, colNum++);
        write("Visit_id", writer, colNum++);
        write("Visit_start", writer, colNum++);
        write("Visit_end", writer, colNum++);
        break;
    case PATIENT:
        write("Patient_id", writer, colNum++);
        break;
    default:
        throw new RuntimeException("row dimension not provided: user:" + " " + outputConfiguration.getUsername()
                + ", " + "name: " + outputConfiguration.getName());
    }
    Collections.sort(outputConfiguration.getColumnConfigs());
    for (int i = 0; i < outputConfiguration.getColumnConfigs().size(); i++) {
        OutputColumnConfigurationEntity colConfig = outputConfiguration.getColumnConfigs().get(i);
        String baseColName = colConfig.getColumnName();
        if (outputConfiguration.getWhitespaceReplacement() != null
                && !outputConfiguration.getWhitespaceReplacement().isEmpty()) {
            baseColName = colConfig.getColumnName().replaceAll("\\s",
                    outputConfiguration.getWhitespaceReplacement());
        }
        switch (colConfig.getDisplayFormat()) {
        case EXISTENCE:
            write(baseColName, writer, colNum++);
            break;
        case VALUE:
            for (int j = 0; j < colConfig.getHowMany(); j++) {
                write(baseColName + "_value", writer, colNum++);
                if (colConfig.getIncludeUnits()) {
                    write(baseColName + "_units", writer, colNum++);
                }
                if (colConfig.getIncludeTimeRange()) {
                    write(baseColName + "_start", writer, colNum++);
                    write(baseColName + "_end", writer, colNum++);
                }
            }
            break;
        case AGGREGATION:
            switch (colConfig.getAggregation()) {
            case MIN:
                write(baseColName + "_min", writer, colNum++);
                break;
            case MAX:
                write(baseColName + "_max", writer, colNum++);
                break;
            case AVG:
                write(baseColName + "_avg", writer, colNum++);
                break;
            default:
                continue;
            }
            if (colConfig.getIncludeUnits()) {
                write(baseColName + "_units", writer, colNum++);
            }
            break;
        default:
            break;
        }
    }
    writer.write(IOUtils.LINE_SEPARATOR);
}