From 937d4c61ef58cd3655ee5449b9b823fe16aa9c3d Mon Sep 17 00:00:00 2001
From: ag2s20150909
@@ -105,7 +107,7 @@ public class IOUtil {
result = new ByteArrayOutputStream();
}
- copy(in, result,DEFAULT_BUFFER_SIZE);
+ copy(in, result);
result.flush();
return result.toByteArray();
} catch (OutOfMemoryError error) {
@@ -138,7 +140,15 @@ public class IOUtil {
}
}
-//
+ //
+ public static void copy(InputStream in, OutputStream result) throws IOException {
+ int buffer=in.available();
+ if(buffer>IOUtil.DEFAULT_BUFFER_SIZE||buffer==0){
+ buffer=IOUtil.DEFAULT_BUFFER_SIZE;
+ }
+ copy(in, result,buffer);
+ }
+
/**
* Copies bytes from an
* This method uses {@link InputStreamReader}.
*
- * @param input the
* This method uses {@link InputStreamReader}.
*
- * @param input the
* This method uses {@link InputStreamReader}.
*
- * @param input the
* This method uses {@link OutputStreamWriter}.
*
- * @param input the
* This method uses {@link OutputStreamWriter}.
*
- * @param input the InputStream
to an OutputStream
using an internal buffer of the
* given size.
@@ -146,12 +156,12 @@ public class IOUtil {
* This method buffers the input internally, so there is no need to use a BufferedInputStream
.
* InputStream
to read from
- * @param output the OutputStream
to write to
+ * @param input the InputStream
to read from
+ * @param output the OutputStream
to write to
* @param bufferSize the bufferSize used to copy from the input to the output
* @return the number of bytes copied. or {@code 0} if {@code input is null}.
* @throws NullPointerException if the output is null
- * @throws IOException if an I/O error occurs
+ * @throws IOException if an I/O error occurs
* @since 2.5
*/
public static long copy(final InputStream input, final OutputStream output, final int bufferSize)
@@ -168,7 +178,7 @@ public class IOUtil {
* InputStream
to read from
+ * @param input the InputStream
to read from
* @param output the Writer
to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -190,8 +200,8 @@ public class IOUtil {
* InputStream
to read from
- * @param output the Writer
to write to
+ * @param input the InputStream
to read from
+ * @param output the Writer
to write to
* @param inputCharset the charset to use for the input stream, null means platform default
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -215,8 +225,8 @@ public class IOUtil {
* InputStream
to read from
- * @param output the Writer
to write to
+ * @param input the InputStream
to read from
+ * @param output the Writer
to write to
* @param inputCharsetName the name of the requested charset for the InputStream, null means platform default
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -227,7 +237,7 @@ public class IOUtil {
*/
public static void copy(final InputStream input, final Writer output, final String inputCharsetName)
throws IOException {
- copy(input, output,Charset.forName(inputCharsetName));
+ copy(input, output, Charset.forName(inputCharsetName));
}
/**
@@ -241,7 +251,7 @@ public class IOUtil {
* number of chars cannot be returned as an int. For large streams
* use the copyLarge(Reader, Writer)
method.
*
- * @param input the Reader
to read from
+ * @param input the Reader
to read from
* @param output the Appendable
to write to
* @return the number of characters copied, or -1 if > Integer.MAX_VALUE
* @throws NullPointerException if the input or output is null
@@ -259,7 +269,7 @@ public class IOUtil {
* BufferedReader
.
* Reader
to read from
+ * @param input the Reader
to read from
* @param output the Appendable
to write to
* @param buffer the buffer to be used for the copy
* @return the number of characters copied
@@ -291,7 +301,7 @@ public class IOUtil {
* Reader
to read from
+ * @param input the Reader
to read from
* @param output the OutputStream
to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -320,8 +330,8 @@ public class IOUtil {
* This method uses {@link OutputStreamWriter}.
* Reader
to read from
- * @param output the OutputStream
to write to
+ * @param input the Reader
to read from
+ * @param output the OutputStream
to write to
* @param outputCharset the charset to use for the OutputStream, null means platform default
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -352,8 +362,8 @@ public class IOUtil {
* Reader
to read from
- * @param output the OutputStream
to write to
+ * @param input the Reader
to read from
+ * @param output the OutputStream
to write to
* @param outputCharsetName the name of the requested charset for the OutputStream, null means platform default
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -378,7 +388,7 @@ public class IOUtil {
* number of chars cannot be returned as an int. For large streams
* use the copyLarge(Reader, Writer)
method.
*
- * @param input the Reader
to read from
+ * @param input the Reader
to read from
* @param output the Writer
to write to
* @return the number of characters copied, or -1 if > Integer.MAX_VALUE
* @throws NullPointerException if the input or output is null
@@ -404,11 +414,11 @@ public class IOUtil {
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
* InputStream
to read from
+ * @param input the InputStream
to read from
* @param output the OutputStream
to write to
* @return the number of bytes copied. or {@code 0} if {@code input is null}.
* @throws NullPointerException if the output is null
- * @throws IOException if an I/O error occurs
+ * @throws IOException if an I/O error occurs
* @since 1.3
*/
public static long copyLarge(final InputStream input, final OutputStream output)
@@ -424,7 +434,7 @@ public class IOUtil {
* BufferedInputStream
.
*
InputStream
to read from
+ * @param input the InputStream
to read from
* @param output the OutputStream
to write to
* @param buffer the buffer to use for the copy
* @return the number of bytes copied. or {@code 0} if {@code input is null}.
@@ -458,11 +468,11 @@ public class IOUtil {
*
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
- * @param input the InputStream
to read from
- * @param output the OutputStream
to write to
+ * @param input the InputStream
to read from
+ * @param output the OutputStream
to write to
* @param inputOffset : number of bytes to skip from input before copying
- * -ve values are ignored
- * @param length : number of bytes to copy. -ve means all
+ * -ve values are ignored
+ * @param length : number of bytes to copy. -ve means all
* @return the number of bytes copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -486,12 +496,12 @@ public class IOUtil {
* this is done to guarantee that the correct number of characters are skipped.
*
*
- * @param input the InputStream
to read from
- * @param output the OutputStream
to write to
+ * @param input the InputStream
to read from
+ * @param output the OutputStream
to write to
* @param inputOffset : number of bytes to skip from input before copying
- * -ve values are ignored
- * @param length : number of bytes to copy. -ve means all
- * @param buffer the buffer to use for the copy
+ * -ve values are ignored
+ * @param length : number of bytes to copy. -ve means all
+ * @param buffer the buffer to use for the copy
* @return the number of bytes copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -531,7 +541,7 @@ public class IOUtil {
*
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
- * @param input the Reader
to read from
+ * @param input the Reader
to read from
* @param output the Writer
to write to
* @return the number of characters copied
* @throws NullPointerException if the input or output is null
@@ -549,7 +559,7 @@ public class IOUtil {
* BufferedReader
.
*
*
- * @param input the Reader
to read from
+ * @param input the Reader
to read from
* @param output the Writer
to write to
* @param buffer the buffer to be used for the copy
* @return the number of characters copied
@@ -576,11 +586,11 @@ public class IOUtil {
*
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
- * @param input the Reader
to read from
- * @param output the Writer
to write to
+ * @param input the Reader
to read from
+ * @param output the Writer
to write to
* @param inputOffset : number of chars to skip from input before copying
- * -ve values are ignored
- * @param length : number of chars to copy. -ve means all
+ * -ve values are ignored
+ * @param length : number of chars to copy. -ve means all
* @return the number of chars copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -599,12 +609,12 @@ public class IOUtil {
* BufferedReader
.
*
*
- * @param input the Reader
to read from
- * @param output the Writer
to write to
+ * @param input the Reader
to read from
+ * @param output the Writer
to write to
* @param inputOffset : number of chars to skip from input before copying
- * -ve values are ignored
- * @param length : number of chars to copy. -ve means all
- * @param buffer the buffer to be used for the copy
+ * -ve values are ignored
+ * @param length : number of chars to copy. -ve means all
+ * @param buffer the buffer to be used for the copy
* @return the number of chars copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
@@ -648,7 +658,7 @@ public class IOUtil {
* this is done to guarantee that the correct number of bytes are skipped.
*