Example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Click Source Link

Document

The line.separator System Property.

Usage

From source file:org.apache.cocoon.generation.TextGenerator.java

/**
 * Generate XML data.//  w  ww . j ava 2  s. c  o m
 *
 * @throws IOException
 * @throws ProcessingException
 * @throws SAXException
 */
public void generate() throws IOException, SAXException, ProcessingException {
    InputStreamReader in = null;

    try {
        final InputStream sis = this.inputSource.getInputStream();
        if (sis == null) {
            throw new ProcessingException("Source '" + this.inputSource.getURI() + "' not found");
        }

        if (encoding != null) {
            in = new InputStreamReader(sis, encoding);
        } else {
            in = new InputStreamReader(sis);
        }
    } catch (SourceException se) {
        throw new ProcessingException("Error during resolving of '" + this.source + "'.", se);
    }

    LocatorImpl locator = new LocatorImpl();

    locator.setSystemId(this.inputSource.getURI());
    locator.setLineNumber(1);
    locator.setColumnNumber(1);

    contentHandler.setDocumentLocator(locator);
    contentHandler.startDocument();
    contentHandler.startPrefixMapping("", URI);

    AttributesImpl atts = new AttributesImpl();
    if (localizable) {
        atts.addAttribute("", "source", "source", "CDATA", locator.getSystemId());
        atts.addAttribute("", "line", "line", "CDATA", String.valueOf(locator.getLineNumber()));
        atts.addAttribute("", "column", "column", "CDATA", String.valueOf(locator.getColumnNumber()));
    }

    contentHandler.startElement(URI, "text", "text", atts);

    LineNumberReader reader = new LineNumberReader(in);
    String line;
    String newline = null;

    while (true) {
        if (newline == null) {
            line = convertNonXmlChars(reader.readLine());
        } else {
            line = newline;
        }
        if (line == null) {
            break;
        }
        newline = convertNonXmlChars(reader.readLine());
        if (newline != null) {
            line += SystemUtils.LINE_SEPARATOR;
        }
        locator.setLineNumber(reader.getLineNumber());
        locator.setColumnNumber(1);
        contentHandler.characters(line.toCharArray(), 0, line.length());
        if (newline == null) {
            break;
        }
    }
    reader.close();
    contentHandler.endElement(URI, "text", "text");
    contentHandler.endPrefixMapping("");
    contentHandler.endDocument();
}

From source file:org.apache.cocoon.generation.TextGenerator2.java

/**
 * Generate XML data./*  w w w .  ja  va  2  s.  c  o m*/
 *
 * @throws IOException
 * @throws ProcessingException
 * @throws SAXException
 */
public void generate() throws IOException, SAXException, ProcessingException {
    InputStreamReader in = null;
    try {
        final InputStream sis = this.inputSource.getInputStream();
        if (sis == null) {
            throw new ProcessingException("Source '" + this.inputSource.getURI() + "' not found");
        }
        if (encoding != null) {
            in = new InputStreamReader(sis, encoding);
        } else {
            in = new InputStreamReader(sis);
        }
    } catch (SourceException se) {
        throw new ProcessingException("Error during resolving of '" + this.source + "'.", se);
    }
    LocatorImpl locator = new LocatorImpl();
    locator.setSystemId(this.inputSource.getURI());
    locator.setLineNumber(1);
    locator.setColumnNumber(1);
    /* Do not pass the source URI to the contentHandler, assuming that that is the LexicalTransformer. It does not have to be.
      contentHandler.setDocumentLocator(locator);
    */
    contentHandler.startDocument();
    AttributesImpl atts = new AttributesImpl();
    if (localizable) {
        atts.addAttribute("", "source", "source", "CDATA", locator.getSystemId());
        atts.addAttribute("", "line", "line", "CDATA", String.valueOf(locator.getLineNumber()));
        atts.addAttribute("", "column", "column", "CDATA", String.valueOf(locator.getColumnNumber()));
    }
    String nsPrefix = this.element.contains(":") ? this.element.replaceFirst(":.+$", "") : "";
    String localName = this.element.replaceFirst("^.+:", "");
    if (this.namespace.length() > 1)
        contentHandler.startPrefixMapping(nsPrefix, this.namespace);
    contentHandler.startElement(this.namespace, localName, this.element, atts);
    LineNumberReader reader = new LineNumberReader(in);
    String line;
    String newline = null;
    while (true) {
        if (newline == null) {
            line = convertNonXmlChars(reader.readLine());
        } else {
            line = newline;
        }
        if (line == null) {
            break;
        }
        newline = convertNonXmlChars(reader.readLine());
        if (newline != null) {
            line += SystemUtils.LINE_SEPARATOR;
        }
        locator.setLineNumber(reader.getLineNumber());
        locator.setColumnNumber(1);
        contentHandler.characters(line.toCharArray(), 0, line.length());
        if (newline == null) {
            break;
        }
    }
    reader.close();
    contentHandler.endElement(this.namespace, localName, this.element);
    if (this.namespace.length() > 1)
        contentHandler.endPrefixMapping(nsPrefix);
    contentHandler.endDocument();
}

