common_helper/src/main/java/com/xiongyingqi/util/FileHelper.java
public static byte[] readInputStreamToBytes(InputStream inputStream) throws Exception {
        byte[] data = null;
        try {
            int bufferSize = 128;
            byte[] buffer = new byte[bufferSize];
            int offset = 0;
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            int length = -1;
            while ((length = inputStream.read(buffer)) != -1) {
                // if(length != bufferSize){
                // System.arraycopy(buffer, 0, data, offset, length);
                // }
//                    System.arraycopy(buffer, 0, data, offset, length);// 从缓冲区拷贝数组
                if (offset + length > byteBuffer.limit()) {
                    byteBuffer = growByteBuffer(byteBuffer, (int) (byteBuffer.limit() * 1.5));
                }
                byteBuffer.put(buffer, 0, length);
                offset += length;
            }
            byteBuffer.flip();
//            byteBuffer.limit(offset);
            data = new byte[offset];
            byteBuffer.get(data, 0, offset);
//            data = byteBuffer.array();
        } catch (IOException e) {
            LOGGER.error(e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return data;
    }
public static byte[] readInputStreamToBytes(InputStream inputStream) throws Exception {
        byte[] data = null;
        try {
            int bufferSize = 128;
            byte[] buffer = new byte[bufferSize];
            int offset = 0;
            ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
            int length = -1;
            while ((length = inputStream.read(buffer)) != -1) {
                // if(length != bufferSize){
                // System.arraycopy(buffer, 0, data, offset, length);
                // }
//                    System.arraycopy(buffer, 0, data, offset, length);// 从缓冲区拷贝数组
                if (offset + length > byteBuffer.limit()) {
                    byteBuffer = growByteBuffer(byteBuffer, (int) (byteBuffer.limit() * 1.5));
                }
                byteBuffer.put(buffer, 0, length);
                offset += length;
            }
            byteBuffer.flip();
//            byteBuffer.limit(offset);
            data = new byte[offset];
            byteBuffer.get(data, 0, offset);
//            data = byteBuffer.array();
        } catch (IOException e) {
            LOGGER.error(e);
        } finally {
            try {
                inputStream.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return data;
    }
public static byte [ ] readInputStreamToBytes ( InputStream inputStream ) throws Exception { byte [ ] data = null ; try { int bufferSize = 128 ; byte [ ] buffer = new byte [ bufferSize ] ; int offset = 0 ; ByteBuffer byteBuffer = ByteBuffer . allocate ( 1024 ) ; int length = - 1 ; while ( ( length = inputStream . read ( buffer ) ) != - 1 ) { // if(length != bufferSize){ // System.arraycopy(buffer, 0, data, offset, length); // } //                    System.arraycopy(buffer, 0, data, offset, length);// 从缓冲区拷贝数组 if ( offset + length > byteBuffer . limit ( ) ) { byteBuffer = growByteBuffer ( byteBuffer , ( int ) ( byteBuffer . limit ( ) * 1.5 ) ) ; } byteBuffer . put ( buffer , 0 , length ) ; offset += length ; } byteBuffer . flip ( ) ; //            byteBuffer.limit(offset); data = new byte [ offset ] ; byteBuffer . get ( data , 0 , offset ) ; //            data = byteBuffer.array(); } catch ( IOException e ) { LOGGER . error ( e ) ; } finally { try { inputStream . close ( ) ; } catch ( IOException e1 ) { e1 . printStackTrace ( ) ; } } return data ; }
读取inputStream并返回字节数组 <br>
2013-9-3 下午12:10:06

@param inputStream
@return
读取inputStream并返回字节数组 <br > 2013 - 9 - 3 下午12 : 10 : 06