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.github.rinde.gpem17.evo.StatsLogger.java

static void appendResults(Iterable<SimulationResult> results, File dest, String generationId) {
    StringBuilder sb = new StringBuilder();
    for (SimulationResult sr : results) {
        SimResult ro = (SimResult) sr.getResultObject();
        StatisticsDTO stats = ro.getStats();

        final String pc = sr.getSimArgs().getScenario().getProblemClass().getId();
        final String id = sr.getSimArgs().getScenario().getProblemInstanceId();
        final String scenarioName = DASH_JOINER.join(pc, id);
        boolean isValid = GPEM17.OBJ_FUNC.isValidResult(stats);
        double cost = GPEM17.OBJ_FUNC.computeCost(stats);
        final ImmutableMap.Builder<Enum<?>, Object> map = ImmutableMap.<Enum<?>, Object>builder()
                .put(CsvFields.GENERATION, generationId).put(CsvFields.SCENARIO_ID, scenarioName)
                .put(CsvFields.RANDOM_SEED, sr.getSimArgs().getRandomSeed()).put(CsvFields.COST, cost)
                .put(CsvFields.TRAVEL_TIME, GPEM17.OBJ_FUNC.travelTime(stats))
                .put(CsvFields.TARDINESS, GPEM17.OBJ_FUNC.tardiness(stats))
                .put(CsvFields.OVER_TIME, GPEM17.OBJ_FUNC.overTime(stats)).put(CsvFields.IS_VALID, isValid)
                .put(CsvFields.NUM_ORDERS, stats.totalParcels).put(CsvFields.NUM_VEHICLES, stats.totalVehicles)
                .put(CsvFields.COST_PER_PARCEL, isValid ? cost / (double) stats.totalParcels : "invalid");

        if (ro.getAuctionStats().isPresent()) {
            final AuctionStats aStats = ro.getAuctionStats().get();
            map.put(CsvFields.NUM_REAUCTIONS, aStats.getNumReauctions())
                    .put(CsvFields.NUM_UNSUC_REAUCTIONS, aStats.getNumUnsuccesfulReauctions())
                    .put(CsvFields.NUM_FAILED_REAUCTIONS, aStats.getNumFailedReauctions());
        } else {/*from  w  w  w  .jav a 2s.  c o  m*/
            map.put(CsvFields.NUM_REAUCTIONS, -1).put(CsvFields.NUM_UNSUC_REAUCTIONS, -1)
                    .put(CsvFields.NUM_FAILED_REAUCTIONS, -1);
        }
        appendValuesTo(sb, map.build(), CsvFields.values()).append(System.lineSeparator());
    }

    try {
        Files.append(sb.toString(), dest, Charsets.UTF_8);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:ch.puzzle.itc.mobiliar.business.utils.SecureFileLoaderTest.java

@Test
public void testLoadFileFromFileSystem() throws IOException, IllegalAccessException {
    String s = "Hello" + System.lineSeparator() + "World" + System.lineSeparator() + "How are you?";
    Files.write(f, Arrays.asList(s.split(System.lineSeparator())), StandardCharsets.UTF_8);
    String result = fileLoader.loadFileFromFileSystem(dir.toString(), f.toString());

    Assert.assertEquals(s, result);/*from  ww w.  j  a v a 2  s.  c  o  m*/

}

From source file:com.cisco.oss.foundation.tools.simulator.rest.resources.SimulatorQueueResource.java

/**
 * this function will delete the last request from the queue on this port
 *//*from   ww w  .j  av a  2  s. com*/
@DELETE
@Path("/lastRequest")
public Response deleteLastRequestFromQueue(@PathParam("port") final int port) {
    if (!simulatorService.simulatorExists(port)) {
        String msg = "can not delete last request from queue of simulator. simulator on port " + port
                + " doesn't exist";
        logger.error(msg);
        return Response.status(Status.BAD_REQUEST).entity(msg).build();
    }

    SimulatorRequest removeLastRequestOfSimulator = simulatorService.removeLastRequestOfSimulator(port);
    if (removeLastRequestOfSimulator == null) {
        return Response.status(Status.OK)
                .entity("queue is empty. No request of simulator on port " + port + " was removed").build();
    } else {
        return Response.status(Status.OK).entity("last request of simulator on port " + port + " was removed: "
                + System.lineSeparator() + removeLastRequestOfSimulator.toString()).build();
    }
}

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

protected void write(String outlierrmFile, String outputFile) {
    BufferedReader br = null;/*w w  w.  j av  a  2 s .c om*/
    String line = "";
    StringBuilder builder = new StringBuilder();

    try {
        br = new BufferedReader(new FileReader(outlierrmFile));
        while ((line = br.readLine()) != null) {
            String[] str = line.split("\t");
            if (notol.contains(Integer.valueOf(str[7]))) {
                builder.append(str[0] + "\t" + str[1] + "\t" + str[2] + "\t" + str[3] + "\t" + str[4] + "\t"
                        + str[5] + "\t" + str[6] + "\t" + str[7] + "\t" + "no");
            } else {
                builder.append(str[0] + "\t" + str[1] + "\t" + str[2] + "\t" + str[3] + "\t" + str[4] + "\t"
                        + str[5] + "\t" + str[6] + "\t" + str[7] + "\t" + "yes");
            }
            builder.append(System.lineSeparator());
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileHelper.writeFile(builder.toString(), outputFile, false);

}

From source file:org.apache.nifi.toolkit.tls.util.TlsHelper.java

public static String writeKeyStore(KeyStore keyStore, OutputStreamFactory outputStreamFactory, File file,
        String password, boolean generatedPassword) throws IOException, GeneralSecurityException {
    try (OutputStream fileOutputStream = outputStreamFactory.create(file)) {
        keyStore.store(fileOutputStream, password.toCharArray());
    } catch (IOException e) {
        if (e.getMessage().toLowerCase().contains(ILLEGAL_KEY_SIZE)
                && !isUnlimitedStrengthCryptographyEnabled()) {
            if (generatedPassword) {
                file.delete();/* w ww.ja  v  a  2s .c  o  m*/
                String truncatedPassword = password.substring(0, 7);
                try (OutputStream fileOutputStream = outputStreamFactory.create(file)) {
                    keyStore.store(fileOutputStream, truncatedPassword.toCharArray());
                }
                logTruncationWarning(file);
                return truncatedPassword;
            } else {
                throw new GeneralSecurityException("Specified password for " + file
                        + " too long to work without unlimited JCE policy installed." + System.lineSeparator()
                        + "Please see " + JCE_URL);
            }
        } else {
            throw e;
        }
    }
    return password;
}

From source file:appmain.AppMain.java

private void writeCSV(File csv, List<String> content) {
    BufferedWriter writer = null;
    try {//from  w  w  w.  j a v a2s  .c  om
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csv, true), "ISO-8859-2"));
        for (String line : content) {
            writer.write(line + System.lineSeparator());
        }
        writer.flush();
    } catch (IOException | HeadlessException e) {
        JOptionPane.showMessageDialog(null,
                "Hiba a CSV fjl rsa kzben!\n" + ExceptionUtils.getStackTrace(e), "Hiba",
                JOptionPane.ERROR_MESSAGE);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}

From source file:org.assertj.maven.generator.AssertionsGeneratorReport.java

private void buildGeneratorReportWhenNothingWasGenerated(StringBuilder reportBuilder) {
    reportBuilder.append(System.lineSeparator());
    reportBuilder//ww w.  j  a  va2 s  .  c o  m
            .append("No assertions generated as no classes have been found from given classes/packages.\n");
    if (isNotEmpty(inputClasses)) {
        reportBuilder.append(INDENT).append("Given classes : ").append(Arrays.toString(inputClasses));
        reportBuilder.append(System.lineSeparator());
    }
    if (isNotEmpty(inputPackages)) {
        reportBuilder.append(INDENT).append("Given packages : ").append(Arrays.toString(inputPackages));
        reportBuilder.append(System.lineSeparator());
    }
    if (isNotEmpty(excludedClassesFromAssertionGeneration)) {
        reportBuilder.append(INDENT).append("Excluded classes : ")
                .append(excludedClassesFromAssertionGeneration);
    }
}

From source file:com.yohanliyanage.jenkins.plugins.sparkdeploy.deployer.DeploymentManager.java

@SuppressWarnings("unchecked")
private Map<String, Object> invokeUrl(String method, URL url, String payload) throws IOException {
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(method);
    connection.setRequestProperty("Accept", "application/json");

    if (payload != null) {
        if (verbose) {
            logger.println("[Spark-Deployer] VERBOSE : Invoking URL: " + method + " " + url.toString()
                    + " with payload : \n" + payload);
        }/* w  ww . j a  va2  s  . com*/
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Type", "application/json");
        OutputStream os = connection.getOutputStream();
        os.write(payload.getBytes());
        os.flush();
    } else {
        if (verbose) {
            logger.println("[Spark-Deployer] VERBOSE : Invoking URL " + method + " " + url.toString());
        }
    }

    InputStream responseStream;

    if (isSuccessResponseCode(connection.getResponseCode())) {
        // 2xx - Success
        responseStream = connection.getInputStream();
    } else {
        responseStream = connection.getErrorStream();
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(responseStream));

    StringBuilder response = new StringBuilder();
    String line;
    while ((line = br.readLine()) != null) {
        response.append(line).append(System.lineSeparator());
    }

    if (verbose) {
        logger.println("[Spark-Deployer] VERBOSE : Response from Spark : \n" + response);
    }

    if (!isSuccessResponseCode(connection.getResponseCode())) {
        throw new RuntimeException("Operation Failed. Response is " + connection.getResponseCode() + " : "
                + connection.getResponseMessage());
    }

    return (Map) mapper.readValue(response.toString(), HashMap.class);
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.ValidationTest.java

@Test
public void validatePluginInvalidActionTypeProviderFailure() {
    final String error = "AWS CodePipeline Jenkins plugin setup error. One or more required configuration parameters have not been specified."
            + System.lineSeparator();

    thrown.expect(Failure.class);
    thrown.expectMessage(error);// ww  w.  j  ava 2  s .  co m
    thrown.expectMessage("Category:");
    thrown.expectMessage("Version: 1");
    thrown.expectMessage("Provider:");

    Validation.validatePlugin("", "", "us-east-1", CategoryType.Build.getName(), "", "1", "ProjectName", null);
}

From source file:org.apache.nifi.processors.radius.ConvertRadiusToCSV.java

/**
 * Generate a String as CSV format/* ww w .  jav a 2s .  com*/
 * @param content String wiht specift format
 * @return String with header at first line and the value at second line
 */
private static String getCsvFormat(final String content) {

    //String [] fileString = content.split("\\n");
    String[] fileString = content.split("\\t"); //Split by anything common to break as line

    StringBuilder csvHeader = new StringBuilder("Time,");
    StringBuilder csvValue = new StringBuilder();

    if (fileString != null) {
        boolean isFirstLine = true;

        for (String line : fileString) {
            if (isFirstLine) {
                csvValue.append(line);
                csvValue.append(COMMA);
                isFirstLine = false;
                continue;
            }
            String[] lineValue = line.split("=");
            csvHeader.append(lineValue[0].trim());
            csvHeader.append(COMMA);
            csvValue.append(lineValue[1].trim());
            csvValue.append(COMMA);
        }
    }

    //Remove the last comma
    csvHeader = csvHeader.deleteCharAt(csvHeader.length() - 2);
    csvValue = csvValue.deleteCharAt(csvValue.length() - 2);

    //Mont the string to be return
    String csvString = csvHeader.toString() + System.lineSeparator() + csvValue.toString();

    return csvString;
}