本文整理汇总了Java中org.bson.BsonWriter类的典型用法代码示例。如果您正苦于以下问题:Java BsonWriter类的具体用法?Java BsonWriter怎么用?Java BsonWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BsonWriter类属于org.bson包,在下文中一共展示了BsonWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomizedBsonConverter
import org.bson.BsonWriter; //导入依赖的package包/类
@Test
public void testCustomizedBsonConverter() throws Exception {
BsonValueConverterRepertory.registerCustomizedBsonConverter(String.class, new AbstractBsonConverter<String, BsonString>() {
@Override
public String decode(BsonReader bsonReader) {
return "replace string";
}
@Override
public void encode(BsonWriter bsonWriter, String value) {
}
@Override
public String decode(BsonValue bsonValue) {
return "replace string";
}
@Override
public BsonString encode(String object) {
return new BsonString("replace string");
}
});
readFrom();
}
示例2: encoderFor
import org.bson.BsonWriter; //导入依赖的package包/类
/**
* Creates "writer" which can serialize existing immutable instance into <a href="http://bsonspec.org/">BSON format</a>
* consumed by mongo server.
*/
public static <T> Encoder<T> encoderFor(final Class<T> type, final TypeAdapter<T> adapter) {
checkNotNull(type, "type");
checkNotNull(adapter, "adapter");
return new Encoder<T>() {
@Override
public void encode(org.bson.BsonWriter writer, T value, EncoderContext encoderContext) {
try {
adapter.write(new org.immutables.mongo.repository.internal.BsonWriter(writer), value);
} catch (IOException e) {
throw new RuntimeException(String.format("Couldn't write value of class %s: %s", type.getName(), value),e);
}
}
@Override
public Class<T> getEncoderClass() {
return type;
}
};
}
示例3: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, SyncError error, EncoderContext encoderContext) {
Document document= new Document();
if(error.getMessage()!=null && !error.getMessage().isEmpty()){
document.append(SyncAttrs.ERROR_MESSAGE, error.getMessage());
}
String fullStackTrace = ExceptionUtils.getStackTrace(error);
if(fullStackTrace!=null && !fullStackTrace.isEmpty()){
document.append(SyncAttrs.TRACE, fullStackTrace);
}
if(error.getThreadName()!=null && !error.getThreadName().isEmpty()){
document.append(SyncAttrs.THREAD_NAME, error.getThreadName());
}
documentCodec.encode(writer, document, encoderContext);
}
示例4: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, SyncUser user, EncoderContext encoderContext) {
logger.info("Start of Encode method");
Document document = new Document();
if (user.getUserid()!=null && !user.getUserid().isEmpty()){
document.append(String.valueOf(UserDetailAttributes._id), user.getUserid());
}
if(user.getSourceDbMap()!=null && !user.getSourceDbMap().isEmpty()){
document.append(String.valueOf(UserDetailAttributes.sourceDbMap), user.getSourceDbMap());
}
if(user.getTargetDbMap()!=null && !user.getTargetDbMap().isEmpty()){
document.append(String.valueOf(UserDetailAttributes.targetDbMap), user.getTargetDbMap());
}
if(user.getUserRoles()!=null && !user.getUserRoles().isEmpty()){
document.append("roles", user.getUserRoles());
}
documentCodec.encode(writer, document, encoderContext);
logger.info("Encoder completed. Document formed is \n"+document);
}
示例5: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, SyncUserSession session, EncoderContext encoderContext) {
Document document = new Document();
if(session.getSessionId()!=null && !session.getSessionId().isEmpty() ){
document.append(String.valueOf(SessionAttributes._id), session.getSessionId());
}
if(session.getUserid()!=null && !session.getUserid().isEmpty()){
document.append(String.valueOf(SessionAttributes.userid), session.getUserid());
}
if(session.getLoginTime()!=null){
document.append(String.valueOf(SessionAttributes.loginTime), session.getLoginTime());
}
if(session.getClientIPAddress()!=null && !session.getClientIPAddress().isEmpty()){
document.append(String.valueOf(SessionAttributes.clientIPAddress), session.getClientIPAddress());
}
if(session.getClientHostName()!=null && !session.getClientHostName().isEmpty()){
document.append(String.valueOf(SessionAttributes.clientHostName), session.getClientHostName());
}
if(session.getClientAgent()!=null && !session.getClientAgent().isEmpty()){
document.append(String.valueOf(SessionAttributes.clientAgent), session.getClientAgent());
}
documentCodec.encode(writer, document, encoderContext);
}
示例6: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, SyncMarker marker, EncoderContext encoderContext) {
Document document = new Document();
if(marker.getStartTime()!=null){
document.append(SyncAttrs.START_TIME, marker.getStartTime());
}
document.append(SyncAttrs.ROWS_READ, marker.getRowsRead());
if(marker.isAllRowsFetchedFromDb()){
document.append(SyncAttrs.ALL_ROWS_FETCHED, marker.isAllRowsFetchedFromDb());
}
document.append(SyncAttrs.ROWS_DUMPED, marker.getRowsDumped());
document.append(SyncAttrs.TOTAL_ROWS, marker.getTotalRows());
if(marker.getEndTime()!=null){
document.append(SyncAttrs.END_TIME, marker.getEndTime());
}
documentCodec.encode(writer, document, encoderContext);
}
示例7: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(BsonWriter writer, T map, EncoderContext encoderContext) {
if (map == null) {
writer.writeNull();
}
else {
writer.writeStartDocument();
for (Map.Entry<String, Object> entry : map.entrySet()) {
writer.writeName(entry.getKey());
Object value = entry.getValue();
Codec fieldMappingCodec = fieldMappingCodecs.get(entry.getKey());
if (fieldMappingCodec != null) {
fieldMappingCodec.encode(writer, value, encoderContext);
} else {
if (value != null) {
Codec codec = codecRegistry.get(value.getClass());
codec.encode(writer, value, encoderContext);
} else {
writer.writeNull();
}
}
}
writer.writeEndDocument();
}
}
示例8: encodeFields
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encodeFields(BsonWriter writer, T instance, EncoderContext encoderContext) {
// first persist meta document
documentMetaCodec.encodeFields(writer, instance.getMeta(), encoderContext);
// only persist data property if and only if properties exist
Map<String, MappedField> persistenceFields = getPersistenceFields();
if (!persistenceFields.isEmpty()) {
writer.writeName("data");
writer.writeStartDocument();
for (MappedField persistenceField : persistenceFields.values()) {
if (!"meta".equals(persistenceField.getMappedFieldName())) {
persistenceField.encode(writer, instance, encoderContext);
}
}
writer.writeEndDocument();
}
}
示例9: writeValuesToBson
import org.bson.BsonWriter; //导入依赖的package包/类
private void writeValuesToBson(BsonWriter bsonWriter, Field field, Collection fieldValue, Class<?> componentType) {
for (Object value : fieldValue) {
if (value == null) {
continue;
}
Class<?> valueClazz = value.getClass();
if (Utils.isArrayType(valueClazz)) {
encode(bsonWriter, field, value);
continue;
}
if (componentType.isInstance(value)) {
if (BsonValueConverterRepertory.isCanConverterValueType(componentType)) {
BsonValueConverterRepertory.getByteIOConverterByClazz(componentType).encode(bsonWriter, value);
} else {
BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonWriter, value);
}
} else {
throw new BsonMapperConverterException(String.format("array field has element which has different type with declaring componentType.field name: %s", field.getName()));
}
}
}
示例10: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
LocalDateTime value,
EncoderContext encoderContext) {
writer.writeDateTime(
value.toInstant(UTC)
.toEpochMilli()
);
}
示例11: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
ZoneOffset value,
EncoderContext encoderContext) {
writer.writeInt32(value.getTotalSeconds());
}
示例12: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
LocalTime value,
EncoderContext encoderContext) {
writer.writeDateTime(
value.atDate(ofEpochDay(0L))
.toInstant(UTC)
.toEpochMilli()
);
}
示例13: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
MonthDay value,
EncoderContext encoderContext) {
writer.writeDecimal128(parse(format(
"%d.%02d",
value.getMonthValue(),
value.getDayOfMonth()
)));
}
示例14: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
LocalDate value,
EncoderContext encoderContext) {
writer.writeDateTime(
value.atStartOfDay()
.toInstant(UTC)
.toEpochMilli()
);
}
示例15: encode
import org.bson.BsonWriter; //导入依赖的package包/类
@Override
public void encode(
BsonWriter writer,
OffsetTime value,
EncoderContext encoderContext) {
writer.writeString(value.toString());
}