List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining()
From source file:com.bosch.cr.examples.jwt.auth.ImAuthenticationServlet.java
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try {//w w w . j a v a 2 s .c o m final String body = req.getReader().lines().collect(Collectors.joining()); final JsonObject jsonObject = JsonFactory.newObject(body); final String tenantNameOrId = jsonObject.getValue(TENANT_NAME_OR_ID).map(JsonValue::asString) .orElse(configurationProperties.getPropertyAsString(ConfigurationProperty.IM_DEFAULT_TENANT)); final String userName = jsonObject.getValue(USERNAME).map(JsonValue::asString) .orElseThrow(() -> new JsonMissingFieldException(USERNAME.getPointer())); final String password = jsonObject.getValue(PASSWORD).map(JsonValue::asString) .orElseThrow(() -> new JsonMissingFieldException(PASSWORD.getPointer())); final AuthenticationDto authenticationDto = authenticationHelper.authenticate(tenantNameOrId, userName, password); final AuthorizationDto authorizationDto = authenticationHelper.authorize(authenticationDto); final String authorizationToken = authorizationDto.getAuthorizationToken(); final boolean secure = configurationProperties .getPropertyAsBoolean(ConfigurationProperty.SECURE_COOKIE); final int maxAge = -1; // cookie is deleted when browser is closed final Cookie cookie = CookieUtil.getJwtAuthenticationCookie(authorizationToken, secure, maxAge); resp.addCookie(cookie); resp.setStatus(HttpStatus.SC_NO_CONTENT); } catch (final IOException e) { resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } catch (final JsonMissingFieldException e) { resp.setStatus(HttpStatus.SC_BAD_REQUEST); resp.getOutputStream().print(e.getMessage()); } catch (final AuthenticationDeniedException e) { resp.setStatus(HttpStatus.SC_UNAUTHORIZED); resp.getOutputStream().print(e.getMessage()); } }
From source file:beast.math.NumberFormatter.java
private DecimalFormat getScientificFormat() { final String format = "0." + IntStream.rangeClosed(0, sf - 1).mapToObj(i -> "#").collect(Collectors.joining()) + "E0"; return new DecimalFormat(format); }
From source file:dk.dma.msiproxy.common.provider.AbstractProviderService.java
/** * Computes an ETag token for the given message list * @param format the format to return the messages in * @param filter the message filter/*from w w w.ja v a2 s. c o m*/ * @param messages the list of messages to compute an ETag token for * @return an ETag token for the given message list */ public String getETagToken(String format, MessageFilter filter, List<Message> messages) { return DigestUtils.md5Hex(String.format("%s_%s_%s", StringUtils.defaultString(format), messages.stream() .map(msg -> msg.getId().toString() + msg.getUpdated().getTime()).collect(Collectors.joining()), getCacheKey(filter))); }
From source file:com.orange.ngsi2.server.Ngsi2BaseControllerTest.java
@Test public void checkListTypeInvalidSyntax() throws Exception { String p257times = IntStream.range(0, 257).mapToObj(x -> "p").collect(Collectors.joining()); String message = "The incoming request is invalid in this context. " + p257times + " has a bad syntax."; mockMvc.perform(get("/v2/i/entities").param("type", p257times).contentType(MediaType.APPLICATION_JSON) .header("Host", "localhost").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$.error").value("400")) .andExpect(MockMvcResultMatchers.jsonPath("$.description").value(message)) .andExpect(status().isBadRequest()); }
From source file:com.orange.ngsi2.server.Ngsi2BaseControllerTest.java
@Test public void checkListAttrsInvalidSyntax() throws Exception { String invalidAttrs = IntStream.range(0, 257).mapToObj(x -> "?").collect(Collectors.joining()); String message = "The incoming request is invalid in this context. " + invalidAttrs + " has a bad syntax."; mockMvc.perform(get("/v2/i/entities").param("attrs", invalidAttrs).contentType(MediaType.APPLICATION_JSON) .header("Host", "localhost").accept(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$.error").value("400")) .andExpect(MockMvcResultMatchers.jsonPath("$.description").value(message)) .andExpect(status().isBadRequest()); }
From source file:sx.blah.discord.api.internal.DiscordWS.java
@Override public void onWebSocketBinary(byte[] payload, int offset, int len) { BufferedReader reader = new BufferedReader( new InputStreamReader(new InflaterInputStream(new ByteArrayInputStream(payload, offset, len)))); onWebSocketText(reader.lines().collect(Collectors.joining())); try {// www . ja v a2 s.c o m reader.close(); } catch (IOException e) { Discord4J.LOGGER.error(LogMarkers.WEBSOCKET, "Encountered websocket error: ", e); } }
From source file:com.formkiq.core.form.service.FormValidatorServiceImpl.java
/** * Validate Form JSON Field.//w ww . j av a2 s.c o m * * @param archive {@link ArchiveDTO} * @param form {@link FormJSON} * @param field {@link FormJSONField} * @param errors {@link Map} * @param types {@link FormJSONRequiredType} */ private void validateFormJSONField(final ArchiveDTO archive, final FormJSON form, final FormJSONField field, final Map<String, String> errors, final FormJSONRequiredType... types) { if (!field.isHide() && !BUTTON.equals(field.getType())) { boolean isRequired = isRequired(field, types); String value = Objects.toString(field.getValue(), ""); List<String> values = field.getValues(); if (!hasText(value) && !isEmpty(values)) { value = values.stream().collect(Collectors.joining()); } if (isRequired) { if (StringUtils.isEmpty(value)) { errors.put(String.valueOf(field.getId()), "Field required"); } } validateFieldCustomFormatter(form, field, value, errors); validateFieldFormula(form, field, errors); if (isRequired || hasText(value)) { validateFieldVariable(archive, form, field, value, errors); } } }
From source file:jp.co.opentone.bsol.linkbinder.service.correspon.impl.CorresponFullTextSearchServiceImpl.java
private void handleResponse(ElasticsearchSearchResponse response, SearchFullTextSearchCorresponCondition condition, Consumer<FullTextSearchCorresponsResult> consumer) { response.records().forEach(rec -> { FullTextSearchCorresponsResult r = new FullTextSearchCorresponsResult(); r.setId(idToLong(rec.getId()));/*from w w w . j a v a2s. co m*/ if (rec.getHighlightedFragments("title").count() > 0) { r.setTitle(rec.getHighlightedFragments("title").collect(Collectors.joining())); } else { r.setTitle(rec.getValueAsString("title")); } r.setMdate(rec.getValueAsString("lastModified")); r.setWorkflowStatus(rec.getValueAsString("workflowStatus")); Stream<Map<String, Object>> s = rec.getValueAsStream("attachments"); if (s != null) { s.forEach(a -> { r.setTitle(ObjectUtils.toString(a.get("name"))); r.setAttachmentId(ObjectUtils.toString(a.get("id"))); }); } setSummaryData(condition, rec, r); consumer.accept(r); }); }
From source file:cognitivej.vision.emotion.EmotionStringBuilder.java
/** * Returns the most dominate emotion and the score for that emotion * * @param emotion - the emotion// ww w . j a va2 s. c om * @return Tile-cased dominant emotion (e.g. Fear) */ @NotNull public static String listAllEmotions(@NotNull Emotion emotion) { return emotion.scores.scores().entrySet().stream() .map((entry1) -> String.format("%s:%.2f\n", entry1.getKey(), entry1.getValue())) .collect(Collectors.joining()); }