public static byte[] input( InputStream inputStream ) { try ( InputStream is = inputStream ) { ByteBuf buf = ByteBuf.create( DEFAULT_BUFFER_SIZE ); byte[] bytes = new byte[ DEFAULT_BUFFER_SIZE ]; int read = -2; while ( read != -1 ) { read = inputStream.read( bytes ); if ( read == DEFAULT_BUFFER_SIZE ) { buf.add( bytes ); } else if ( read > 0 ) { buf.add( bytes, read ); } } return buf.toBytes(); } catch ( Exception ex ) { return Exceptions.handle( byte[].class, ex ); } }
public static byte[] input( InputStream inputStream ) { try ( InputStream is = inputStream ) { ByteBuf buf = ByteBuf.create( DEFAULT_BUFFER_SIZE ); byte[] bytes = new byte[ DEFAULT_BUFFER_SIZE ]; int read = -2; while ( read != -1 ) { read = inputStream.read( bytes ); if ( read == DEFAULT_BUFFER_SIZE ) { buf.add( bytes ); } else if ( read > 0 ) { buf.add( bytes, read ); } } return buf.toBytes(); } catch ( Exception ex ) { return Exceptions.handle( byte[].class, ex ); } }
public static byte[] input( InputStream inputStream ) { try ( InputStream is = inputStream ) { ByteBuf buf = ByteBuf.create( DEFAULT_BUFFER_SIZE ); byte[] bytes = new byte[ DEFAULT_BUFFER_SIZE ]; int read = -2; while ( read != -1 ) { read = inputStream.read( bytes ); if ( read == DEFAULT_BUFFER_SIZE ) { buf.add( bytes ); } else if ( read > 0 ) { buf.add( bytes, read ); } } return buf.toBytes(); } catch ( Exception ex ) { return Exceptions.handle( byte[].class, ex ); } }
ByteBuf buf = ByteBuf.create( 244 );
ByteBuf buf = ByteBuf.create( 244 );
ByteBuf buf = ByteBuf.create( 244 );
@Test public void testURLEncodeBytes() { ByteBuf buf = ByteBuf.create( 20 ); buf.addUrlEncodedByteArray( new byte[]{ 0x0, 0x1, 0x2 } ); final byte[] bytes = buf.readForRecycle(); boolean ok = true; ok |= bytes[ 0 ] == '%' || die(); ok |= bytes[ 1 ] == '0' || die(); ok |= bytes[ 2 ] == '0' || die(); ok |= bytes[ 3 ] == '%' || die(); ok |= bytes[ 4 ] == '0' || die(); ok |= bytes[ 5 ] == '1' || die(); ok |= bytes[ 6 ] == '%' || die(); ok |= bytes[ 7 ] == '0' || die(); ok |= bytes[ 8 ] == '2' || die(); }
ByteBuf buf = ByteBuf.create( 20 ); buf.addByte( 0xAA ); buf.addByte( 0x78 );