本文整理汇总了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();
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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);
}
}
};
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例12: decode
import org.bson.BsonReader; //导入依赖的package包/类
@Override
public LocalDateTime decode(
BsonReader reader,
DecoderContext decoderContext) {
return ofEpochMilli(reader.readDateTime())
.atOffset(UTC)
.toLocalDateTime();
}
示例13: decode
import org.bson.BsonReader; //导入依赖的package包/类
@Override
public ZoneOffset decode(
BsonReader reader,
DecoderContext decoderContext) {
return ofTotalSeconds(reader.readInt32());
}
示例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);
}
示例15: decode
import org.bson.BsonReader; //导入依赖的package包/类
@Override
public LocalDate decode(
BsonReader reader,
DecoderContext decoderContext) {
return ofEpochMilli(reader.readDateTime())
.atOffset(UTC)
.toLocalDate();
}