Skip to content

Commit 7aae216

Browse files
author
Ryan
committed
Merge pull request #31 from josephks/master
Adding BasicOutputBuffer.pipe( DataOutput out )
2 parents c495cfd + b275de4 commit 7aae216

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,69 @@
66

77
public class BasicOutputBuffer extends OutputBuffer {
88

9+
@Override
910
public void write(byte[] b){
1011
write( b , 0 , b.length );
1112
}
1213

14+
@Override
1315
public void write(byte[] b, int off, int len){
1416
_ensure( len );
1517
System.arraycopy( b , off , _buffer , _cur , len );
1618
_cur += len;
1719
_size = Math.max( _cur , _size );
1820
}
21+
@Override
1922
public void write(int b){
2023
_ensure(1);
2124
_buffer[_cur++] = (byte)(0xFF&b);
2225
_size = Math.max( _cur , _size );
2326
}
2427

28+
@Override
2529
public int getPosition(){
2630
return _cur;
2731
}
32+
@Override
2833
public void setPosition( int position ){
2934
_cur = position;
3035
}
3136

37+
@Override
3238
public void seekEnd(){
3339
_cur = _size;
3440
}
41+
@Override
3542
public void seekStart(){
3643
_cur = 0;
3744
}
3845

3946
/**
4047
* @return size of data so far
4148
*/
49+
@Override
4250
public int size(){
4351
return _size;
4452
}
4553

4654
/**
4755
* @return bytes written
4856
*/
57+
@Override
4958
public int pipe( OutputStream out )
5059
throws IOException {
5160
out.write( _buffer , 0 , _size );
5261
return _size;
5362
}
63+
/**
64+
* @return bytes written
65+
*/
66+
public int pipe( DataOutput out )
67+
throws IOException {
68+
out.write( _buffer , 0 , _size );
69+
return _size;
70+
}
71+
5472

5573
void _ensure( int more ){
5674
final int need = _cur + more;
@@ -66,10 +84,12 @@ void _ensure( int more ){
6684
_buffer = n;
6785
}
6886

87+
@Override
6988
public String asString(){
7089
return new String( _buffer , 0 , _size );
7190
}
7291

92+
@Override
7393
public String asString( String encoding )
7494
throws UnsupportedEncodingException {
7595
return new String( _buffer , 0 , _size , encoding );

0 commit comments

Comments
 (0)