X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2FStreamUtils.java;fp=org.argeo.util%2Fsrc%2Forg%2Fargeo%2Futil%2FStreamUtils.java;h=30404f1e4edc195b9270488b1b0ed41eb7056187;hb=f3ea14abccc33b1c3326417a87c91145be776c72;hp=6d7d940ceaf74ea3b9dd60682688cb918ef6c9ff;hpb=2752f591462f846423020ef1c1989766b20cd554;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.util/src/org/argeo/util/StreamUtils.java b/org.argeo.util/src/org/argeo/util/StreamUtils.java index 6d7d940ce..30404f1e4 100644 --- a/org.argeo.util/src/org/argeo/util/StreamUtils.java +++ b/org.argeo.util/src/org/argeo/util/StreamUtils.java @@ -1,13 +1,15 @@ package org.argeo.util; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; +import java.util.StringJoiner; -/** Utilities to be used when Apache Commons IO is not available. */ -class StreamUtils { +/** Stream utilities to be used when Apache Commons IO is not available. */ +public class StreamUtils { private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; /* @@ -15,8 +17,7 @@ class StreamUtils { */ /** @return the number of bytes */ - public static Long copy(InputStream in, OutputStream out) - throws IOException { + public static Long copy(InputStream in, OutputStream out) throws IOException { Long count = 0l; byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; while (true) { @@ -78,4 +79,12 @@ class StreamUtils { // } } + + public static String toString(BufferedReader reader) throws IOException { + StringJoiner sn = new StringJoiner("\n"); + String line = null; + while ((line = reader.readLine()) != null) + sn.add(line); + return sn.toString(); + } }