当前位置: 首页>>代码示例>>Java>>正文


Java BsonReader类代码示例

本文整理汇总了Java中org.bson.BsonReader的典型用法代码示例。如果您正苦于以下问题:Java BsonReader类的具体用法?Java BsonReader怎么用?Java BsonReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BsonReader类属于org.bson包,在下文中一共展示了BsonReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomizedBsonConverter

import org.bson.BsonReader; //导入依赖的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();
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:26,代码来源:DefaultBsonMapperTest.java

示例2: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public MonthDay decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    BigDecimal value = reader
            .readDecimal128()
            .bigDecimalValue();
    int month = value.intValue();
    return of(
            month,
            value.subtract(new BigDecimal(month))
                 .scaleByPowerOfTen(2)
                 .intValue()
    );
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:17,代码来源:MonthDayCodec.java

示例3: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public YearMonth decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    BigDecimal value = reader
            .readDecimal128()
            .bigDecimalValue();
    int year = value.intValue();
    return of(
            year,
            value.subtract(new BigDecimal(year))
                 .scaleByPowerOfTen(2)
                 .abs()
                 .intValue()
    );
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:18,代码来源:YearMonthCodec.java

示例4: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public Duration decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    BigDecimal value = reader
            .readDecimal128()
            .bigDecimalValue();
    long seconds = value.longValue();
    return ofSeconds(
            seconds,
            value.subtract(new BigDecimal(seconds))
                 .scaleByPowerOfTen(9)
                 .abs()
                 .intValue()
    );
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:18,代码来源:DurationCodec.java

示例5: decoderFor

import org.bson.BsonReader; //导入依赖的package包/类
/**
 * Creates a "reader" which is able to deserialize binary data into a immutables instance (using GSON type adapter).
 */
