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:net.sf.logsaw.dialect.log4j.pattern.Log4JConversionPatternTranslator.java

@Override
public String getRegexPatternForRule(ConversionRule rule) throws CoreException {
    if (rule.getPlaceholderName().equals("d")) { //$NON-NLS-1$
        // Pattern is dynamic
        return "(" + RegexUtils.getRegexForSimpleDateFormat(rule.getModifier()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("p")) { //$NON-NLS-1$
        String lnHint = RegexUtils.getLengthHint(rule);
        if (lnHint.length() > 0) {
            return "([ A-Z]" + lnHint + ")"; //$NON-NLS-1$ //$NON-NLS-2$
        }/*w  ww  .j av a2s.  c  o  m*/
        // Default: Length is limited by the levels available
        return "([A-Z]{4,5})"; //$NON-NLS-1$
    } else if (rule.getPlaceholderName().equals("c")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("t")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("m")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("n")) { //$NON-NLS-1$
        return "(" + IOUtils.LINE_SEPARATOR + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("F")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("C")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("M")) { //$NON-NLS-1$
        return "([a-zA-Z0-9]*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("L")) { //$NON-NLS-1$
        return "([0-9]*" + RegexUtils.getLengthHint(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    } else if (rule.getPlaceholderName().equals("x")) { //$NON-NLS-1$
        return "(.*" + RegexUtils.getLengthHint(rule) + RegexUtils.getLazySuffix(rule) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
    }
    throw new CoreException(new Status(IStatus.ERROR, Log4JDialectPlugin.PLUGIN_ID,
            NLS.bind(Messages.Log4JConversionRuleTranslator_error_unsupportedConversionCharacter,
                    rule.getPlaceholderName())));
}

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

public String executeINowLicenseRequestView() throws ExceptionWrapper {
    String result = ERROR;/*from  w  w w .  java  2  s . c  om*/
    try {

        String hostAddress = this.imagenowlicenses.getHostname();
        System.out.println("Hostname is: " + hostAddress);

        InetAddress address = InetAddress.getByName(hostAddress);
        boolean reachable = address.isReachable(5000);
        System.out.println("Is Host Reachable: " + reachable);

        if (!reachable) {
            System.out.println("Not Reachable");
            errorMessage = errorMessage + "* Hostname not Reachable." + IOUtils.LINE_SEPARATOR;
            return result;
        } else {
            result = SUCCESS;
            System.out.println("RESULT is: " + result);
            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);
        errorMessage = errorMessage + "* Invalid Hostname." + IOUtils.LINE_SEPARATOR;
        result = ERROR;
    }

    return result;
}

From source file:com.mgmtp.jfunk.web.JFunkWebDriverEventListener.java

/**
 * Saves the currently displayed browser window. The page title is used for the filename -
 * preceded by some identifying information (thread, counter). Pages of the same type are
 * collected inside the same subdirectory. The subdirectory uses
 * {@link SaveOutput#getIdentifier()} for its name. If an alert is present, saving is not
 * supported and thus skipped./*w w  w  .jav  a 2s . c o  m*/
 *
 * @param action
 *            the event which triggered to save the page. Will be included in the filename.
 * @param triggeredBy
 *            the object which triggered the event (e.g. a button or a link)
 */
protected void savePage(final WebDriver driver, final String action, final String triggeredBy) {
    try {
        // this updates the driver's window handles, so a subsequent call to
        // getWindowHandle() fails if the window no longer exists
        driver.getWindowHandles();
        driver.getWindowHandle();
    } catch (NoSuchWindowException ex) {
        // Window is already closed. Saving the page could cause problems, e. g.
        // ChromeDriver ould hang.
        return;
    }
    File moduleArchiveDir = moduleArchiveDirProvider.get();
    if (moduleArchiveDir == null) {
        return;
    }

    if (config.getBoolean(JFunkConstants.ARCHIVE_DO_NOT_SAVE_WHEN_ALERT, false)) {
        try {
            // Saving the page does not work if an alert is present
            driver.switchTo().alert();
            log.trace("Cannot save page. Alert is present.");
            return;
        } catch (NoAlertPresentException ex) {
            // ignore
        } catch (UnsupportedOperationException ex) {
            // ignore
            // HtmlUnit does not support alerts
        } catch (Exception ex) {
            // ignore
        }
    }

    for (SaveOutput saveOutput : SaveOutput.values()) {
        boolean saveSwitch = saveOutputMap.get(saveOutput);
        if (!saveSwitch) {
            // Saving is disabled by property
            continue;
        }

        File f = null;
        try {
            f = dumpFileCreatorProvider.get().createDumpFile(
                    new File(moduleArchiveDir, saveOutput.getIdentifier()), saveOutput.getExtension(),
                    driver.getCurrentUrl(), action);

            if (f == null) {
                return;
            }

            switch (saveOutput) {
            case HTML:
                StringBuilder html = new StringBuilder();
                html.append("<!-- Requested URL: ");
                html.append(driver.getCurrentUrl());
                html.append(" -->");
                html.append(IOUtils.LINE_SEPARATOR);
                html.append(driver.getPageSource());
                writeStringToFile(f, html.toString(), "UTF-8");
                copyFile(f, new File(moduleArchiveDir, JFunkConstants.LASTPAGE_HTML));
                log.trace("Saving page: filename={}, action={}, trigger={}, response={}", f.getName(), action,
                        triggeredBy, driver.getCurrentUrl());
                break;
            case PNG:
                if (driver instanceof TakesScreenshot) {
                    File tmpFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
                    if (tmpFile != null) {
                        copyFile(tmpFile, f);
                        log.trace("Saving page: filename={}, action={}, trigger={}, response={}", f.getName(),
                                action, triggeredBy, driver.getCurrentUrl());
                        deleteQuietly(tmpFile);
                    }
                }
                break;
            case HTML_VALIDATION:
                /*
                 * JFunkWebDriver.getPageSource() doesn't return the complete page source
                 * e.g. DOCTYPE is missing. Therefore we are using a more complicated way to
                 * retrieve the "real" page source. However, this only works when using
                 * HtmlUnitDriver.
                 */
                if (WebDriverUtils.isHtmlUnitDriver(driver)) {
                    String content = ((HtmlPage) WebDriverUtils.getHtmlUnitDriverWebClient(driver)
                            .getCurrentWindow().getEnclosedPage()).getWebResponse().getContentAsString();
                    writeStringToFile(f, content, "UTF-8");
                    HtmlValidatorUtil.validateHtml(f.getParentFile(), config, f);
                }
                break;
            default:
                throw new IllegalStateException("unknown enum constant");
            }
        } catch (Exception ex) {
            log.error("Could not save file: {}. {}", f, ex.getMessage());
            return;
        }
    }
}

From source file:com.alibaba.rocketmq.common.MixAll.java

public static String properties2String(final Properties properties) {
    Set<Object> sets = properties.keySet();
    StringBuilder sb = new StringBuilder();
    for (Object key : sets) {
        Object value = properties.get(key);
        if (value != null) {
            sb.append(key.toString() + "=" + value.toString() + IOUtils.LINE_SEPARATOR);
        }/*from  www .j av  a  2 s .c o  m*/
    }

    return sb.toString();
}

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

private void output(final String cacheFilename, final Map<String, ColumnType> columnToType)
        throws FileNotFoundException {
    PrintWriter out = null;//from   ww  w  .j av a 2s  .c  om
    try {
        out = new PrintWriter(cacheFilename);
        int columnNumber = 0;
        for (final Map.Entry<String, ColumnType> entry : columnToType.entrySet()) {
            if (columnNumber == 0) {
                out.println("id\tcolumn-name\tcolumn-type");
            }
            out.print("col_" + columnNumber);
            out.print('\t');
            out.print(entry.getKey());
            out.print('\t');
            if (entry.getValue() == ColumnType.Unknown) {
                // If there are no values in the column, we'll just assume the column to be a string
                out.print(ColumnType.String.toString());
            } else {
                out.print(entry.getValue().toString());
            }

            out.print(IOUtils.LINE_SEPARATOR);
            columnNumber++;
        }
    } finally {
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    }
}

From source file:net.sf.logsaw.dialect.pattern.APatternDialect.java

@Override
public void parse(ILogResource log, InputStream input, ILogEntryCollector collector) throws CoreException {
    Assert.isNotNull(log, "log"); //$NON-NLS-1$
    Assert.isNotNull(input, "input"); //$NON-NLS-1$
    Assert.isNotNull(collector, "collector"); //$NON-NLS-1$
    Assert.isTrue(isConfigured(), "Dialect should be configured by now"); //$NON-NLS-1$
    try {//from   w  ww .j a  v a2 s .co m
        LogEntry currentEntry = null;
        IHasEncoding enc = (IHasEncoding) log.getAdapter(IHasEncoding.class);
        IHasLocale loc = (IHasLocale) log.getAdapter(IHasLocale.class);
        if (loc != null) {
            // Apply the locale
            getPatternTranslator().applyLocale(loc.getLocale(), rules);
        }
        IHasTimeZone tz = (IHasTimeZone) log.getAdapter(IHasTimeZone.class);
        if (tz != null) {
            // Apply the timezone
            getPatternTranslator().applyTimeZone(tz.getTimeZone(), rules);
        }
        LineIterator iter = IOUtils.lineIterator(input, enc.getEncoding());
        int minLinesPerEntry = getPatternTranslator().getMinLinesPerEntry();
        int lineNo = 0;
        int moreLinesToCome = 0;
        try {
            String line = null;
            while (iter.hasNext()) {
                lineNo++;

                if (minLinesPerEntry == 1) {
                    // Simple case
                    line = iter.nextLine();
                } else {
                    String s = iter.nextLine();
                    if (moreLinesToCome == 0) {
                        Matcher m = getInternalPatternFirstLine().matcher(s);
                        if (m.find()) {
                            // First line
                            line = s;
                            moreLinesToCome = minLinesPerEntry - 1;
                            continue;
                        } else {
                            // Some crazy stuff
                            line = s;
                        }
                    } else if (iter.hasNext() && (moreLinesToCome > 1)) {
                        // Some middle line
                        line += IOUtils.LINE_SEPARATOR + s;
                        moreLinesToCome--;
                        continue;
                    } else {
                        // Last line
                        line += IOUtils.LINE_SEPARATOR + s;
                        if (!iter.hasNext()) {
                            line += IOUtils.LINE_SEPARATOR;
                        }
                        moreLinesToCome = 0;
                    }
                }

                // Error handling
                List<IStatus> statuses = null;
                boolean fatal = false; // determines whether to interrupt parsing

                Matcher m = getInternalPatternFull().matcher(line);
                if (m.find()) {
                    // The next line matches, so flush the previous entry and continue
                    if (currentEntry != null) {
                        collector.collect(currentEntry);
                        currentEntry = null;
                    }
                    currentEntry = new LogEntry();
                    for (int i = 0; i < m.groupCount(); i++) {
                        try {
                            getPatternTranslator().extractField(currentEntry, getRules().get(i),
                                    m.group(i + 1));
                        } catch (CoreException e) {
                            // Mark for interruption
                            fatal = fatal || e.getStatus().matches(IStatus.ERROR);

                            // Messages will be displayed later
                            if (statuses == null) {
                                statuses = new ArrayList<IStatus>();
                            }
                            if (e.getStatus().isMultiStatus()) {
                                Collections.addAll(statuses, e.getStatus().getChildren());
                            } else {
                                statuses.add(e.getStatus());
                            }
                        }
                    }

                    // We encountered errors or warnings
                    if (statuses != null && !statuses.isEmpty()) {
                        currentEntry = null; // Stop propagation
                        IStatus status = new MultiStatus(PatternDialectPlugin.PLUGIN_ID, 0,
                                statuses.toArray(new IStatus[statuses.size()]),
                                NLS.bind(Messages.APatternDialect_error_failedToParseLine, lineNo), null);
                        if (fatal) {
                            // Interrupt parsing in case of error
                            throw new CoreException(status);
                        } else {
                            collector.addMessage(status);
                        }
                    }
                } else if (currentEntry != null) {
                    // Append to message
                    String msg = currentEntry.get(getFieldProvider().getMessageField());
                    currentEntry.put(getFieldProvider().getMessageField(), msg + IOUtils.LINE_SEPARATOR + line);
                }

                if (collector.isCanceled()) {
                    // Cancel parsing
                    break;
                }
            }

            if (currentEntry != null) {
                // Collect left over entry
                collector.collect(currentEntry);
            }
        } finally {
            LineIterator.closeQuietly(iter);
        }
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, PatternDialectPlugin.PLUGIN_ID,
                NLS.bind(Messages.APatternDialect_error_failedToParseFile,
                        new Object[] { log.getName(), e.getLocalizedMessage() }),
                e));
    }
}

