Polish StreamUtils
This commit is contained in:
@@ -47,7 +47,7 @@ import org.springframework.lang.Nullable;
|
|||||||
public abstract class StreamUtils {
|
public abstract class StreamUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default buffer size used why copying bytes.
|
* The default buffer size used when copying bytes.
|
||||||
*/
|
*/
|
||||||
public static final int BUFFER_SIZE = 4096;
|
public static final int BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of the given InputStream into a new byte array.
|
* Copy the contents of the given InputStream into a new byte array.
|
||||||
* Leaves the stream open when done.
|
* <p>Leaves the stream open when done.
|
||||||
* @param in the stream to copy from (may be {@code null} or empty)
|
* @param in the stream to copy from (may be {@code null} or empty)
|
||||||
* @return the new byte array that has been copied to (possibly empty)
|
* @return the new byte array that has been copied to (possibly empty)
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
@@ -73,8 +73,9 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of the given InputStream into a String.
|
* Copy the contents of the given InputStream into a String.
|
||||||
* Leaves the stream open when done.
|
* <p>Leaves the stream open when done.
|
||||||
* @param in the InputStream to copy from (may be {@code null} or empty)
|
* @param in the InputStream to copy from (may be {@code null} or empty)
|
||||||
|
* @param charset the {@link Charset} to use to decode the bytes
|
||||||
* @return the String that has been copied to (possibly empty)
|
* @return the String that has been copied to (possibly empty)
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
*/
|
*/
|
||||||
@@ -116,7 +117,7 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of the given byte array to the given OutputStream.
|
* Copy the contents of the given byte array to the given OutputStream.
|
||||||
* Leaves the stream open when done.
|
* <p>Leaves the stream open when done.
|
||||||
* @param in the byte array to copy from
|
* @param in the byte array to copy from
|
||||||
* @param out the OutputStream to copy to
|
* @param out the OutputStream to copy to
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
@@ -130,7 +131,7 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of the given String to the given output OutputStream.
|
* Copy the contents of the given String to the given output OutputStream.
|
||||||
* Leaves the stream open when done.
|
* <p>Leaves the stream open when done.
|
||||||
* @param in the String to copy from
|
* @param in the String to copy from
|
||||||
* @param charset the Charset
|
* @param charset the Charset
|
||||||
* @param out the OutputStream to copy to
|
* @param out the OutputStream to copy to
|
||||||
@@ -138,7 +139,7 @@ public abstract class StreamUtils {
|
|||||||
*/
|
*/
|
||||||
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
|
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
|
||||||
Assert.notNull(in, "No input String specified");
|
Assert.notNull(in, "No input String specified");
|
||||||
Assert.notNull(charset, "No charset specified");
|
Assert.notNull(charset, "No Charset specified");
|
||||||
Assert.notNull(out, "No OutputStream specified");
|
Assert.notNull(out, "No OutputStream specified");
|
||||||
|
|
||||||
Writer writer = new OutputStreamWriter(out, charset);
|
Writer writer = new OutputStreamWriter(out, charset);
|
||||||
@@ -148,7 +149,7 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of the given InputStream to the given OutputStream.
|
* Copy the contents of the given InputStream to the given OutputStream.
|
||||||
* Leaves both streams open when done.
|
* <p>Leaves both streams open when done.
|
||||||
* @param in the InputStream to copy from
|
* @param in the InputStream to copy from
|
||||||
* @param out the OutputStream to copy to
|
* @param out the OutputStream to copy to
|
||||||
* @return the number of bytes copied
|
* @return the number of bytes copied
|
||||||
@@ -212,7 +213,7 @@ public abstract class StreamUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Drain the remaining content of the given InputStream.
|
* Drain the remaining content of the given InputStream.
|
||||||
* Leaves the InputStream open when done.
|
* <p>Leaves the InputStream open when done.
|
||||||
* @param in the InputStream to drain
|
* @param in the InputStream to drain
|
||||||
* @return the number of bytes read
|
* @return the number of bytes read
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
|
|||||||
Reference in New Issue
Block a user