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:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSyncValidator.java

private Integer getCreateAfter(JSONObject validateParameters, Volume vol) {
    if ((validateParameters == null) | (vol == null)) {
        return null;
    }//  www.j  av a 2  s .  c o  m

    Integer createAfter = null;
    if (validateParameters.containsKey("CreateAfter")) {
        try {
            createAfter = Integer.parseInt(validateParameters.get("CreateAfter").toString());
        } catch (Exception e) {
            logger.error("Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return createAfter;
}

From source file:com.jhash.oimadmin.Utils.java

public static String readFileInJar(JarFile jarFile, JarEntry file) {
    StringBuilder readFileData = new StringBuilder();
    try (BufferedReader jarFileInputStream = new BufferedReader(
            new InputStreamReader(jarFile.getInputStream(file)))) {
        String readLine;//from   w ww  .  jav  a  2s.  co m
        while ((readLine = jarFileInputStream.readLine()) != null) {
            readFileData.append(readLine);
            readFileData.append(System.lineSeparator());
        }
    } catch (Exception exception) {
        throw new OIMAdminException("Failed to read file " + file + " in jar file " + jarFile.getName(),
                exception);
    }
    return readFileData.toString();
}

From source file:com.compomics.colims.client.controller.AnalyticalRunsSearchSettingsController.java

/**
 * Delete the database entity (project, experiment, analytical runs) from
 * the database. Shows a confirmation dialog first. When confirmed, a
 * DeleteDbTask message is sent to the DB task queue. A message dialog is
 * shown in case the queue cannot be reached or in case of an IOException
 * thrown by the sendDbTask method./*w  w w .  j  a  v a 2s . co m*/
 *
 * @param entity the entity to delete
 * @param dbEntityClass the database entity class
 * @return true if the delete task is confirmed.
 */
private boolean deleteEntity(final DatabaseEntity entity, final Class dbEntityClass) {
    boolean deleteConfirmation = false;

    //check delete permissions
    if (userBean.getDefaultPermissions().get(DefaultPermission.DELETE)) {
        int option = JOptionPane.showConfirmDialog(mainController.getMainFrame(),
                "Are you sure? This will remove all underlying database relations (spectra, psm's, ...) as well."
                        + System.lineSeparator() + "A delete task will be sent to the database task queue.",
                "Delete " + dbEntityClass.getSimpleName() + " confirmation.", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            //check connection
            if (queueManager.isReachable()) {
                DeleteDbTask deleteDbTask = new DeleteDbTask(dbEntityClass, entity.getId(),
                        userBean.getCurrentUser().getId());
                try {
                    dbTaskProducer.sendDbTask(deleteDbTask);
                    deleteConfirmation = true;
                } catch (IOException e) {
                    LOGGER.error(e, e.getCause());
                    eventBus.post(new UnexpectedErrorMessageEvent(e.getMessage()));
                }
            } else {
                eventBus.post(new StorageQueuesConnectionErrorMessageEvent(queueManager.getBrokerName(),
                        queueManager.getBrokerUrl(), queueManager.getBrokerJmxUrl()));
            }
        }
    } else {
        mainController.showPermissionErrorDialog(
                "Your user doesn't have rights to delete this " + entity.getClass().getSimpleName());
    }

    return deleteConfirmation;
}

From source file:ie.nuim.cs.dri.metadata.WebSearch.java

/**
 *
 * @return/*  w w w  .j  a  v a  2  s .c  o  m*/
 */
public String getGS() {
    BufferedReader br = null;
    String sCurrentLine;
    String fullText = "";
    try {
        FileReader jrcFileReader = new FileReader("C:\\DRINVENTOR_PROJECT\\corpus\\test.htm");
        br = new BufferedReader(jrcFileReader);
        StringBuilder sb = new StringBuilder();

        while ((sCurrentLine = br.readLine()) != null) {
            sb.append(sCurrentLine);
            //System.out.println(sb.toString());
            sb.append(System.lineSeparator());

        }
        fullText = sb.toString();
    } catch (IOException e) {
    } finally {
        try {
            if (br != null) {
                br.close();
            }
        } catch (IOException ex) {
        }
    }
    //System.out.println("Full text from gs "+ fullText);
    return fullText;
}

From source file:com.netflix.genie.core.jobs.workflow.impl.InitialSetupTask.java

@VisibleForTesting
void createJobEnvironmentVariables(final Writer writer, final String jobId, final String jobName,
        final int memory) throws GenieException, IOException {
    writer.write(JobConstants.EXPORT + JobConstants.GENIE_JOB_ID_ENV_VAR + JobConstants.EQUALS_SYMBOL
            + JobConstants.DOUBLE_QUOTE_SYMBOL + jobId + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR);

    // Append new line
    writer.write(System.lineSeparator());

    // create environment variable for the job name
    writer.write(JobConstants.EXPORT + JobConstants.GENIE_JOB_NAME_ENV_VAR + JobConstants.EQUALS_SYMBOL
            + JobConstants.DOUBLE_QUOTE_SYMBOL + jobName + JobConstants.DOUBLE_QUOTE_SYMBOL + LINE_SEPARATOR);

    // Append new line
    writer.write(LINE_SEPARATOR);/* w  ww . j a v a 2s.  c  o m*/

    // create environment variable for the job name
    writer.write(JobConstants.EXPORT + JobConstants.GENIE_JOB_MEMORY_ENV_VAR + JobConstants.EQUALS_SYMBOL
            + memory + LINE_SEPARATOR);

    // Append new line
    writer.write(LINE_SEPARATOR);
}

From source file:it.larusba.integration.neo4j.jsonloader.transformer.UnrefactoredDomainBasedJsonTransformer.java

/**
 * @param documentId//from   w  w w.j a v a2s  . c o  m
 * @param documentType
 * @param documentMap
 * @param objectDescriptors
 * @return
 */
@SuppressWarnings("unchecked")
private String transform(String documentId, String documentType, Map<String, Object> documentMap,
        JsonObjectDescriptorHelper objectDescriptorHelper, Integer position) {

    boolean firstAttr = true;
    boolean firstUniqueAttr = true;

    List<String> childNodes = new ArrayList<String>();
    List<String> childRelationships = new ArrayList<String>();

    StringBuffer rootNode = new StringBuffer();

    String nodeLabel = buildNodeLabel(documentType, documentMap, objectDescriptorHelper);
    String nodeReference = buildNodeReference(position, nodeLabel);

    //TODO implement
    if (objectDescriptorHelper.hasUniqueKeyAttributes(nodeLabel)) {
    } else {
    }

    rootNode.append("MERGE (").append(nodeReference).append(":").append(nodeLabel);

    StringBuffer nodeAttributes = new StringBuffer();

    for (String attributeName : documentMap.keySet()) {

        Object attributeValue = documentMap.get(attributeName);

        if (attributeValue instanceof Map) {

            childNodes.add(transform(documentId, StringUtils.capitalize(attributeName),
                    (Map<String, Object>) attributeValue, objectDescriptorHelper, null));

            childRelationships
                    .add(new StringBuffer().append("CREATE (").append(nodeReference).append(")-[").append(":")
                            .append(nodeReference.toUpperCase()).append("_").append(attributeName.toUpperCase())
                            .append("]->(").append(attributeName).append(")").toString());

        } else if (attributeValue instanceof List) {

            List<Object> attributeValueList = (List<Object>) attributeValue;

            if (attributeValueList.size() > 0) {

                if (attributeValueList.get(0) instanceof Map) {

                    for (int i = 0; i < attributeValueList.size(); i++) {

                        Object attributeValueElement = attributeValueList.get(i);

                        if (attributeValueElement instanceof Map) {

                            childNodes.add(transform(documentId, StringUtils.capitalize(attributeName),
                                    (Map<String, Object>) attributeValueElement, objectDescriptorHelper, i));

                            childRelationships.add(new StringBuffer().append("MERGE (").append(nodeReference)
                                    .append(")-[").append(":").append(nodeReference.toUpperCase()).append("_")
                                    .append(attributeName.toUpperCase()).append("]->(")
                                    .append(attributeName + i).append(")").toString());
                        }
                    }
                } else {

                    if (firstAttr) {
                        nodeAttributes.append("ON CREATE SET ");

                        if (documentId != null) {
                            nodeAttributes.append(nodeReference).append(".").append("_documentId = '")
                                    .append(documentId).append("', ");
                        }

                        firstAttr = false;
                    } else {
                        nodeAttributes.append(", ");
                    }

                    nodeAttributes.append(nodeReference).append(".").append(attributeName).append(" = [");

                    for (int i = 0; i < attributeValueList.size(); i++) {

                        Object attributeValueElement = attributeValueList.get(i);

                        if (attributeValueElement != null) {

                            if (i != 0)
                                nodeAttributes.append(", ");

                            if (attributeValueElement instanceof String) {
                                nodeAttributes.append("'").append(attributeValueElement).append("'");
                            } else {
                                nodeAttributes.append(attributeValueElement);
                            }
                        }
                    }

                    nodeAttributes.append("]");
                }
            }
        } else {

            if (objectDescriptorHelper.isAttributeInUniqueKey(nodeLabel, attributeName)) {

                if (firstUniqueAttr) {
                    rootNode.append(" { ");

                    firstUniqueAttr = false;
                } else {
                    rootNode.append(", ");
                }

                rootNode.append(attributeName).append(": ");

                if (attributeValue instanceof String) {
                    rootNode.append("'").append(attributeValue).append("'");
                } else {
                    rootNode.append(attributeValue);
                }

            } else {

                if (attributeValue != null) {

                    if (firstAttr) {
                        nodeAttributes.append("ON CREATE SET ");

                        if (documentId != null) {
                            nodeAttributes.append(nodeReference).append(".").append("_documentId = '")
                                    .append(documentId).append("', ");
                        }

                        firstAttr = false;
                    } else {
                        nodeAttributes.append(", ");
                    }

                    nodeAttributes.append(nodeReference).append(".").append(attributeName).append(" = ");

                    if (attributeValue instanceof String) {
                        nodeAttributes.append("'").append(attributeValue).append("'");
                    } else {
                        nodeAttributes.append(attributeValue);
                    }
                }
            }
        }
    }

    if (firstAttr == firstUniqueAttr) {
        rootNode.append("}");
    }
    rootNode.append(")").append(System.lineSeparator()).append(nodeAttributes);

    StringBuffer cypher = new StringBuffer();
    cypher.append(rootNode);

    for (String childNode : childNodes) {
        cypher.append(System.lineSeparator()).append(childNode);
    }

    for (String childRelationship : childRelationships) {
        cypher.append(System.lineSeparator()).append(childRelationship);
    }

    return cypher.toString();
}

From source file:net.e2.bw.idreg.db2ldif.Db2Ldif.java

/**
 * Loads and returns the text of the given file. The file must be placed
 * in the same package as the class./*from   www. j a  va  2s .c  om*/
 *
 * @param resourceName the name of the file
 * @return the text content of the file
 */
public static String loadResourceText(String resourceName) {
    try (BufferedReader r = new BufferedReader(
            new InputStreamReader(Db2Ldif.class.getResourceAsStream(resourceName), "UTF-8"))) {
        StringBuilder result = new StringBuilder();
        String line;
        while ((line = r.readLine()) != null) {
            result.append(line).append(System.lineSeparator());
        }
        return result.toString();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Undefined resource " + resourceName, ex);
    }
}

From source file:com.joyent.manta.config.ConfigContext.java

/**
 * Utility method for validating that the configuration has been instantiated
 * with valid settings./*from w w w.  j av a 2  s  .c  o m*/
 *
 * @param config configuration to test
 * @throws ConfigurationException thrown when validation fails
 */
static void validate(final ConfigContext config) {
    List<String> failureMessages = new ArrayList<>();

    if (StringUtils.isBlank(config.getMantaUser())) {
        failureMessages.add("Manta account name must be specified");
    }

    if (StringUtils.isBlank(config.getMantaURL())) {
        failureMessages.add("Manta URL must be specified");
    } else {
        try {
            new URI(config.getMantaURL());
        } catch (URISyntaxException e) {
            final String msg = String.format("%s - invalid Manta URL: %s", e.getMessage(),
                    config.getMantaURL());
            failureMessages.add(msg);
        }
    }

    if (config.getTimeout() != null && config.getTimeout() < 0) {
        failureMessages.add("Manta timeout must be 0 or greater");
    }

    if (config.getTcpSocketTimeout() != null && config.getTcpSocketTimeout() < 0) {
        failureMessages.add("Manta tcp socket timeout must be 0 or greater");
    }

    if (config.getConnectionRequestTimeout() != null && config.getConnectionRequestTimeout() < 0) {
        failureMessages.add("Manta connection request timeout must be 0 or greater");
    }

    if (config.getExpectContinueTimeout() != null && config.getExpectContinueTimeout() < 1) {
        failureMessages.add("Manta Expect 100-continue timeout must be 1 or greater");
    }

    final boolean authenticationEnabled = BooleanUtils.isNotTrue(config.noAuth());

    if (authenticationEnabled) {
        if (config.getMantaKeyId() == null) {
            failureMessages.add("Manta key id must be specified");
        }

        if (config.getMantaKeyPath() == null && config.getPrivateKeyContent() == null) {
            failureMessages.add("Either the Manta key path must be set or the private "
                    + "key content must be set. Both can't be null.");
        }

        if (config.getMantaKeyPath() != null && StringUtils.isBlank(config.getMantaKeyPath())) {
            failureMessages.add("Manta key path must not be blank");
        }

        if (config.getPrivateKeyContent() != null && StringUtils.isBlank(config.getPrivateKeyContent())) {
            failureMessages.add("Manta private key content must not be blank");
        }
    }

    if (config.getSkipDirectoryDepth() != null && config.getSkipDirectoryDepth() < 0) {
        failureMessages.add("Manta skip directory depth must be 0 or greater");
    }

    if (config.getMetricReporterMode() != null) {
        if (MetricReporterMode.SLF4J.equals(config.getMetricReporterMode())) {
            if (config.getMetricReporterOutputInterval() == null) {
                failureMessages.add("SLF4J metric reporter selected but no output interval was provided");
            } else if (config.getMetricReporterOutputInterval() < 1) {
                failureMessages.add("Metric reporter output interval (ms) must be 1 or greater");
            }
        }
    }

    if (BooleanUtils.isTrue(config.isClientEncryptionEnabled())) {
        encryptionSettings(config, failureMessages);
    }

    if (!failureMessages.isEmpty()) {
        String messages = StringUtils.join(failureMessages, System.lineSeparator());
        ConfigurationException e = new ConfigurationException(
                "Errors when loading Manta SDK configuration:" + System.lineSeparator() + messages);

        // We don't dump all of the configuration settings, just the important ones

        e.setContextValue(MapConfigContext.MANTA_URL_KEY, config.getMantaURL());
        e.setContextValue(MapConfigContext.MANTA_USER_KEY, config.getMantaUser());
        e.setContextValue(MapConfigContext.MANTA_KEY_ID_KEY, config.getMantaKeyId());
        e.setContextValue(MapConfigContext.MANTA_NO_AUTH_KEY, config.noAuth());
        e.setContextValue(MapConfigContext.MANTA_KEY_PATH_KEY, config.getMantaKeyPath());

        final String redactedPrivateKeyContent;
        if (config.getPrivateKeyContent() == null) {
            redactedPrivateKeyContent = "null";
        } else {
            redactedPrivateKeyContent = "non-null";
        }

        e.setContextValue(MapConfigContext.MANTA_PRIVATE_KEY_CONTENT_KEY, redactedPrivateKeyContent);
        e.setContextValue(MapConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_KEY,
                config.isClientEncryptionEnabled());

        if (BooleanUtils.isTrue(config.isClientEncryptionEnabled())) {
            e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_KEY_ID_KEY, config.getEncryptionKeyId());
            e.setContextValue(MapConfigContext.MANTA_PERMIT_UNENCRYPTED_DOWNLOADS_KEY,
                    config.permitUnencryptedDownloads());
            e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_ALGORITHM_KEY, config.getEncryptionAlgorithm());
            e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_PATH_KEY,
                    config.getEncryptionPrivateKeyPath());
            e.setContextValue(MapConfigContext.MANTA_ENCRYPTION_PRIVATE_KEY_BYTES_KEY + "_size",
                    ArrayUtils.getLength(config.getEncryptionPrivateKeyBytes()));
        }

        throw e;
    }
}