From source file:hudson.FunctionsTest.java

private static void assertPrintThrowable(Throwable t, String traditional, String custom) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    assertEquals(sw.toString().replace(IOUtils.LINE_SEPARATOR, "\n"), traditional);
    String actual = Functions.printThrowable(t);
    System.out.println(actual);//from   w  w w .  jav  a 2s.  co m
    assertEquals(actual.replace(IOUtils.LINE_SEPARATOR, "\n"), custom);
}

From source file:org.alfresco.repo.virtual.bundle.VirtualNodeServiceExtension.java

private void createDownloadAssociation(NodeRef sourceNodeRef, NodeRef targetRef) {

    NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve(true);

    String tempFileName = sourceNodeRef.getId();
    NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS,
            tempFileName);//from  w  w  w  . j  a  v  a2s . com
    if (tempFileNodeRef == null) {
        FileInfo newTempFileInfo = environment.create(tempFolderNodeRef, tempFileName,
                ContentModel.TYPE_CONTENT);
        tempFileNodeRef = newTempFileInfo.getNodeRef();
        ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
        writer.setMimetype("text/plain");
        writer.putContent(targetRef.toString());

    } else {
        ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true);
        try {
            List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef),
                    StandardCharsets.UTF_8);

            String targetRefString = targetRef.toString();
            if (!readLines.contains(targetRefString)) {
                readLines.add(targetRefString);
            }
            String text = "";
            for (String line : readLines) {
                if (text.isEmpty()) {
                    text = line;
                } else {
                    text = text + IOUtils.LINE_SEPARATOR + line;
                }

            }
            writer.putContent(text);
        } catch (IOException e) {
            throw new ActualEnvironmentException(e);
        }

    }

}

