Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { private static byte[] getSizeData(InputStream is) { ByteArrayOutputStream byteBuffer; try { byteBuffer = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { byteBuffer.write(buffer, 0, len); } return byteBuffer.toByteArray(); } catch (Exception e) { return new byte[] {}; } } }