List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:com.ethercamp.harmony.service.wallet.FileSystemWalletStore.java
public List<WalletAddressItem> fromStore() { final ObjectMapper mapper = new ObjectMapper(); try {//from ww w .j ava 2s . c o m final File file = getKeyStoreLocation().resolve(FILE_NAME).toFile(); final String content = Files.readAllLines(file.toPath()).stream().collect(Collectors.joining("")); return mapper.readValue(content, new TypeReference<List<WalletAddressItem>>() { }); } catch (NoSuchFileException e) { return Collections.EMPTY_LIST; } catch (IOException e) { throw new RuntimeException("Problem loading data. Message: " + e.getMessage(), e); } }
From source file:ru.xxlabaza.aspect.MyAspect.java
@Around("bean(*Controller)") public Object around(ProceedingJoinPoint joinPoint) throws Throwable { String methodName = ((MethodSignature) joinPoint.getSignature()).getMethod().getName(); String arguments = Stream.of(joinPoint.getArgs()).map(Object::toString).collect(Collectors.joining(", ")); log.info("\n\tAROUND ->\n" + "\tMethod name: {}\n" + "\tArguments: {}", methodName, arguments); return joinPoint.proceed(); }
From source file:co.runrightfast.vertx.orientdb.config.OServerSideScriptInterpreterConfig.java
@Override public OServerHandlerConfiguration get() { final OServerHandlerConfiguration config = new OServerHandlerConfiguration(); config.clazz = OServerSideScriptInterpreter.class.getName(); config.parameters = new OServerParameterConfiguration[] { new OServerParameterConfiguration("enabled", Boolean.toString(enabled)), new OServerParameterConfiguration("allowedLanguages", allowedLanguages.stream().collect(Collectors.joining(","))) }; return config; }
From source file:com.epam.reportportal.extension.bugtracking.tfs.DescriptionBuilder.java
@Override public String build(WorkItem workItem, InternalTicket ticket, Collection<String> values) { Map<String, Object> templateContext = new HashMap<>(); /* What is description? */ templateContext.put("description", values.stream().collect(Collectors.joining("<br>"))); if ((null != ticket.getComments()) && (!ticket.getComments().trim().isEmpty())) { templateContext.put("comments", ticket.getComments()); }/*from www . j a va 2 s. c om*/ if (null != ticket.getBackLinks()) { templateContext.put("backLinks", ticket.getBackLinks()); } if (null != ticket.getLogs()) { /* Order of log items is important */ List<HtmlLogEntry> logData = new LinkedList<>(); for (InternalTicket.LogEntry log : ticket.getLogs()) { String attachmentUrl = null; if (null != log.getAttachment()) { Attachment attachment = new AttachmentImpl(createFile(log), log.getLog().getLogMsg()); workItem.getAttachments().add(attachment); /* need to save to obtain attachment URL */ TfsUtils.saveWorkItem(workItem); attachmentUrl = attachment.getURL().toString(); } String message = log.getIncludeLogs() ? log.getLog().getLogMsg() : ""; String screen = Strings.isNullOrEmpty(attachmentUrl) ? null : attachmentUrl; boolean isLogs = log.getIncludeLogs(); HtmlLogEntry entry = new HtmlLogEntry(message, screen, isLogs); logData.add(entry); } templateContext.put("logs", logData); } return templateEngine.merge(TFS_BUG_TEMPLATE_PATH, templateContext); }
From source file:cn.edu.zjnu.acm.judge.core.Judger.java
private static String collectLines(Path path) throws IOException { Charset charset = Platform.getCharset(); String compileInfo;/* w w w. j a v a2 s . c o m*/ try (InputStream is = Files.newInputStream(path); InputStreamReader isr = new InputStreamReader(is, charset); BufferedReader br = new BufferedReader(isr)) { compileInfo = br.lines().collect(Collectors.joining("\n")); } return compileInfo.length() > 1000 ? compileInfo.substring(0, 997) + "..." : compileInfo; }
From source file:com.ikanow.aleph2.data_model.utils.ProcessUtils.java
/** * Starts the given process by calling process_builder.start(); * Records the started processes pid and start date. * /* w ww . j av a2s. c o m*/ * @param process_builder * @throws IOException * @return returns any error in _1(), the pid in _2() */ public static Tuple2<String, String> launchProcess(final ProcessBuilder process_builder, final String application_name, final DataBucketBean bucket, final String aleph_root_path, final Optional<Tuple2<Long, Integer>> timeout_kill) { try { if (timeout_kill.isPresent()) { final Stream<String> timeout_stream = Stream.of("timeout", "-s", timeout_kill.get()._2.toString(), timeout_kill.get()._1.toString()); process_builder.command(Stream.concat(timeout_stream, process_builder.command().stream()) .collect(Collectors.toList())); } //starts the process, get pid back logger.debug("Starting process: " + process_builder.command().toString()); final Process px = process_builder.start(); String err = null; String pid = null; if (!px.isAlive()) { err = "Unknown error: " + px.exitValue() + ": " + process_builder.command().stream().collect(Collectors.joining(" ")); // (since not capturing output) } else { pid = getPid(px); //get the date on the pid file from /proc/<pid> final long date = getDateOfPid(pid); //record pid=date to aleph_root_path/pid_manager/bucket._id/application_name storePid(application_name, bucket, aleph_root_path, pid, date); } return Tuples._2T(err, pid); } catch (Throwable t) { return Tuples._2T(ErrorUtils.getLongForm("{0}", t), null); } }
From source file:io.pivotal.strepsirrhini.chaoslemur.reporter.DataDogReporter.java
private String message(List<Member> members) { int size = members.size(); String s = "\n"; s += size + English.plural(" VM", size) + " destroyed:\n"; s += members.stream().sorted().map(member -> String.format("%s", member.getName())) .collect(Collectors.joining("\n")); return s;/* w w w.ja v a2 s . c o m*/ }
From source file:example.UserInitializer.java
private static List<User> readUsers(Resource resource) throws Exception { Scanner scanner = new Scanner(resource.getInputStream()); String line = scanner.nextLine(); scanner.close();// ww w . ja v a2 s .co m FlatFileItemReader<User> reader = new FlatFileItemReader<User>(); reader.setResource(resource); DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(); tokenizer.setNames(line.split(",")); tokenizer.setStrict(false); DefaultLineMapper<User> lineMapper = new DefaultLineMapper<User>(); lineMapper.setFieldSetMapper(fields -> { User user = new User(); user.setEmail(fields.readString("email")); user.setFirstname(capitalize(fields.readString("first"))); user.setLastname(capitalize(fields.readString("last"))); user.setNationality(fields.readString("nationality")); String city = Arrays.stream(fields.readString("city").split(" "))// .map(StringUtils::capitalize)// .collect(Collectors.joining(" ")); String street = Arrays.stream(fields.readString("street").split(" "))// .map(StringUtils::capitalize)// .collect(Collectors.joining(" ")); try { user.setAddress(new Address(city, street, fields.readString("zip"))); } catch (IllegalArgumentException e) { user.setAddress(new Address(city, street, fields.readString("postcode"))); } user.setPicture(new Picture(fields.readString("large"), fields.readString("medium"), fields.readString("thumbnail"))); user.setUsername(fields.readString("username")); user.setPassword(fields.readString("password")); return user; }); lineMapper.setLineTokenizer(tokenizer); reader.setLineMapper(lineMapper); reader.setRecordSeparatorPolicy(new DefaultRecordSeparatorPolicy()); reader.setLinesToSkip(1); reader.open(new ExecutionContext()); List<User> users = new ArrayList<>(); User user = null; do { user = reader.read(); if (user != null) { users.add(user); } } while (user != null); return users; }
From source file:grakn.core.util.GraqlTestUtil.java
public static void loadFromFile(String gqlPath, String file, TransactionOLTP tx) { try {//w w w . j a v a 2 s . c o m System.out.println("Loading... " + gqlPath + file); InputStream inputStream = GraqlTestUtil.class.getClassLoader().getResourceAsStream(gqlPath + file); String s = new BufferedReader(new InputStreamReader(inputStream)).lines() .collect(Collectors.joining("\n")); Graql.parseList(s).forEach(tx::execute); } catch (Exception e) { System.err.println(e); throw new RuntimeException(e); } }
From source file:com.javafxpert.wikibrowser.WikiPageController.java
/** * *//*from w ww. j ava 2 s . c o m*/ @RequestMapping("/wikipage") String generateWikiBrowserPage( @RequestParam(value = "name", defaultValue = "Ada_Lovelace") String wikipediaPageName, @RequestParam(value = "lang") String lang) throws Exception { String language = wikiBrowserProperties.computeLang(lang); String mWikipediaBase = String.format(WikiClaimsController.WIKIPEDIA_MOBILE_BASE_TEMPLATE, language); String mWikipedia = String.format(WikiClaimsController.WIKIPEDIA_MOBILE_TEMPLATE, language); String mWikipediaPage = mWikipedia + wikipediaPageName; URL url = new URL(mWikipediaPage); InputStream inputStream = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); String pageText = reader.lines().collect(Collectors.joining("\n")); pageText = pageText.replaceAll("\\\"/w/", "\"" + mWikipediaBase + "w/"); pageText = pageText.replaceAll("\\\"/images/", "\"" + mWikipediaBase + "images/"); pageText = pageText.replaceAll("\\\"/static/", "\"" + mWikipediaBase + "static/"); pageText = pageText.replaceAll("\\\"href\\\":\\\"/w/", "\"href\":\"" + mWikipediaBase + "w/"); pageText = pageText.replaceAll("\\\"href\\\":\\\"/wiki/", "\"href\":\"" + mWikipedia); pageText = pageText.replaceAll("href=\\\"/wiki/", "href=\"" + "/wikipage?lang=" + language + "&name="); pageText = pageText.replaceAll("href=\\\"//", "target=\"_blank\" href=\"//"); pageText = pageText.replaceAll("href=\\\"http", "target=\"_blank\" href=\"http"); // Remove the search menu at the top of the page int searchAnchorStartPos = pageText.indexOf("<a title"); if (searchAnchorStartPos > 0) { int searchAnchorEndPos = pageText.indexOf("</a>", searchAnchorStartPos); if (searchAnchorEndPos > 0) { pageText = pageText.substring(0, searchAnchorStartPos) + pageText.substring(searchAnchorEndPos + "</a>".length()); } } // Remove the search form at the top of the page int searchFormStartPos = pageText.indexOf("<form"); if (searchFormStartPos > 0) { int searchFormEndPos = pageText.indexOf("</form>", searchFormStartPos); if (searchFormEndPos > 0) { pageText = pageText.substring(0, searchFormStartPos) + pageText.substring(searchFormEndPos + "</form>".length()); } } return pageText; }