cn.zcltd.btg.sutil.IOUtil Maven / Gradle / Ivy
package cn.zcltd.btg.sutil;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/**
* util:io
*/
public final class IOUtil {
/**
* 将InputStream读取为byte[]
*
* @param inputStream 输入流
* @return byte[]
*/
public static byte[] read(InputStream inputStream) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int rc;
while ((rc = inputStream.read(buff)) != -1) {
byteArrayOutputStream.write(buff, 0, rc);
}
return byteArrayOutputStream.toByteArray();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}