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.netflix.genie.core.jobs.workflow.impl.JobTask.java

/**
 * {@inheritDoc}//from   w  w  w .  j  a  v a  2s.  c  o m
 */
@Override
public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException {
    final long start = System.nanoTime();
    try {
        final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context
                .get(JobConstants.JOB_EXECUTION_ENV_KEY);
        final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath();
        final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY);
        final String jobId = jobExecEnv.getJobRequest().getId()
                .orElseThrow(() -> new GeniePreconditionException("No job id found. Unable to continue"));
        log.info("Starting Job Task for job {}", jobId);

        final Optional<String> setupFile = jobExecEnv.getJobRequest().getSetupFile();
        if (setupFile.isPresent()) {
            final String jobSetupFile = setupFile.get();
            if (StringUtils.isNotBlank(jobSetupFile)) {
                final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + jobSetupFile
                        .substring(jobSetupFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1);

                fts.getFile(jobSetupFile, localPath);

                writer.write("# Sourcing setup file specified in job request" + System.lineSeparator());
                writer.write(
                        JobConstants.SOURCE
                                + localPath.replace(jobWorkingDirectory,
                                        "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}")
                                + System.lineSeparator());

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

        // Iterate over and get all dependencies
        for (final String dependencyFile : jobExecEnv.getJobRequest().getDependencies()) {
            if (StringUtils.isNotBlank(dependencyFile)) {
                final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + dependencyFile
                        .substring(dependencyFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1);

                fts.getFile(dependencyFile, localPath);
            }
        }

        // Copy down the attachments if any to the current working directory
        this.attachmentService.copy(jobId, jobExecEnv.getJobWorkingDir());
        // Delete the files from the attachment service to save space on disk
        this.attachmentService.delete(jobId);

        // Print out the current Envrionment to a env file before running the command.
        writer.write("# Dump the environment to a env.log file" + System.lineSeparator());
        writer.write("env | sort > " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}"
                + JobConstants.GENIE_ENV_PATH + System.lineSeparator());

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

        writer.write("# Kick off the command in background mode and wait for it using its pid"
                + System.lineSeparator());

        writer.write(jobExecEnv.getCommand().getExecutable() + JobConstants.WHITE_SPACE
                + jobExecEnv.getJobRequest().getCommandArgs() + JobConstants.STDOUT_REDIRECT
                + JobConstants.STDOUT_LOG_FILE_NAME + JobConstants.STDERR_REDIRECT
                + JobConstants.STDERR_LOG_FILE_NAME + " &" + System.lineSeparator());

        // Wait for the above process started in background mode. Wait lets us get interrupted by kill signals.
        writer.write("wait $!" + System.lineSeparator());

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

        // capture exit code and write to genie.done file
        writer.write("# Write the return code from the command in the done file." + System.lineSeparator());
        writer.write(JobConstants.GENIE_DONE_FILE_CONTENT_PREFIX + JobConstants.GENIE_DONE_FILE_NAME
                + System.lineSeparator());

        // Print the timestamp once its done running.
        writer.write("echo End: `date '+%Y-%m-%d %H:%M:%S'`\n");

        log.info("Finished Job Task for job {}", jobExecEnv.getJobRequest().getId());
    } finally {
        final long finish = System.nanoTime();
        this.timer.record(finish - start, TimeUnit.NANOSECONDS);
    }
}

From source file:edu.purdue.pivot.skwiki.server.ImageUploaderServlet.java

@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles)
        throws UploadActionException {

    connection = null;// w  ww  .java2s. c  o m
    Statement st = null;

    /* read database details from file */
    BufferedReader br;
    current_project_name = "";
    main_database_name = "";

    try {
        br = new BufferedReader(new FileReader(this.getServletContext().getRealPath("/serverConfig.txt")));
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();

        while (line != null) {
            String first = line.substring(0, line.lastIndexOf(':'));
            String last = line.substring(line.lastIndexOf(':') + 1);

            if (first.contains("content_database")) {
                current_project_name = last;
            }

            if (first.contains("owner_database")) {
                main_database_name = last;
            }

            if (first.contains("username")) {
                postgres_name = last;
            }

            if (first.contains("password")) {
                postgres_password = last;
            }

            sb.append(line);
            sb.append(System.lineSeparator());
            line = br.readLine();
        }

        //String everything = sb.toString();
        //System.out.println("file: "+everything);
        br.close();

    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } finally {

    }

    try {
        connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/" + current_project_name,
                "postgres", "fujiko");
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String response = "";
    int cont = 0;
    for (FileItem item : sessionFiles) {
        if (false == item.isFormField()) {
            cont++;
            try {
                String uuid = UUID.randomUUID().toString();
                String saveName = uuid + '.' + FilenameUtils.getExtension(item.getName());

                //               String saveName = item.getName();

                //write to database
                File file = new File(saveName);
                item.write(file);

                // / Save a list with the received files
                receivedFiles.put(item.getFieldName(), file);
                receivedContentTypes.put(item.getFieldName(), item.getContentType());
                receivedFilePaths.put(item.getFieldName(), file.getAbsolutePath());

                // / Send a customized message to the client.
                response += "File saved as " + file.getAbsolutePath();

                //write filename to database

                String selectStr = "insert into images values (" + "\'" + item.getFieldName() + "\'," + "\'"
                        + file.getAbsolutePath() + "\'" + ")";
                st = connection.createStatement();
                int textReturnCode = st.executeUpdate(selectStr);

            } catch (Exception e) {
                throw new UploadActionException(e.getMessage());
            }
        }
    }

    // / Remove files from session because we have a copy of them
    removeSessionFileItems(request);

    // / Send your customized message to the client.
    return response;
}

