Example usage for java.lang System lineSeparator

List of usage examples for java.lang System lineSeparator

Introduction

In this page you can find the example usage for java.lang System lineSeparator.

Prototype

String lineSeparator

To view the source code for java.lang System lineSeparator.

Click Source Link

Usage

From source file:org.apache.carbondata.processing.util.CarbonLoaderUtilTest.java

private <K, T> String convertMapListAsString(Map<K, List<T>> mapList) {
    StringBuffer sb = new StringBuffer();
    for (Map.Entry<K, List<T>> entry : mapList.entrySet()) {
        String key = entry.getKey().toString();
        String value = StringUtils.join(entry.getValue(), ", ");
        sb.append(key).append(" -- ").append(value).append(System.lineSeparator());
    }//w w w . ja v a  2s .  co  m
    return sb.toString();
}

From source file:kmi.taa.core.Crawler.java

public void resultToFile(List<String> result, String fname) {
    File file = new File(fname);
    file.getParentFile().mkdirs();/*  www  .  ja v  a  2s  .c o m*/
    try {
        BufferedWriter bw = new BufferedWriter(new FileWriter(fname, false));
        synchronized (result) {
            for (String str : result) {
                bw.write(str);
                bw.write(System.lineSeparator());
            }
        }
        bw.close();
    } catch (IOException e) {
        log.error("write fetched subject links to file error", e);
    }

}

From source file:org.apache.hadoop.hdfs.server.diskbalancer.command.ReportCommand.java

private void handleNodeReport(final CommandLine cmd, StrBuilder result, final String nodeFormat,
        final String volumeFormat) throws Exception {
    String outputLine = "";
    /*//from ww  w.ja v a  2  s .  co m
     * get value that identifies a DataNode from command line, it could be UUID,
     * IP address or host name.
     */
    final String nodeVal = cmd.getOptionValue(DiskBalancer.NODE);

    if (StringUtils.isBlank(nodeVal)) {
        outputLine = "The value for '-node' is neither specified or empty.";
        recordOutput(result, outputLine);
    } else {
        /*
         * Reporting volume information for a specific DataNode
         */
        outputLine = String.format("Reporting volume information for DataNode '%s'.", nodeVal);
        recordOutput(result, outputLine);

        final String trueStr = "True";
        final String falseStr = "False";
        DiskBalancerDataNode dbdn = getNode(nodeVal);
        // get storage path of datanode
        populatePathNames(dbdn);

        if (dbdn == null) {
            outputLine = String.format("Can't find a DataNode that matches '%s'.", nodeVal);
            recordOutput(result, outputLine);
        } else {
            result.appendln(String.format(nodeFormat, dbdn.getDataNodeName(), dbdn.getDataNodeIP(),
                    dbdn.getDataNodePort(), dbdn.getDataNodeUUID(), dbdn.getVolumeCount(),
                    dbdn.getNodeDataDensity()));

            List<String> volumeList = Lists.newArrayList();
            for (DiskBalancerVolumeSet vset : dbdn.getVolumeSets().values()) {
                for (DiskBalancerVolume vol : vset.getVolumes()) {
                    volumeList.add(String.format(volumeFormat, vol.getStorageType(), vol.getPath(),
                            vol.getUsedRatio(), vol.getUsed(), vol.getCapacity(), vol.getFreeRatio(),
                            vol.getFreeSpace(), vol.getCapacity(), vol.isFailed() ? trueStr : falseStr,
                            vol.isReadOnly() ? trueStr : falseStr, vol.isSkip() ? trueStr : falseStr,
                            vol.isTransient() ? trueStr : falseStr));
                }
            }

            Collections.sort(volumeList);
            result.appendln(StringUtils.join(volumeList.toArray(), System.lineSeparator()));
        }
    }
}

From source file:org.ballerinalang.containers.docker.cmd.DockerCmd.java

@Override
public void printLongDesc(StringBuilder out) {
    out.append("Creates docker images for Ballerina programs." + System.lineSeparator());
    out.append(System.lineSeparator());
}

From source file:org.smigo.log.LogHandler.java