From source file:org.apache.cocoon.util.log.ExtensiblePatternFormatter.java

/**
 * Extract and build a text run  from input string.
 * It does special handling of '\n' and '\t' replaceing
 * them with newline and tab./* w  w w .  java2  s. c om*/
 *
 * @param stack the stack on which to place runs
 * @param pattern the input string
 * @param index the start of the text run
 * @return the number of characters in run
 */
protected int addTextRun(final Stack stack, final char pattern[], int index) {
    final PatternRun run = new PatternRun();
    final int start = index;
    boolean escapeMode = false;

    if ('%' == pattern[index]) {
        index++;
    }
    final StringBuffer sb = new StringBuffer();
    while (index < pattern.length && pattern[index] != '%') {
        if (escapeMode) {
            if ('n' == pattern[index]) {
                sb.append(SystemUtils.LINE_SEPARATOR);
            } else if ('t' == pattern[index]) {
                sb.append('\t');
            } else {
                sb.append(pattern[index]);
            }
            escapeMode = false;
        } else if ('\\' == pattern[index]) {
            escapeMode = true;
        } else {
            sb.append(pattern[index]);
        }
        index++;
    }
    run.m_data = sb.toString();
    run.m_type = TYPE_TEXT;
    stack.push(run);
    return index - start;
}

From source file:org.apache.cocoon.util.log.XMLCocoonLogFormatter.java

/**
 * Format the event according to the pattern.
 *
 * @param event the event/* w  ww .jav a2s  .  c o  m*/
 * @return the formatted output
 */