From source file:org.apache.nifi.toolkit.zkmigrator.ZooKeeperMigratorMain.java

private static void printUsage(String errorMessage, Options options) {
    Preconditions.checkNotNull(options, "command line options were not specified");
    if (errorMessage != null) {
        System.out.println(errorMessage + System.lineSeparator());
    }/*from w w  w  .j av  a2 s  .c om*/
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setWidth(160);
    helpFormatter.setDescPadding(0);
    helpFormatter.printHelp(ZooKeeperMigratorMain.class.getCanonicalName(), HEADER, options, FOOTER, true);
}

From source file:de.fosd.jdime.strategy.ASTNodeStrategy.java

/**
 * @param artifact/*w w  w  .j av  a2 s .co m*/
 *            artifact that should be printed
 */
private void dumpGraphVizTree(final ASTNodeArtifact artifact) {
    StringBuilder sb = new StringBuilder();
    sb.append("digraph ast {").append(System.lineSeparator());
    sb.append("node [shape=ellipse];").append(System.lineSeparator());
    sb.append("nodesep=0.8;").append(System.lineSeparator());

    // nodes
    sb.append(artifact.dumpGraphvizTree(true));

    // footer
    sb.append("}");

    System.out.println(sb.toString());
}

From source file:io.fd.maintainer.plugin.parser.MaintainersParserTest.java

@Test
public void testParse() throws URISyntaxException, IOException, MaintainerMismatchException {
    final MaintainersParser parser = new MaintainersParser();

    final URL url = this.getClass().getResource("/maintainers");
    final String content = Files.readLines(new File(url.toURI()), StandardCharsets.UTF_8).stream()
            .collect(Collectors.joining(System.lineSeparator()));
    final List<ComponentInfo> maintainers = parser.parseMaintainers(content);
    assertTrue(!maintainers.isEmpty());//from  ww  w  .j a  va  2  s  .c o m

    // tests couple of entries
    assertTrue(compare(maintainers.get(0), buildSystem()));
    assertTrue(compare(maintainers.get(1), buildSystemInternal()));
    assertTrue(compare(maintainers.get(2), doxygen()));
    assertTrue(compare(maintainers.get(3), dpdkDevelopmentPackaging()));
    assertTrue(compare(maintainers.get(4), infrastractureLibrary()));
    assertTrue(compare(maintainers.get(5), vlibLibrary()));
    assertTrue(compare(maintainers.get(6), vlibApiLibraries()));
    assertTrue(compare(maintainers.get(7), vnetBfd()));
    assertEquals(32, maintainers.size());
}

From source file:com.bc.fiduceo.matchup.MatchupTool.java

void printUsageTo(OutputStream outputStream) {
    final String ls = System.lineSeparator();
    final PrintWriter writer = new PrintWriter(outputStream);
    writer.write("matchup-tool version " + VERSION_NUMBER);
    writer.write(ls + ls);//  ww w  .  ja  v a  2s .  c  o m

    final HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.printHelp(writer, 120, "matchup-tool <options>", "Valid options are:", getOptions(), 3, 3,
            "");

    writer.flush();
}

From source file:org.apache.zeppelin.interpreter.recovery.FileSystemRecoveryStorage.java

