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.opendoorlogistics.core.distances.DistancesSingleton.java

private synchronized ODLCostMatrix calculateGraphhopper(DistancesConfiguration request,
        StandardisedStringTreeMap<LatLong> points, final ProcessingApi processingApi) {
    initGraphhopperGraph(request, processingApi);

    final StringBuilder statusMessage = new StringBuilder();
    statusMessage.append("Loaded the graph "
            + new File(request.getGraphhopperConfig().getGraphDirectory()).getAbsolutePath());
    statusMessage.append(System.lineSeparator() + "Calculating " + points.size() + "x" + points.size()
            + " matrix using Graphhopper road network distances.");
    if (processingApi != null) {
        processingApi.postStatusMessage(statusMessage.toString());
    }/*w  w w  . j  a  va2  s .  c  o m*/

    // check for user cancellation
    if (processingApi != null && processingApi.isCancelled()) {
        return null;
    }

    // convert input to an array of graphhopper points
    int n = points.size();
    int i = 0;
    List<Map.Entry<String, LatLong>> list = IteratorUtils.toList(points.entrySet());
    GHPoint[] ghPoints = new GHPoint[n];
    for (Map.Entry<String, LatLong> entry : list) {
        ghPoints[i++] = new GHPoint(entry.getValue().getLatitude(), entry.getValue().getLongitude());
    }

    // calculate the matrix 
    CHProcessingApi chprocApi = new CHProcessingApi() {

        @Override
        public void postStatusMessage(String s) {
            if (processingApi != null) {
                processingApi.postStatusMessage(s);
            }
        }

        @Override
        public boolean isCancelled() {
            return processingApi != null ? processingApi.isCancelled() : false;
        }
    };

    MatrixResult result = lastCHGraph.calculateMatrix(ghPoints, chprocApi);
    if (processingApi != null && processingApi.isCancelled()) {
        return null;
    }

    // convert result to the output data structure
    ODLCostMatrixImpl output = ODLCostMatrixImpl.createEmptyMatrix(list);
    for (int ifrom = 0; ifrom < n; ifrom++) {
        for (int ito = 0; ito < n; ito++) {
            double timeSeconds = result.getTimeMilliseconds(ifrom, ito) * 0.001;
            timeSeconds *= request.getGraphhopperConfig().getTimeMultiplier();
            if (!result.isInfinite(ifrom, ito)) {
                setOutputValues(ifrom, ito, result.getDistanceMetres(ifrom, ito), timeSeconds,
                        request.getOutputConfig(), output);
            } else {
                for (int k = 0; k < 3; k++) {
                    output.set(UNCONNECTED_TRAVEL_COST, ifrom, ito, k);
                }
            }
        }
    }

    return output;
}

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