public String format(final LogEvent event) {
    final StringBuffer sb = new StringBuffer();
    sb.append("<log-entry>").append(SystemUtils.LINE_SEPARATOR);
    final String value = this.getRequestId(event.getContextMap());
    if (value != null) {
        sb.append("<request-id>").append(value).append("</request-id>").append(SystemUtils.LINE_SEPARATOR);
    }
    for (int i = 0; i < this.types.length; i++) {
        switch (this.types[i]) {
        case TYPE_REQUEST_URI:
            sb.append("<uri>");
            sb.append(this.getURI(event.getContextMap()));
            sb.append("</uri>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_CLASS:
            sb.append("<class>");
            sb.append(this.getClass(TYPE_CLASS));
            sb.append("</class>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_CLASS_SHORT:
            sb.append("<class>");
            sb.append(this.getClass(TYPE_CLASS_SHORT));
            sb.append("</class>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_THREAD:
            sb.append("<thread>");
            sb.append(this.getThread(event.getContextMap()));
            sb.append("</thread>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_RELATIVE_TIME:
            sb.append("<relative-time>");
            sb.append(event.getRelativeTime());
            sb.append("</relative-time>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_TIME:
            sb.append("<time>");
            sb.append(dateFormatter.format(new Date(event.getTime())));
            sb.append("</time>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_THROWABLE:
            Throwable throwable = event.getThrowable();
            if (throwable != null) {
                sb.append("<throwable><![CDATA[").append(SystemUtils.LINE_SEPARATOR);
                while (throwable != null) {
                    final StringWriter sw = new StringWriter();
                    throwable.printStackTrace(new java.io.PrintWriter(sw));
                    sb.append(sw.toString());
                    if (throwable instanceof CascadingThrowable) {
                        throwable = ((CascadingThrowable) throwable).getCause();
                    } else {
                        throwable = null;
                    }
                }
                sb.append(SystemUtils.LINE_SEPARATOR).append("]]> </throwable>")
                        .append(SystemUtils.LINE_SEPARATOR);
            }
            break;
        case TYPE_MESSAGE:
            sb.append("<message><![CDATA[").append(SystemUtils.LINE_SEPARATOR);
            sb.append(event.getMessage());
            sb.append(SystemUtils.LINE_SEPARATOR).append("]]> </message>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_CATEGORY:
            sb.append("<category>");
            sb.append(event.getCategory());
            sb.append("</category>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_PRIORITY:
            sb.append("<priority>");
            sb.append(event.getPriority().getName());
            sb.append("</priority>").append(SystemUtils.LINE_SEPARATOR);
            break;
        case TYPE_HOST:
            sb.append("<host>");
            sb.append(getHost(event.getContextMap()));
            sb.append("</host>");
            break;
        }
    }
    sb.append("</log-entry>");
    sb.append(SystemUtils.LINE_SEPARATOR);
    return sb.toString();
}

From source file:org.apache.cxf.jaxb.JAXBToStringStyle.java

JAXBToStringStyleImpl(boolean multiLine) {
    super();//  w  ww.  j  av  a2s. com
    if (multiLine) {
        this.setContentStart("[");
        this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + "  ");
        this.setFieldSeparatorAtStart(true);
        this.setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
    } else {
        // simple
        this.setUseClassName(false);
        this.setUseIdentityHashCode(false);
        this.setUseFieldNames(false);
        this.setContentStart("");
        this.setContentEnd("");
    }
}

From source file:org.apache.directory.server.kerberos.kdc.AbstractKerberosITest.java

/**
 * Creates the krb5.conf file for the test.
 * //from  w  w  w  .j  ava 2  s  . c  o  m
 * It looks similar to this:
 * 
 * <pre>
 * [libdefaults]
 *     default_realm = EXAMPLE.COM
 *     default_tkt_enctypes = aes256-cts-hmac-sha1-96
 *     default_tgs_enctypes = aes256-cts-hmac-sha1-96
 *     permitted_enctypes = aes256-cts-hmac-sha1-96
 * 
 * [realms]
 *     EXAMPLE.COM = {
 *         kdc = localhost:6088
 *     }
 * 
 * [domain_realm]
 *     .example.com = EXAMPLE.COM
 *     example.com = EXAMPLE.COM
 * </pre>
 *
 * @param encryptionType
 * @param checksumType
 * @return the path to the krb5.conf file
 * @throws IOException
 */
private String createKrb5Conf(ChecksumType checksumType, EncryptionType encryptionType, boolean isTcp)
        throws IOException {
    File file = folder.newFile("krb5.conf");

    String data = "";

    data += "[libdefaults]" + SystemUtils.LINE_SEPARATOR;
    data += "default_realm = " + REALM + SystemUtils.LINE_SEPARATOR;
    data += "default_tkt_enctypes = " + encryptionType.getName() + SystemUtils.LINE_SEPARATOR;
    data += "default_tgs_enctypes = " + encryptionType.getName() + SystemUtils.LINE_SEPARATOR;
    data += "permitted_enctypes = " + encryptionType.getName() + SystemUtils.LINE_SEPARATOR;
    //        data += "default_checksum = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
    //        data += "ap_req_checksum_type = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;
    data += "default-checksum_type = " + checksumType.getName() + SystemUtils.LINE_SEPARATOR;

    if (isTcp) {
        data += "udp_preference_limit = 1" + SystemUtils.LINE_SEPARATOR;
    }

    data += "[realms]" + SystemUtils.LINE_SEPARATOR;
    data += REALM + " = {" + SystemUtils.LINE_SEPARATOR;
    data += "kdc = " + HOSTNAME + ":" + kdcServer.getTransports()[0].getPort() + SystemUtils.LINE_SEPARATOR;
    data += "}" + SystemUtils.LINE_SEPARATOR;

    data += "[domain_realm]" + SystemUtils.LINE_SEPARATOR;
    data += "." + Strings.toLowerCaseAscii(REALM) + " = " + REALM + SystemUtils.LINE_SEPARATOR;
    data += Strings.toLowerCaseAscii(REALM) + " = " + REALM + SystemUtils.LINE_SEPARATOR;

    FileUtils.writeStringToFile(file, data);

    return file.getAbsolutePath();
}

From source file:org.apache.geode.internal.process.ProcessStreamReader.java

private static String waitAndCaptureProcessStream(final Process process, final InputStream processInputStream,
        final long waitTimeMilliseconds) {
    StringBuffer buffer = new StringBuffer();

    InputListener inputListener = line -> {
        buffer.append(line);/* www  .j ava2 s.c  om*/
        buffer.append(SystemUtils.LINE_SEPARATOR);
    };

    ProcessStreamReader reader = new ProcessStreamReader.Builder(process).inputStream(processInputStream)
            .inputListener(inputListener).build();

    try {
        reader.start();

        long endTime = System.currentTimeMillis() + waitTimeMilliseconds;

        while (System.currentTimeMillis() < endTime) {
            try {
                reader.join(waitTimeMilliseconds);
            } catch (InterruptedException ignore) {
            }
        }
    } finally {
        reader.stop();
    }

    return buffer.toString();
}

From source file:org.apache.geode.management.internal.cli.commands.QueryInterceptor.java

@Override
public Result postExecution(GfshParseResult parseResult, Result result, Path tempFile) {
    File outputFile = getOutputFile(parseResult);

    if (outputFile == null) {
        return result;
    }// ww w.jav  a  2 s.  com

    CommandResult commandResult = (CommandResult) result;
    CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
    CompositeResultData.SectionResultData sectionResultData = resultData.retrieveSectionByIndex(0);

    String limit = sectionResultData.retrieveString("Limit");
    String resultString = sectionResultData.retrieveString("Result");
    String rows = sectionResultData.retrieveString("Rows");

    if ("false".equalsIgnoreCase(resultString)) {
        return result;
    }

    TabularResultData tabularResultData = sectionResultData.retrieveTableByIndex(0);
    CommandResult resultTable = new CommandResult(tabularResultData);
    try {
        writeResultTableToFile(outputFile, resultTable);
        // return a result w/ message explaining limit
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    InfoResultData infoResultData = ResultBuilder.createInfoResultData();
    infoResultData.addLine("Result : " + resultString);
    if (StringUtils.isNotBlank(limit)) {
        infoResultData.addLine("Limit  : " + limit);
    }
    infoResultData.addLine("Rows   : " + rows);
    infoResultData.addLine(SystemUtils.LINE_SEPARATOR);
    infoResultData.addLine("Query results output to " + outputFile.getAbsolutePath());

    return new CommandResult(infoResultData);
}

From source file:org.apache.geode.management.internal.cli.commands.QueryInterceptor.java

private void writeResultTableToFile(File file, CommandResult commandResult) throws IOException {
    try (FileWriter fileWriter = new FileWriter(file)) {
        while (commandResult.hasNextLine()) {
            fileWriter.write(commandResult.nextLine());

            if (commandResult.hasNextLine()) {
                fileWriter.write(SystemUtils.LINE_SEPARATOR);
            }/*from   w w  w.  j a  v  a 2 s.  c om*/
        }
    }
}

From source file:org.apache.geode.test.compiler.UncompiledSourceCode.java

public static UncompiledSourceCode fromClassName(String fullyQualifiedClassName) {
    ClassNameWithPackage classNameWithPackage = ClassNameWithPackage.of(fullyQualifiedClassName);
    boolean isPackageSpecified = StringUtils.isNotBlank(classNameWithPackage.packageName);

    StringBuilder sourceCode = new StringBuilder();
    if (isPackageSpecified) {
        sourceCode.append(String.format("package %s;", classNameWithPackage.packageName));
        sourceCode.append(SystemUtils.LINE_SEPARATOR);
    }//from w  ww .  j a  v  a  2 s .  co m

    sourceCode.append(String.format("public class %s {}", classNameWithPackage.simpleClassName));

    return new UncompiledSourceCode(classNameWithPackage.simpleClassName, sourceCode.toString());
}