private void save(String interpreterSettingName) throws IOException {
    InterpreterSetting interpreterSetting = interpreterSettingManager
            .getInterpreterSettingByName(interpreterSettingName);
    List<String> recoveryContent = new ArrayList<>();
    for (ManagedInterpreterGroup interpreterGroup : interpreterSetting.getAllInterpreterGroups()) {
        RemoteInterpreterProcess interpreterProcess = interpreterGroup.getInterpreterProcess();
        if (interpreterProcess != null) {
            recoveryContent.add(interpreterGroup.getId() + "\t" + interpreterProcess.getHost() + ":"
                    + interpreterProcess.getPort());
        }//w  ww  .  j a  v a2s. co m
    }
    LOGGER.debug("Updating recovery data for interpreterSetting: " + interpreterSettingName);
    LOGGER.debug("Recovery Data: " + StringUtils.join(recoveryContent, System.lineSeparator()));
    Path recoveryFile = new Path(recoveryDir, interpreterSettingName + ".recovery");
    fs.writeFile(StringUtils.join(recoveryContent, System.lineSeparator()), recoveryFile, true);
}

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

@Override
public void run() {
    isFinished_ = false;/*from w w w .  jav a2 s  . co m*/
    //kill thread if wrong creds \/ \/ \/ \/
    AmazonEC2Client ec2Client = connect(region_, awsAccessKeyId_, awsSecretKey_);

    for (Volume vol : VolumeNoTime_) {
        try {
            Date date = new java.util.Date();
            JSONParser parser = new JSONParser();

            String inttagvalue = getIntTagValue(vol);
            if (inttagvalue == null) {
                continue;
            }

            JSONObject eideticParameters;
            try {
                Object obj = parser.parse(inttagvalue);
                eideticParameters = (JSONObject) obj;
            } catch (Exception e) {
                logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                        + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                        + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
                continue;
            }

            String period = getPeriod(eideticParameters, vol);
            if (period == null) {
                continue;
            }

            Integer keep = getKeep(eideticParameters, vol);
            if (keep == null) {
                continue;
            }

            Boolean success;
            success = snapshotDecision(ec2Client, vol, period);
            if (!success) {
                continue;
            }

            success = snapshotCreation(ec2Client, vol, period, date);
            if (!success) {
                continue;
            }

            snapshotDeletion(ec2Client, vol, period, keep);

            logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=\"Error\", Error=\"normal eidetic process did not create a snapshot for volume in alloted time.\", Volume_id=\""
                    + vol.getVolumeId() + "\"");

        } catch (Exception e) {
            logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=\"Error\", Error=\"error in SnapshotChecker workflow\", stacktrace=\""
                    + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\"");
        }

    }

    for (Volume vol : VolumeTime_) {
        try {
            Date date = new java.util.Date();
            JSONParser parser = new JSONParser();

            String inttagvalue = getIntTagValue(vol);
            if (inttagvalue == null) {
                continue;
            }

            JSONObject eideticParameters;
            try {
                Object obj = parser.parse(inttagvalue);
                eideticParameters = (JSONObject) obj;
            } catch (Exception e) {
                logger.error("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                        + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId()
                        + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                        + StackTrace.getStringFromStackTrace(e) + "\"");
                continue;
            }

            String period = getPeriod(eideticParameters, vol);
            if (period == null) {
                continue;
            }

            Integer keep = getKeep(eideticParameters, vol);
            if (keep == null) {
                continue;
            }

            Boolean success;
            success = snapshotDecision(ec2Client, vol, period);
            if (!success) {
                continue;
            }

            success = snapshotCreation(ec2Client, vol, period, date);
            if (!success) {
                continue;
            }

            snapshotDeletion(ec2Client, vol, period, keep);

            logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=\"Error\", Error=\"normal eidetic process did not create a snapshot for volume in alloted time.\", Volume_id=\""
                    + vol.getVolumeId() + "\"");

        } catch (Exception e) {
            logger.info("awsAccountNickname=\"" + uniqueAwsAccountIdentifier_
                    + "\",Event=\"Error\", Error=\"error in EideticChcker workflow', Volume_id=\""
                    + vol.getVolumeId() + "\", stacktrace=\"" + e.toString() + System.lineSeparator()
                    + StackTrace.getStringFromStackTrace(e) + "\"");
        }
    }

    ec2Client.shutdown();
    isFinished_ = true;

}

From source file:com.hp.mqm.atrf.App.java

private void confValidation() {
    logger.info(System.lineSeparator());
    logger.info("PHASE : connectivity validation");
    //VALIDATE LOGIN TO ALM
    loginToAlm();/*from w  w w  . j a v a2 s  . c  om*/

    //VALIDATE LOGIN TO OCTANE
    if (!isOutput()) {
        loginToOctane();
    }
}

From source file:org.ballerinalang.swagger.cmd.SwaggerCmd.java

@Override
public void printLongDesc(StringBuilder out) {
    out.append("Generates ballerina connector, service skeleton and mock service" + System.lineSeparator());
    out.append("for a given swagger definition" + System.lineSeparator());
    out.append(System.lineSeparator());
}