2424public class Bits {
2525
2626 public static void readFully ( InputStream in , byte [] b )
27+ throws IOException {
28+ readFully ( in , b , b .length );
29+ }
30+
31+ public static void readFully ( InputStream in , byte [] b , int l )
2732 throws IOException {
2833 int x = 0 ;
29- while ( x <b . length ){
30- int temp = in .read ( b , x , b . length - x );
34+ while ( x <l ){
35+ int temp = in .read ( b , x , l - x );
3136 if ( temp < 0 )
3237 throw new EOFException ();
3338 x += temp ;
@@ -36,8 +41,12 @@ public static void readFully( InputStream in, byte[] b )
3641
3742 public static int readInt ( InputStream in )
3843 throws IOException {
39- byte [] data = new byte [4 ];
40- readFully (in , data );
44+ return readInt ( in , new byte [4 ] );
45+ }
46+
47+ public static int readInt ( InputStream in , byte [] data )
48+ throws IOException {
49+ readFully (in , data , 4 );
4150 return readInt (data );
4251 }
4352
@@ -52,9 +61,13 @@ public static int readInt( byte[] data ) {
5261
5362 public static long readLong ( InputStream in )
5463 throws IOException {
64+ return readLong ( in , new byte [8 ] );
65+ }
5566
56- byte [] data = new byte [8 ];
57- readFully (in , data );
67+
68+ public static long readLong ( InputStream in , byte [] data )
69+ throws IOException {
70+ readFully (in , data , 8 );
5871 return readLong (data );
5972 }
6073
0 commit comments