Example usage for java.util.stream Collectors joining

List of usage examples for java.util.stream Collectors joining

Introduction

In this page you can find the example usage for java.util.stream Collectors joining.

Prototype

public static Collector<CharSequence, ?, String> joining() 

Source Link

Document

Returns a Collector that concatenates the input elements into a String , in encounter order.

Usage

From source file:net.dv8tion.jda.core.requests.Response.java

protected Response(final okhttp3.Response response, final int code, final String message, final long retryAfter,
        final Set<String> cfRays) {
    this.rawResponse = response;
    this.code = code;
    this.message = message;
    this.exception = null;
    this.retryAfter = retryAfter;
    this.cfRays = cfRays;

    if (response == null || response.body().contentLength() == 0) {
        this.object = null;
        return;//from   w  w w  . j  a  v a  2 s .  com
    }

    InputStream body = null;
    BufferedReader reader = null;
    try {
        body = Requester.getBody(response);
        // this doesn't add overhead as org.json would do that itself otherwise
        reader = new BufferedReader(new InputStreamReader(body));
        char begin; // not sure if I really like this... but we somehow have to get if this is an object or an array
        int mark = 1;
        do {
            reader.mark(mark++);
            begin = (char) reader.read();
        } while (Character.isWhitespace(begin));

        reader.reset();

        if (begin == '{')
            this.object = new JSONObject(new JSONTokener(reader));
        else if (begin == '[')
            this.object = new JSONArray(new JSONTokener(reader));
        else
            this.object = reader.lines().collect(Collectors.joining());
    } catch (final Exception e) {
        throw new RuntimeException("An error occurred while parsing the response for a RestAction", e);
    } finally {
        try {
            body.close();
            reader.close();
        } catch (NullPointerException | IOException ignored) {
        }
    }
}

From source file:eu.stamp_project.automaticbuilder.MavenAutomaticBuilder.java

@Override
public void compile() {
    this.runGoals(this.configuration.getAbsolutePathToProjectRoot(), "clean", "test", "-DskipTests",
            "dependency:build-classpath", "-Dmdep.outputFile=" + "target/dspot/classpath");
    final File classpathFile = new File(
            this.configuration.getAbsolutePathToProjectRoot() + "/target/dspot/classpath");
    try (BufferedReader buffer = new BufferedReader(new FileReader(classpathFile))) {
        this.classpath = buffer.lines().collect(Collectors.joining());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }/*from   w  w  w . j ava2 s.  co  m*/
}

From source file:controllers.Index.java

static void createEmptyIndex(final Client aClient, final String aIndexName, final String aPathToIndexSettings)
        throws IOException {
    deleteIndex(aClient, aIndexName);/*from   w ww.  ja v  a2 s.  c  o  m*/
    CreateIndexRequestBuilder cirb = aClient.admin().indices().prepareCreate(aIndexName);
    if (aPathToIndexSettings != null) {
        String settingsMappings = Files.lines(Paths.get(aPathToIndexSettings)).collect(Collectors.joining());
        cirb.setSource(settingsMappings);
    }
    cirb.execute().actionGet();
    aClient.admin().indices().refresh(new RefreshRequest()).actionGet();
}

From source file:com.salesforce.dva.argus.service.callback.DefaultCallbackService.java

@Override
public HttpResponse sendNotification(DefaultAlertService.NotificationContext context) {
    String subscription = context.getNotification().getSubscriptions().stream().collect(Collectors.joining());
    try {/*from w  ww. j a  va2s. com*/
        Request request = _mapper.readValue(subscription, Request.class);
        return sendNotification(buildRequest(context, request));
    } catch (IOException e) {
        return errorResponse("illegal subscription format", e);
    }
}

From source file:alfio.manager.EventNameManager.java

private Optional<String> getCroppedName(String cleanDisplayName) {
    String candidate = Arrays.stream(cleanDisplayName.split(SPACES_AND_PUNCTUATION))
            .map(w -> Pair.of(NUMBER_MATCHER.matcher(w).matches(), w))
            .map(p -> p.getKey() ? p.getValue() : StringUtils.left(p.getValue(), 1))
            .collect(Collectors.joining());
    if (isUnique(candidate)) {
        return Optional.of(candidate);
    }//www.  j a  v  a2  s  . c om
    return Optional.empty();
}

From source file:eu.stamp_project.automaticbuilder.MavenAutomaticBuilder.java

