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

devutility.internal.io.StreamUtils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
package devutility.internal.io;

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

/**
 * 
 * StreamUtils
 * 
 * @author: Aldwin Su
 */
public class StreamUtils {
	/**
	 * Read bytes array from InputStream object.
	 * @param inputStream InputStream object.
	 * @return byte[]
	 */
	public static byte[] read(InputStream inputStream) {
		int index = 0;
		byte[] bytes = new byte[1024];

		try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
			while ((index = inputStream.read(bytes, 0, bytes.length)) > 0) {
				byteArrayOutputStream.write(bytes, 0, index);
			}

			return byteArrayOutputStream.toByteArray();
		} catch (Exception e) {
			System.out.println(e.toString());
			return null;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy