Skip to content

Commit 43eeba7

Browse files
committed
few minor improvements
1 parent 306e36c commit 43eeba7

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/main/org/bson/BSONDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ class Input {
259259
int readInt()
260260
throws IOException {
261261
_read += 4;
262-
return Bits.readInt( _in );
262+
return Bits.readInt( _in , _random );
263263
}
264264

265265
long readLong()
266266
throws IOException {
267267
_read += 8;
268-
return Bits.readLong( _in );
268+
return Bits.readLong( _in , _random );
269269
}
270270

271271
double readDouble()

src/main/org/bson/io/Bits.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@
2424
public 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

Comments
 (0)