public static <T> Decoder<T> decoderFor(final Class<T> type, final TypeAdapter<T> adapter) {
  checkNotNull(type, "type");
  checkNotNull(adapter, "adapter");
  return new Decoder<T>() {
    @Override
    public T decode(BsonReader reader, DecoderContext decoderContext) {
      if (!(reader instanceof AbstractBsonReader)) {
        throw new UnsupportedOperationException(String.format("Only readers of type %s supported. Yours is %s",
            AbstractBsonReader.class.getName(), reader.getClass().getName()));
      }

      try {
        return adapter.read(new org.immutables.mongo.repository.internal.BsonReader((AbstractBsonReader) reader));
      } catch (IOException e) {
        throw new RuntimeException(String.format("Couldn't encode %s", type), e);
      }
    }
  };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:BsonEncoding.java

示例6: decode

import org.bson.BsonReader; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public SyncNodeDetails decode(BsonReader bsonReader, DecoderContext context) {
	Document document = documentCodec.decode(bsonReader, context);
	SyncNodeDetails nodeAndEvent = new SyncNodeDetails();
	SyncNode node = SyncNodeDecoder.decodeNode((Document) document.get("node"));
	nodeAndEvent.setNode(node);
	SyncEvent event = null;
	List<SyncEvent> eventList = new ArrayList<SyncEvent>();
	SyncMapAndEventDecoder eventDecoder = new SyncMapAndEventDecoder();
	@SuppressWarnings("unchecked")
	List<Document> list = (List<Document>) document.get("events");
	for(Document doc : list){ 
		event = eventDecoder.decodeSyncEvent(doc);
		eventList.add(event); 
	} 
	nodeAndEvent.setEvent(eventList);
	return nodeAndEvent;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:20,代码来源:SyncNodeDetailsCodec.java

示例7: decode

import org.bson.BsonReader; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public O2MSyncEventLog decode(BsonReader arg0, DecoderContext arg1) {
	Document document = documentCodec.decode(arg0, arg1);
	O2MSyncEventLog log = new O2MSyncEventLog();
	log.setLogId(document.getObjectId(_ID));
	log.setEventId(document.getString(EVENT_ID));
	log.setCrOn(document.getDate(CREATED_ON));
	log.setSyOn(document.getDate(SYNCED_ON));
	log.setStatus(document.getString(STATUS));
	log.setOperation(document.getString(OPERATION));
	List<Document> filterDocList = (List<Document>) document.get(EVENT_FILTERS);
	if(filterDocList!=null){
		List<O2MSyncEventInfo> filters = new ArrayList<O2MSyncEventInfo>(filterDocList.size());
		O2MSyncEventInfo filter = null;
		for(Document filterDoc : filterDocList){
			filter= new O2MSyncEventInfo();
			filter.setTableName(filterDoc.getString(TABLE_NAME));
			filter.setColumnName(filterDoc.getString(COLUMN_NAME));
			filter.setColumnValue(filterDoc.get(COLUMN_VALUE));
			filters.add(filter);
		}
		log.setEventFilters(filters);
	}
	return log;
}
 
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:27,代码来源:O2MSyncEventLogCodec.java

示例8: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
    T map = newInstance();
    reader.readStartDocument();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        String key = reader.readName();

        Object value;
        Codec fieldMappingCodec = fieldMappingCodecs.get(key);
        if (fieldMappingCodec != null) {
            value = fieldMappingCodec.decode(reader, decoderContext);
        } else {
            value = readValue(reader, decoderContext);
        }

        map.put(key, value);
    }
    reader.readEndDocument();
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:21,代码来源:SpecialFieldsMapCodec.java

示例9: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public Map<String, V> decode(BsonReader reader, DecoderContext decoderContext) {
    Map<String, V> map = newInstance();
    if (BsonType.DOCUMENT.equals(reader.getCurrentBsonType())) {
        reader.readStartDocument();
        while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
            String key = reader.readName();
            V value = valueTypeCodec.decode(reader, decoderContext);
            map.put(key, value);
        }
        reader.readEndDocument();
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.DOCUMENT, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:18,代码来源:SimpleMapTypeCodec.java

示例10: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public T decode(BsonReader reader, DecoderContext decoderContext) {
    if (BsonType.STRING.equals(reader.getCurrentBsonType())) {
        String name = reader.readString();
        if (name != null) {
            try {
                return Enum.valueOf(clazz, name);
            } catch (IllegalArgumentException e) {
                LOGGER.warn("Enum value {} could not be determined for enum type {}", name, clazz, e);
            }
        }
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.STRING, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return null;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:18,代码来源:EnumCodec.java

示例11: handleArrayForBsonReader

import org.bson.BsonReader; //导入依赖的package包/类
private Object handleArrayForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
    Class<?> fieldType = field.getType();
    ArrayList<Object> arrayList = new ArrayList<Object>();
    bsonReader.readStartArray();
    while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        BsonType currentBsonType = bsonReader.getCurrentBsonType();
        if (currentBsonType == BsonType.NULL) {
            continue;
        }
        if (currentBsonType == BsonType.ARRAY) {
            arrayList.add(decode(bsonReader, field, bsonMapperConfig));
        } else {
            Object javaValue;
            if (currentBsonType == BsonType.DOCUMENT) {
                javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, fieldType.getComponentType(), bsonMapperConfig);
            } else {
                javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
            }
            arrayList.add(javaValue);
        }
    }
    bsonReader.readEndArray();
    return arrayList.toArray((Object[]) Array.newInstance(fieldType.getComponentType(), 0));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:25,代码来源:BsonArrayConverter.java

示例12: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public LocalDateTime decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return ofEpochMilli(reader.readDateTime())
            .atOffset(UTC)
            .toLocalDateTime();
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:10,代码来源:LocalDateTimeCodec.java

示例13: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public ZoneOffset decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return ofTotalSeconds(reader.readInt32());
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:8,代码来源:ZoneOffsetCodec.java

示例14: testByteIOEncode

import org.bson.BsonReader; //导入依赖的package包/类
@Test
public void testByteIOEncode() throws Exception {
    BasicOutputBuffer bsonOutput = new BasicOutputBuffer();
    BsonWriter bsonWriter = new BsonBinaryWriter(bsonOutput);
    BsonValueConverterRepertory.getBsonDocumentConverter().encode(bsonWriter, getObject());
    BsonReader bsonReader = new BsonBinaryReader(new ByteBufferBsonInput(bsonOutput.getByteBuffers().get(0)));
    BsonTest bsonTest = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, BsonTest.class, BsonMapperConfig.DEFALUT);
    System.out.println(bsonTest);
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:10,代码来源:BsonDocumentConverterTest.java

示例15: decode

import org.bson.BsonReader; //导入依赖的package包/类
@Override
public LocalDate decode(
        BsonReader reader,
        DecoderContext decoderContext) {

    return ofEpochMilli(reader.readDateTime())
            .atOffset(UTC)
            .toLocalDate();
}
 
开发者ID:cbartosiak,项目名称:bson-codecs-jsr310,代码行数:10,代码来源:LocalDateCodec.java


注:本文中的org.bson.BsonReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。