public class IOUtil {
public static ByteArrayOutputStream parse(InputStream inputStream) throws IOException {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
int ch;
while ((ch = inputStream.read()) != -1) {
swapStream.write(ch);
}
return swapStream;
}
public static ByteArrayInputStream parse(OutputStream out) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
return swapStream;
}
public static void close(InputStream in) {
if (null != in) {
try {
in.close();
} catch (IOException e) {
log.error("close inputStream error", e);
}
}
}
public static void close(Reader reader) {
if (null != reader) {
try {
reader.close();
} catch (IOException e) {
log.error("close reader error", e);
}
}
}
public static void close(OutputStream out) {
if (null != out) {
try {
out.close();
} catch (IOException e) {
log.error("close OutputStream error", e);
}
}
}
public static void close(Writer writer) {
if (null != writer) {
try {
writer.close();
} catch (IOException e) {
log.error("close writer error", e);
}
}
}
}