From source file:org.apache.flex.compiler.filespecs.CombinedFile.java

/**
 * Concatenate source files together. The main source file is always at the
 * end./*w ww.  j a v a2 s.c om*/
 * 
 * @throws FileNotFoundException error
 */
private void combineFile() throws FileNotFoundException {
    assert combinedSource == null : "Do not call combineFile() twice.";

    combinedSource = new StringBuilder();

    for (final String filename : fileList) {
        Reader reader = null;
        try {
            final BufferedInputStream strm = getStreamAndSkipBOM(filename);
            reader = new InputStreamReader(strm);
            combinedSource.append(IOUtils.toString(reader));
            combinedSource.append(IOUtils.LINE_SEPARATOR);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(reader);
        }
    }
}

From source file:org.apache.jackrabbit.core.query.lucene.join.QueryEngine.java

private static void logQueryAnalysis(ConstraintSplitInfo csi, int printIndentation) throws RepositoryException {
    if (!log.isDebugEnabled()) {
        return;/*ww  w .  ja  va2s  .  c o m*/
    }
    StringBuilder sb = new StringBuilder();
    sb.append(genString(printIndentation));
    sb.append("SQL2 JOIN analysis:");
    sb.append(IOUtils.LINE_SEPARATOR);
    sb.append(constraintSplitInfoToString(csi, 2));
    log.debug(sb.toString());
}