public Integer getKeep(JSONObject eideticParameters, Volume vol) {
    if ((eideticParameters == null) | (vol == null)) {
        return null;
    }//from   w  w  w  .j  av  a2s  .c o  m

    JSONObject createSnapshot = null;
    if (eideticParameters.containsKey("SyncSnapshot")) {
        createSnapshot = (JSONObject) eideticParameters.get("SyncSnapshot");
    }
    if (createSnapshot == null) {
        logger.error("awsAccountId=\"" + uniqueAwsAccountIdentifier_
                + "\",Event=Error, Error=\"Malformed Eidetic Tag\", Volume_id=\"" + vol.getVolumeId() + "\"");
        return null;
    }

    Integer keep = null;
    if (createSnapshot.containsKey("Retain")) {
        try {
            keep = Integer.parseInt(createSnapshot.get("Retain").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 keep;
}

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

public void addLineids(Path path, String output) {
    StringBuilder builder = new StringBuilder();

    try {//from w  w  w .  ja  v a  2 s  .  com
        List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);
        int i = 1;
        for (String l : lines) {
            builder.append(l + "\t" + i++);
            builder.append(System.lineSeparator());
        }
    } catch (IOException e) {

    }

    FileHelper.writeFile(builder.toString(), output, false);
}

From source file:controllers.modules.CorpusModule.java

public static Result update(UUID corpus) {
    OpinionCorpus corpusObj = null;//  w ww  .  j  a va 2  s. com
    if (corpus != null) {
        corpusObj = fetchResource(corpus, OpinionCorpus.class);
    }
    OpinionCorpusFactory corpusFactory = null;

    MultipartFormData formData = request().body().asMultipartFormData();
    if (formData != null) {
        // if we have a multi-part form with a file.
        if (formData.getFiles() != null) {
            // get either the file named "file" or the first one.
            FilePart filePart = ObjectUtils.defaultIfNull(formData.getFile("file"),
                    Iterables.getFirst(formData.getFiles(), null));
            if (filePart != null) {
                corpusFactory = (OpinionCorpusFactory) new OpinionCorpusFactory().setFile(filePart.getFile())
                        .setFormat(FilenameUtils.getExtension(filePart.getFilename()));
            }
        }
    } else {
        // otherwise try as a json body.
        JsonNode json = request().body().asJson();
        if (json != null) {
            OpinionCorpusFactoryModel optionsVM = Json.fromJson(json, OpinionCorpusFactoryModel.class);
            if (optionsVM != null) {
                corpusFactory = optionsVM.toFactory();
            } else {
                throw new IllegalArgumentException();
            }

            if (optionsVM.grabbers != null) {
                if (optionsVM.grabbers.twitter != null) {
                    if (StringUtils.isNotBlank(optionsVM.grabbers.twitter.query)) {
                        TwitterFactory tFactory = new TwitterFactory();
                        Twitter twitter = tFactory.getInstance();
                        twitter.setOAuthConsumer(
                                Play.application().configuration().getString("twitter4j.oauth.consumerKey"),
                                Play.application().configuration().getString("twitter4j.oauth.consumerSecret"));
                        twitter.setOAuthAccessToken(new AccessToken(
                                Play.application().configuration().getString("twitter4j.oauth.accessToken"),
                                Play.application().configuration()
                                        .getString("twitter4j.oauth.accessTokenSecret")));

                        Query query = new Query(optionsVM.grabbers.twitter.query);
                        query.count(ObjectUtils.defaultIfNull(optionsVM.grabbers.twitter.limit, 10));
                        query.resultType(Query.RECENT);
                        if (StringUtils.isNotEmpty(corpusFactory.getLanguage())) {
                            query.lang(corpusFactory.getLanguage());
                        } else if (corpusObj != null) {
                            query.lang(corpusObj.getLanguage());
                        }

                        QueryResult qr;
                        try {
                            qr = twitter.search(query);
                        } catch (TwitterException e) {
                            throw new IllegalArgumentException();
                        }

                        StringBuilder tweets = new StringBuilder();
                        for (twitter4j.Status status : qr.getTweets()) {
                            // quote for csv, normalize space, and remove higher unicode characters. 
                            String text = StringEscapeUtils.escapeCsv(StringUtils
                                    .normalizeSpace(status.getText().replaceAll("[^\\u0000-\uFFFF]", "")));
                            tweets.append(text + System.lineSeparator());
                        }

                        corpusFactory.setContent(tweets.toString());
                        corpusFactory.setFormat("txt");
                    }
                }
            }
        } else {
            // if not json, then just create empty.
            corpusFactory = new OpinionCorpusFactory();
        }
    }

    if (corpusFactory == null) {
        throw new IllegalArgumentException();
    }

    if (corpus == null && StringUtils.isEmpty(corpusFactory.getTitle())) {
        corpusFactory.setTitle("Untitled corpus");
    }

    corpusFactory.setOwnerId(SessionedAction.getUsername(ctx())).setExistingId(corpus).setEm(em());

    DocumentCorpusModel corpusVM = null;
    corpusObj = corpusFactory.create();
    if (!em().contains(corpusObj)) {
        em().persist(corpusObj);

        corpusVM = (DocumentCorpusModel) createViewModel(corpusObj);
        corpusVM.populateSize(em(), corpusObj);
        return created(corpusVM.asJson());
    }

    for (PersistentObject obj : corpusObj.getDocuments()) {
        if (em().contains(obj)) {
            em().merge(obj);
        } else {
            em().persist(obj);
        }
    }
    em().merge(corpusObj);

    corpusVM = (DocumentCorpusModel) createViewModel(corpusObj);
    corpusVM.populateSize(em(), corpusObj);
    return ok(corpusVM.asJson());
}

From source file:org.openlmis.fulfillment.service.OrderCsvHelperTest.java

@Test
public void shouldExcludeZeroQuantityLineItemsIfConfiguredSo() throws IOException {
    ReflectionTestUtils.setField(orderCsvHelper, "includeZeroQuantity", false);

    List<OrderFileColumn> orderFileColumns = new ArrayList<>();
    orderFileColumns.add(new OrderFileColumn(true, HEADER_ORDERABLE, PRODUCT, true, 1, null, LINE_ITEM,
            ORDERABLE, null, null, null));

    OrderFileTemplate orderFileTemplate = new OrderFileTemplate("O", false, orderFileColumns);

    String csv = writeCsvFile(order, orderFileTemplate);
    int numberOfLines = csv.split(System.lineSeparator()).length;

    assertThat(numberOfLines, is(1));/*from w  w w .j a v a  2 s .  c o m*/
}

From source file:org.apache.zeppelin.submarine.hadoop.YarnClient.java

public void deleteService(String serviceName) {
    String appUrl = this.yarnWebHttpAddr + "/app/v1/services/" + serviceName + "?_="
            + System.currentTimeMillis();

    InputStream inputStream = null;
    try {// ww  w.j a v  a 2 s .co  m
        HttpResponse response = callRestUrl(appUrl, principal, HTTP.DELETE);
        inputStream = response.getEntity().getContent();
        String result = new BufferedReader(new InputStreamReader(inputStream)).lines()
                .collect(Collectors.joining(System.lineSeparator()));
        if (response.getStatusLine().getStatusCode() != 200 /*success*/) {
            LOGGER.warn("Status code " + response.getStatusLine().getStatusCode());
            LOGGER.warn("message is :" + Arrays.deepToString(response.getAllHeaders()));
            LOGGER.warn("result\n" + result);
        }
    } catch (Exception exp) {
        exp.printStackTrace();
    } finally {
        try {
            if (null != inputStream) {
                inputStream.close();
            }
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

From source file:org.bonitasoft.web.designer.controller.PreviewControllerTest.java

@Test
public void should_return_a_fake_css_file_for_living_application_theme() throws Exception {
    String expectedContent = "/**" + System.lineSeparator() + "* Living application theme"
            + System.lineSeparator() + "*/";

    mockMvc.perform(get("/preview/page/theme/theme.css")).andExpect(status().isOk())
            .andExpect(content().string(expectedContent))
            .andExpect(header().string("Content-Disposition", "inline; filename=\"theme.css\""))
            .andExpect(content().encoding("UTF-8"));

}

From source file:io.gravitee.reporter.file.FileReporter.java

private StringBuilder format(Metrics metrics) {
    StringBuilder buf = accessLogBuffer;
    StringBuffer dateBuffer = dateFormatBuffer;
    buf.setLength(0);/*from   w w  w  .  j a v a 2s  .c o  m*/
    dateBuffer.setLength(0);

    // Append request timestamp
    buf.append('[');
    dateFormatter.format(metrics.timestamp().toEpochMilli(), dateBuffer);
    buf.append(dateBuffer);
    buf.append("] ");

    // Append request id
    buf.append(metrics.getRequestId());
    buf.append(" ");

    // Append transaction id
    buf.append(metrics.getTransactionId());
    buf.append(" ");

    // Append local IP
    buf.append('(');
    buf.append(metrics.getLocalAddress());
    buf.append(") ");

    // Append remote IP
    buf.append(metrics.getRemoteAddress());
    buf.append(' ');

    // Append Api name
    String apiName = metrics.getApi();
    if (apiName == null) {
        apiName = NO_STRING_DATA_VALUE;
    }

    buf.append(apiName);
    buf.append(' ');

    // Append security type
    SecurityType securityType = metrics.getSecurityType();
    if (securityType == null) {
        buf.append(NO_STRING_DATA_VALUE);
    } else {
        buf.append(securityType.name());
    }
    buf.append(' ');

    // Append security token
    String securityToken = metrics.getSecurityToken();
    if (securityToken == null) {
        securityToken = NO_STRING_DATA_VALUE;
    }
    buf.append(securityToken);
    buf.append(' ');

    // Append request method and URI
    buf.append(metrics.getHttpMethod());
    buf.append(' ');
    buf.append(metrics.getUri());
    buf.append(' ');

    // Append response status
    int status = metrics.getStatus();
    if (status <= 0) {
        status = 404;
    }
    buf.append((char) ('0' + ((status / 100) % 10)));
    buf.append((char) ('0' + ((status / 10) % 10)));
    buf.append((char) ('0' + (status % 10)));
    buf.append(' ');

    // Append response length
    long responseLength = metrics.getResponseContentLength();
    if (responseLength >= 0) {
        if (responseLength > 99999) {
            buf.append(responseLength);
        } else {
            if (responseLength > 9999)
                buf.append((char) ('0' + ((responseLength / 10000) % 10)));
            if (responseLength > 999)
                buf.append((char) ('0' + ((responseLength / 1000) % 10)));
            if (responseLength > 99)
                buf.append((char) ('0' + ((responseLength / 100) % 10)));
            if (responseLength > 9)
                buf.append((char) ('0' + ((responseLength / 10) % 10)));
            buf.append((char) ('0' + (responseLength) % 10));
        }
    } else {
        buf.append(NO_INTEGER_DATA_VALUE);
    }
    buf.append(' ');

    // Append total response time
    buf.append(metrics.getProxyResponseTimeMs());
    buf.append(' ');

    // Append proxy latency
    buf.append(metrics.getProxyLatencyMs());

    buf.append(System.lineSeparator());

    return buf;
}

From source file:io.cloudslang.content.httpclient.build.auth.AuthSchemeProviderLookupBuilder.java

private static File createLoginConfig() throws IOException {
    File tempFile = File.createTempFile("krb", "loginConf");
    tempFile.deleteOnExit();// ww  w.  j a va  2 s.  c om
    ArrayList<String> lines = new ArrayList<>();
    lines.add("com.sun.security.jgss.initiate {\n" + "  " + KrbHttpLoginModule.class.getCanonicalName()
            + " required\n" + "  doNotPrompt=true\n" + "  useFirstPass=true\n" + "  debug=true ;\n" + "};");
    FileWriter writer = null;
    try {
        writer = new FileWriter(tempFile);
        IOUtils.writeLines(lines, System.lineSeparator(), writer);
    } finally {
        if (writer != null) {
            //                IOUtils.closeQuietly(writer);
            safeClose(writer);
        }
    }
    return tempFile;
}

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

@Test
public void validatePluginInvalidActionTypeVersionFailure() {
    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);//from  w  w w  . j a  va  2 s . com
    thrown.expectMessage("Category: Build");
    thrown.expectMessage("Version:");
    thrown.expectMessage("Provider: Jenkins-Build");

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