@Override
public String buildClasspath() {
    if (this.classpath == null) {
        try {/*ww w  .ja  va  2s  .c o  m*/
            final File classpathFile = new File(
                    this.configuration.getAbsolutePathToProjectRoot() + "/target/dspot/classpath");
            if (!classpathFile.exists()) {
                this.runGoals(this.configuration.getAbsolutePathToProjectRoot(), "dependency:build-classpath",
                        "-Dmdep.outputFile=" + "target/dspot/classpath");
            }
            try (BufferedReader buffer = new BufferedReader(new FileReader(classpathFile))) {
                this.classpath = buffer.lines().collect(Collectors.joining());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return this.classpath;
}

From source file:de.bund.bfr.knime.gis.GisUtils.java

public static CoordinateReferenceSystem getCoordinateSystem(String shpFile)
        throws InvalidPathException, MalformedURLException, IOException, FactoryException, NoSuchFileException {
    try (Stream<String> stream = Files
            .lines(KnimeUtils.getFile(FilenameUtils.removeExtension(shpFile) + ".prj").toPath())) {
        return CRS.parseWKT(stream.collect(Collectors.joining()));
    }//  ww w. j  a  va2s.  co m
}

From source file:com.nestedbird.modules.sitemap.SitemapGenerator.java

private String retrieveEntityXML() {
    final Stream<String> songStream = songRepository.findAll().stream().filter(AuditedEntity::getActive)
            .map(this::generateEntity);

    final Stream<String> mediumStream = mediumRepository.findAll().stream().filter(AuditedEntity::getActive)
            .map(this::generateEntity);

    final Stream<String> eventStream = eventRepository.findAll().stream().filter(AuditedEntity::getActive)
            .filter(Event::isInFuture).map(this::generateEntity);

    final Stream<String> locationStream = locationRepository.findAll().stream().filter(AuditedEntity::getActive)
            .map(this::generateEntity);

    final Stream<String> artistStream = artistRepository.findAll().stream().filter(AuditedEntity::getActive)
            .map(this::generateEntity);

    return concatStreams(extraEntities(), songStream, mediumStream, eventStream, locationStream, artistStream)
            .collect(Collectors.joining());
}

From source file:com.demonwav.mcdev.creator.LiteLoaderProjectSettingsWizard.java

public LiteLoaderProjectSettingsWizard(@NotNull MinecraftProjectCreator creator) {
    this.creator = creator;

    mcpWarning.setVisible(false);/*from w w w .  java2 s .  c  o m*/

    minecraftVersionBox.addActionListener(e -> {
        if (mcpVersion != null) {
            mcpVersion.setMcpVersion(mcpVersionBox, (String) minecraftVersionBox.getSelectedItem(),
                    mcpBoxActionListener);
        }
    });

    pluginNameField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            if (mainClassModified) {
                return;
            }

            String[] words = pluginNameField.getText().split("\\s+");
            String word = Arrays.stream(words).map(WordUtils::capitalize).collect(Collectors.joining());

            String[] mainClassWords = mainClassField.getText().split("\\.");
            mainClassWords[mainClassWords.length - 1] = LITEMOD + word;

            mainClassField.getDocument().removeDocumentListener(listener);
            mainClassField.setText(Arrays.stream(mainClassWords).collect(Collectors.joining(".")));
            mainClassField.getDocument().addDocumentListener(listener);
        }
    });

    mainClassField.getDocument().addDocumentListener(listener);

    try {
        new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                mcpVersion = McpVersion.downloadData();
                return null;
            }

            @Override
            protected void done() {
                if (mcpVersion == null) {
                    return;
                }

                minecraftVersionBox.removeAllItems();

                mcpVersion.getVersions().forEach(minecraftVersionBox::addItem);
                // Always select most recent
                minecraftVersionBox.setSelectedIndex(0);

                if (mcpVersion != null) {
                    mcpVersion.setMcpVersion(mcpVersionBox, (String) minecraftVersionBox.getSelectedItem(),
                            mcpBoxActionListener);
                }

                loadingBar.setIndeterminate(false);
                loadingBar.setVisible(false);
            }
        }.execute();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.breadmoirai.samurai.plugins.groovyval.GroovyvalPlugin.java

private void initializeFunctions() {
    final InputStream resourceAsStream = GroovyvalPlugin.class.getResourceAsStream("functions.txt");
    if (resourceAsStream != null) {
        try (BufferedReader br = new BufferedReader(
                new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8))) {
            functions.addAll(Arrays.asList(br.lines().collect(Collectors.joining()).split("(?:});\n\n")));
        } catch (IOException e) {
            e.printStackTrace();//from  w  w w  .j  av a  2  s .c  om
        }
    }
}