private BSONEncoder getEncoder() { return new BasicBSONEncoder(); }
/** * Encodes a DBObject as a BSON byte array. * * @param doc the document to encode * @return the document encoded as BSON */ public static byte[] encode(final BSONObject doc) { return new BasicBSONEncoder().encode(doc); }
<T> Key<T> createKey(final Class<T> clazz, final Object id) { if (id instanceof Serializable) { return createKey(clazz, (Serializable) id); } //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does. final BSONEncoder enc = new BasicBSONEncoder(); return new Key<T>(clazz, getCollectionName(clazz), enc.encode(toDBObject(id))); } }
BSONEncoder getBSONEncoder(){ if (_bsonEncoder == null) _bsonEncoder = new BasicBSONEncoder(); return _bsonEncoder; }
BSONEncoder getBSONEncoder(){ if (_bsonEncoder == null) _bsonEncoder = new BasicBSONEncoder(); return _bsonEncoder; }
BSONEncoder getBSONEncoder(){ if (_bsonEncoder == null) _bsonEncoder = new BasicBSONEncoder(); return _bsonEncoder; }
protected BSONEncoder initialValue() { return new BasicBSONEncoder(); } };
import org.bson.BasicBSONEncoder; BSONObject bson = (BSONObject)com.mongodb.util.JSON.parse(string_json); BasicBSONEncoder encoder = new BasicBSONEncoder(); byte[] bson_byte = encoder.encode(bson);
public static byte[] encode(BSONObject bsonObject) { BSONEncoder encoder = new BasicBSONEncoder(); return encoder.encode(bsonObject); } public static BSONObject readObject(InputStream is) throws IOException { BasicBSONDecoder encoder = new BasicBSONDecoder(); return encoder.readObject(is); } public static BSONObject readObject(byte[] bsonObject) { BasicBSONDecoder encoder = new BasicBSONDecoder(); return encoder.readObject(bsonObject); }
/** * {@inheritDoc} */ @Override public String toString(){ BSONEncoder enc = new BasicBSONEncoder(); BasicOutputBuffer buf = new BasicOutputBuffer(); enc.set( buf ); enc.putObject( _doc ); enc.done(); String str = buf.asString(); log.debug( "Output As String: '" + str + "'" ); return str; }
public <T> Key<T> createKey(Class<T> clazz, Object id) { if (id instanceof Serializable) return createKey(clazz, (Serializable) id); //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does. BSONEncoder enc = new BasicBSONEncoder(); return new Key<T>(clazz, enc.encode(toDBObject(id))); }
<T> Key<T> createKey(final Class<T> clazz, final Object id) { if (id instanceof Serializable) { return createKey(clazz, (Serializable) id); } //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does. final BSONEncoder enc = new BasicBSONEncoder(); return new Key<T>(clazz, enc.encode(toDBObject(id))); }
<T> Key<T> createKey(final Class<T> clazz, final Object id) { if (id instanceof Serializable) { return createKey(clazz, (Serializable) id); } //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does. final BSONEncoder enc = new BasicBSONEncoder(); return new Key<T>(clazz, getCollectionName(clazz), enc.encode(toDBObject(id))); }
public byte[] DBObjectToBSON(DBObject dbObject) { BasicBSONEncoder encoder = new BasicBSONEncoder(); byte bson[] = encoder.encode(dbObject); return bson; } public DBObject BSONToDBObject(byte[] bson) { BasicBSONDecoder decoder = new BasicBSONDecoder(); JSONCallback callback = new JSONCallback(); decoder.decode(bson, callback); Object obj = callback.get(); DBObject dbObject = (DBObject) obj; return dbObject; }
/** * {@inheritDoc} * * @see Writable#write(DataOutput) */ public void write( DataOutput out ) throws IOException{ BSONEncoder enc = new BasicBSONEncoder(); BasicOutputBuffer buf = new BasicOutputBuffer(); enc.set( buf ); enc.putObject( _doc ); enc.done(); buf.pipe( out ); }
/** * {@inheritDoc} * * @see Writable#write(DataOutput) */ public void write( DataOutput out ) throws IOException{ BSONEncoder enc = new BasicBSONEncoder(); BasicOutputBuffer buf = new BasicOutputBuffer(); enc.set( buf ); enc.putObject( _doc ); enc.done(); buf.pipe( out ); }
/** * {@inheritDoc} * * @see Writable#write(DataOutput) */ public void write(final DataOutput out) throws IOException { BSONEncoder enc = new BasicBSONEncoder(); BasicOutputBuffer buf = new BasicOutputBuffer(); enc.set(buf); enc.putObject(doc); enc.done(); buf.pipe(out); }
@Override public void writeStructEnd() throws TException { super.writeStructEnd(); if (!inFlight()) { // We've finished writing the root struct, so dump out to the real transport. realTransport.write(new BasicBSONEncoder().encode(super.getOutput())); } }
private static <T> T generateAndParse(Object o, Class<T> cls) throws Exception { BSONObject bo = new BasicBSONObject(); bo.put("obj", o); //that's why all properties of classes in TC must be named 'obj' BSONEncoder encoder = new BasicBSONEncoder(); byte[] barr = encoder.encode(bo); ByteArrayInputStream bais = new ByteArrayInputStream(barr); ObjectMapper om = new ObjectMapper(new BsonFactory()); om.registerModule(new BsonModule()); T r = om.readValue(bais, cls); return r; }
/** * {@inheritDoc} * * @see Writable#write(DataOutput) */ public void write(final DataOutput out) throws IOException { BSONEncoder enc = new BasicBSONEncoder(); BasicOutputBuffer buf = new BasicOutputBuffer(); enc.set(buf); enc.putObject(doc); enc.done(); buf.pipe(new DataOutputOutputStreamAdapter(out)); }