mongo-ruby-driver/ext/java/src/org/jbson/RubyBSONDecoder.java

38 lines
966 B
Java
Raw Normal View History

2010-09-30 13:43:17 +00:00
// RubyBSONDecoder.java
package org.jbson;
import static org.bson.BSON.*;
import java.io.*;
import org.jruby.*;
import org.bson.*;
import org.bson.io.*;
import org.bson.types.*;
2011-08-10 18:14:52 +00:00
public class RubyBSONDecoder extends BasicBSONDecoder {
2010-09-30 13:43:17 +00:00
protected void _binary( String name )
throws IOException {
final int totalLen = _in.readInt();
final byte bType = _in.read();
if( bType == 2 ) {
final int len = _in.readInt();
if ( len + 4 != totalLen )
throw new IllegalArgumentException( "bad data size subtype 2 len: " + len + "totalLen: " + totalLen );
final byte[] data = new byte[len];
_in.fill( data );
_callback.gotBinary( name, (byte)2, data );
}
else {
byte[] data = new byte[totalLen];
_in.fill( data );
_callback.gotBinary( name, bType, data );
}
}
2010-09-30 13:43:17 +00:00
}