From source file:dpfmanager.shell.modules.report.core.ReportGenerator.java

/**
 * Read filefrom resources string.//from ww  w . ja v a2s .  c o  m
 *
 * @param pathStr the path str
 * @return the string
 */
public String readFilefromResources(String pathStr) {
    String text = "";
    Path path = Paths.get(pathStr);
    try {
        if (Files.exists(path)) {
            // Look in current dir
            BufferedReader br = new BufferedReader(new FileReader(pathStr));
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();
            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            text = sb.toString();
            br.close();
        } else {
            // Look in JAR
            Class cls = ReportGenerator.class;
            ClassLoader cLoader = cls.getClassLoader();
            InputStream in = cLoader.getResourceAsStream(pathStr);
            if (in != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                StringBuilder out = new StringBuilder();
                String newLine = System.getProperty("line.separator");
                String line;
                while ((line = reader.readLine()) != null) {
                    out.append(line);
                    out.append(newLine);
                }
                text = out.toString();
            }
        }
    } catch (FileNotFoundException e) {
        context.send(BasicConfig.MODULE_MESSAGE,
                new LogMessage(getClass(), Level.ERROR, "Template for html not found in dir."));
    } catch (IOException e) {
        context.send(BasicConfig.MODULE_MESSAGE,
                new LogMessage(getClass(), Level.ERROR, "Error reading " + pathStr));
    }

    return text;
}

From source file:com.pearson.eidetic.driver.threads.subthreads.SnapshotVolumeSyncValidator.java

private String getCluster(JSONObject validateParameters, Volume vol) {
    if ((validateParameters == null) | (vol == null)) {
        return null;
    }//w w  w .jav a2  s.c o m

    String cluster = null;
    if (validateParameters.containsKey("Cluster")) {
        try {
            cluster = validateParameters.get("Cluster").toString();
        } catch (Exception e) {
            logger.error("Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                    + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    return cluster;

}