package org.codinjutsu.tools.jenkins.util;
import java.io.*;
/**
* Extracted from commons-io (because of bloated size in compare to whole plugin)
* maybe should somehow use streamlined jar?
*/
public class IOUtils {
public static String toString(InputStream input) throws IOException {
StringWriter sw = new StringWriter();
copy(input, sw);
return sw.toString();
}
public static String toString(InputStream input, String encoding) throws IOException {
StringWriter sw = new StringWriter();
copy(input, sw, encoding);
return sw.toString();
}
public static void copy(InputStream input, Writer output, String encoding) throws IOException {
if(encoding == null) {
copy(input, output);
} else {
InputStreamReader in = new InputStreamReader(input, encoding);
copy(in, output);
}
}
public static void copy(InputStream input, Writer output) throws IOException {
InputStreamReader in = new InputStreamReader(input);
copy(in, output);
}
public static int copy(Reader input, Writer output) throws IOException {
long count = copyLarge(input, output);
return count > 2147483647L?-1:(int)count;
}
public static long copyLarge(Reader input, Writer output) throws IOException {
char[] buffer = new char[4096];
long count = 0L;
int n1;
for(; -1 != (n1 = input.read(buffer)); count += (long)n1) {
output.write(buffer, 0, n1);
}
return count;
}
}