public void logError(HttpServletRequest request, HttpServletResponse response, Exception ex, String subject) {
    final String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
    final Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");

    final String separator = System.lineSeparator();
    StringBuilder text = new StringBuilder();
    text.append(getRequestDump(request, response, separator)).append(separator);
    text.append("Statuscode:").append(statusCode).append(separator);
    text.append("Uri:").append(uri).append(separator);
    text.append("Exception:").append(getStackTrace(ex)).append(separator);

    log.error("Error during request" + subject, ex);
    if (!Log.create(request, response).getUseragent().contains("compatible")) {
        mailHandler.sendAdminNotification("error during request " + subject, text);
    }/*from w  w  w.  j  ava  2 s . c o m*/
}

From source file:nl.knaw.huygens.alexandria.dropwizard.cli.CommandIntegrationTest.java

String normalize(final String string) {
    return string.trim().replace(System.lineSeparator(), "\n");
}

From source file:it.ecubecenter.processors.zookeeper.ZookeeperList.java

@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();// w ww  .j  a v a2s  .co  m
    if (flowFile == null) {
        return;
    }
    final String outputFormat = context.getProperty(OUTPUT_FORMAT).getValue();
    renewKerberosAuthenticationIfNeeded(context);
    String zookeeperURL = context.getProperty(ZOOKEEPER_URL).getValue();
    ThreadsafeZookeeperClient conn = ThreadsafeZookeeperClient.getConnection(zookeeperURL);
    int trials = 3;
    while (trials > 0) {
        try {
            String zNode = context.getProperty(ZNODE_NAME).evaluateAttributeExpressions(flowFile).getValue();
            List<String> list = conn.listZNode(zNode);

            if (list == null) {
                session.getProvenanceReporter().route(flowFile, ZNODE_NOT_FOUND);
                session.transfer(flowFile, ZNODE_NOT_FOUND);
            } else {
                switch (context.getProperty(DESTINATION).getValue()) {
                case DESTINATION_CONTENT:
                    flowFile = session.write(flowFile, new OutputStreamCallback() {
                        @Override
                        public void process(OutputStream outputStream) throws IOException {
                            switch (outputFormat) {
                            case "csv":
                                StringBuilder sb = new StringBuilder();
                                boolean firstLine = true;
                                for (String zNode : list) {
                                    if (!firstLine) {
                                        sb.append(System.lineSeparator());
                                    }
                                    sb.append(zNode);
                                    firstLine = false;
                                }
                                outputStream.write(sb.toString().getBytes());
                                break;
                            case "json":
                                outputStream.write(objMapper.writeValueAsBytes(list));
                                break;
                            default:
                                throw new InvalidClassException("Unrecognized output format.");
                            }

                        }
                    });
                    session.getProvenanceReporter().fetch(flowFile, zookeeperURL + zNode);
                    flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(),
                            MIME_TYPE_MAP.get(outputFormat));
                    break;
                case DESTINATION_ATTRIBUTE:
                    switch (outputFormat) {
                    case "csv":
                        StringBuilder sb = new StringBuilder();
                        boolean firstLine = true;
                        for (String zN : list) {
                            if (!firstLine) {
                                sb.append(",");
                            }
                            sb.append(zN);
                            firstLine = false;
                        }
                        flowFile = session.putAttribute(flowFile, ATTIRUBTE_NAME, sb.toString());
                        break;
                    case "json":
                        flowFile = session.putAttribute(flowFile, ATTIRUBTE_NAME,
                                objMapper.writeValueAsString(list));
                        break;
                    default:
                        throw new InvalidClassException("Unrecognized output format.");
                    }
                    session.getProvenanceReporter().modifyAttributes(flowFile);
                    break;
                default:
                    throw new InvalidClassException("Unrecognized destination.");

                }

                session.transfer(flowFile, SUCCESS);
            }

            break;
        } catch (Exception e) {
            try {
                conn.close();
            } catch (InterruptedException e1) {
                getLogger().warn("Unable to close connection to Zookeeper.", e);
            }
            getLogger().warn("Error while listing from Zookeeper", e);
        }
        trials--;
    }
    if (trials == 0) {
        getLogger().error("Zookeeper operation failed 3 times");
        session.transfer(flowFile, FAILURE);
    }

}

From source file:com.amazon.alexa.avs.http.AVSClient.java

private void createNewHttpClient() throws Exception {

    if ((httpClient != null) && httpClient.isStarted()) {
        try {// w w w  . j a  v a  2s  .c o  m
            httpClient.stop();
        } catch (Exception e) {
            log.error("There was a problem stopping the HTTP client", e);
            throw e;
        }
    }

    // Sets up an HttpClient that sends HTTP/1.1 requests over an HTTP/2 transport
    httpClient = new HttpClient(new PingSendingHttpClientTransportOverHTTP2(http2Client, this),
            sslContextFactory);
    httpClient.addLifeCycleListener(new Listener() {

        @Override
        public void lifeCycleFailure(LifeCycle arg0, Throwable arg1) {
            log.error("HttpClient failed", arg1);
            StackTraceElement st[] = Thread.currentThread().getStackTrace();
            log.info(String.join(System.lineSeparator(), Arrays.toString(st)));
        }

        @Override
        public void lifeCycleStarted(LifeCycle arg0) {
            log.info("HttpClient started");
        }

        @Override
        public void lifeCycleStarting(LifeCycle arg0) {
            log.info("HttpClient starting");
        }

        @Override
        public void lifeCycleStopped(LifeCycle arg0) {
            log.info("HttpClient stopped");
        }

        @Override
        public void lifeCycleStopping(LifeCycle arg0) {
            log.info("HttpClient stopping");
            StackTraceElement st[] = Thread.currentThread().getStackTrace();
            log.info(String.join(System.lineSeparator(), Arrays.toString(st)));
        }

    });
    httpClient.start();

}

From source file:com.vmware.bdd.utils.CommonUtil.java

public static void prettyOutputStrings(List<Object> objs, String fileName, String delimeter) throws Exception {
    StringBuffer buff = new StringBuffer();
    if (isBlank(delimeter)) {
        delimeter = System.lineSeparator();
    }/*from  w w  w .  ja v a  2s.  c  om*/

    for (Object obj : objs) {
        if (obj != null) {
            String str = obj.toString();
            if (!isBlank(str)) {
                buff.append(str).append(delimeter);
            }
        }
    }
    if (buff.length() > 0) {
        buff.delete(buff.length() - delimeter.length(), buff.length());
    }

    OutputStream out = null;
    BufferedWriter bw = null;
    try {
        if (!isBlank(fileName)) {
            out = new FileOutputStream(fileName);
        } else {
            out = System.out;
        }
        bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
        bw.write(buff.toString());
        if (!isBlank(fileName)) {
            // [Bug 1406542] always append a newline at the end of the file
            bw.newLine();
        }
        bw.flush();
    } finally {
        if (bw != null && out != null && !(out instanceof PrintStream)) {
            bw.close();
            out.close();
        }
    }
}

From source file:net.certifi.audittablegen.AuditTableGen.java

/**
 * Examines the DataSource metadata for information pertaining to the
 * driver, catalog, schema and the presence of audit table configuration
 * data.//from   w w w. ja v  a 2s  . c om
 * 
 * @return String containing datasource information.
 * @throws SQLException 
 */
String getDataSourceInfo() throws SQLException {

    Connection conn = dataSource.getConnection();
    DatabaseMetaData dmd = conn.getMetaData();
    StringBuilder s = new StringBuilder();

    s.append("Driver Name: ").append(dmd.getDriverName()).append("Driver Version: ")
            .append(dmd.getDriverVersion()).append(System.lineSeparator()).append("CatalogSeperator: ")
            .append(dmd.getCatalogSeparator()).append(System.lineSeparator()).append("CatalogTerm: ")
            .append(dmd.getCatalogTerm()).append(System.lineSeparator()).append("SchemaTerm: ")
            .append(dmd.getSchemaTerm()).append(System.lineSeparator()).append("Catalogs: ");

    ResultSet rs = dmd.getCatalogs();
    while (rs.next()) {
        s.append(rs.getString("TABLE_CAT")).append(",");
        logger.debug("Catalog: {}", rs.getString("TABLE_CAT"));
    }
    rs.close();
    s.append(System.lineSeparator());

    s.append("Schemas: ");
    rs = dmd.getSchemas();
    while (rs.next()) {
        logger.debug("Schema: {}", rs.getString("TABLE_SCHEM"));
        s.append("{catalog}:").append(rs.getString("TABLE_CATALOG")).append(" {schema}:")
                .append(rs.getString("TABLE_SCHEM")).append(",");
    }
    rs.close();
    s.append(System.lineSeparator()).append("Target Catalog: ").append(catalog).append(System.lineSeparator())
            .append("Target Schema: ").append(schema).append(System.lineSeparator());

    //       if (dmr.hasAuditConfigTable()){
    //           s.append("Has auditConfigSource table").append(System.lineSeparator());
    //       }

    conn.close();

    return s.toString();

}