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

com.qiniu.util.IOUtils Maven / Gradle / Ivy

There is a newer version: 7.17.0
Show newest version
package com.qiniu.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class IOUtils {

    private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

    private IOUtils() {

    }

    /**
     * 输入InputSteam,返回byte[].
     * 参考: 链接 
* * @param input 输入流 * @return byte 数组 * @throws IOException 异常 */ public static byte[] toByteArray(final InputStream input) throws IOException { try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; int n; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); } return output.toByteArray(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy