List of usage examples for java.util.stream Collectors joining
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter)
From source file:com.diffplug.gradle.GradleIntegrationTest.java
protected void write(String path, String... lines) throws IOException { String content = Arrays.asList(lines).stream().collect(Collectors.joining("\n")) + "\n"; Path target = folder.getRoot().toPath().resolve(path); Files.createDirectories(target.getParent()); Files.write(target, content.getBytes(StandardCharsets.UTF_8)); }
From source file:io.github.binout.jaxrs.csv.CsvSchemaFactoryTest.java
static String inputStreamToString(InputStream is) throws IOException { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { return br.lines().collect(Collectors.joining(System.lineSeparator())); }//from ww w. ja v a 2 s.c om }
From source file:com.simiacryptus.util.lang.CodeUtil.java
/** * Find file file.//from ww w .j a v a 2 s . c om * * @param callingFrame the calling frame * @return the file */ @javax.annotation.Nonnull public static File findFile(@javax.annotation.Nonnull final StackTraceElement callingFrame) { @javax.annotation.Nonnull final String[] packagePath = callingFrame.getClassName().split("\\."); @javax.annotation.Nonnull final String path = Arrays.stream(packagePath).limit(packagePath.length - 1) .collect(Collectors.joining(File.separator)) + File.separator + callingFrame.getFileName(); return com.simiacryptus.util.lang.CodeUtil.findFile(path); }
From source file:edu.emory.bmi.datacafe.core.DataCafeUtil.java
/** * Construct a string from a collection//from ww w .j ava 2s. c o m * * @param collection the collection * @return the collection as a comma separated line */ public static String constructStringFromCollection(Collection collection) { // This line of code is genius (despite looking ugly). // Future maintainer: Be careful if you are trying to refactor it. return (String) collection.stream().map(i -> doublequote(doubleTheDoubleQuote(i.toString()))) .collect(Collectors.joining(",")); }
From source file:org.flywaydb.core.internal.util.plus.MysqlToH2ConverterTests.java
/** * Read file in class path/* w w w . ja v a 2 s . com*/ * * @param path path * @param joiner joiner * @return string in file */ private String readFileInClassPath(String path, String joiner) { try { return Files.lines(Paths.get(new ClassPathResource(path).getURI()), StandardCharsets.UTF_8) .collect(Collectors.joining(joiner)); } catch (IOException e) { throw new IllegalStateException("Failed to read file", e); } }
From source file:org.trustedanalytics.routermetrics.gathering.adapters.gorouter.GorouterMetrics.java
@Override public String toString() { String latencyToString = latency.entrySet().stream() .map(x -> String.format("'%s'='%s'", x.getKey(), x.getValue())).collect(Collectors.joining(", ")); return "GorouterMetrics{" + "host='" + host + "'," + "requestPerSec=" + requestPerSec + ", latency={" + latencyToString + "}" + "}"; }
From source file:io.syndesis.model.filter.RuleFilterStep.java
/** * Filter in the simple expression language. *///from w ww . ja v a2 s . c o m default String getFilterExpression() { final Map<String, String> props = getConfiguredProperties(); if (!props.isEmpty()) { FilterPredicate predicate = getPredicate(props.get("predicate")); List<FilterRule> rules = extractRules(props.get("rules")); if (rules != null && !rules.isEmpty()) { return rules.stream().map(FilterRule::getFilterExpression) .collect(Collectors.joining(predicate.getExpressionDelimiter())); } throw new IllegalStateException( String.format("No rules defined in step properties %s for rule filter step", props)); } throw new IllegalStateException("No step properties defined for rule filter step"); }
From source file:org.flywaydb.core.internal.util.XMysqlToH2SqlReplacerTests.java
/** * Read class path file/*from ww w . java 2s. c om*/ * * @param path path * @param joiner joiner * @return string in file */ private String readClassPathFile(String path, String joiner) { try { return Files.lines(Paths.get(new ClassPathResource(path).getURI()), StandardCharsets.UTF_8) .collect(Collectors.joining(joiner)); } catch (IOException e) { throw new IllegalStateException("Failed to read class path file", e); } }
From source file:com.heliosdecompiler.helios.controller.ProcessController.java
public Process launchProcess(ProcessBuilder launch) throws IOException { Process process = launch.start(); try {/*from w w w . j a v a 2 s .co m*/ lock.lock(); processes.add(process); } finally { lock.unlock(); } backgroundTaskHelper.submit(new BackgroundTask( Message.TASK_LAUNCH_PROCESS.format(launch.command().stream().collect(Collectors.joining(" "))), true, () -> { try { process.waitFor(); if (!process.isAlive()) { processes.remove(process); } } catch (InterruptedException ignored) { } }, () -> { process.destroyForcibly(); try { lock.lock(); processes.remove(process); } finally { lock.unlock(); } })); return process; }
From source file:io.schultz.dustin.service.VideoDownloaderService.java
public void download(final URL url, final OutputStream outputStream) { final String filename = downloaderProperties.getDownloadDir() + File.separator + "video-" + new Date().getTime() + ".mp4"; List<String> cmd = new ArrayList<>(); cmd.add(downloaderProperties.getDownloaderAbsolutePath()); cmd.add(url.toString());//from w ww . j a v a 2 s.c o m cmd.add("-f mp4"); cmd.add("-o" + filename); if (log.isDebugEnabled()) { log.debug("Running command: {}", cmd.stream().collect(Collectors.joining(" "))); } try { Process p = new ProcessBuilder().command(cmd).start(); int c; while ((c = p.getInputStream().read()) != -1) { outputStream.write(c); outputStream.flush(); } } catch (IOException e) { log.error("Unable to download video at {}", url, e); } }