All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.zcltd.btg.sutil.IOUtil Maven / Gradle / Ivy

There is a newer version: 4.0.24
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy