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


Java BsonReader.readEndArray方法代码示例

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


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

示例1: 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

示例2: decode

import org.bson.BsonReader; //导入方法依赖的package包/类
@Override
public Map<K, V> decode(BsonReader reader, DecoderContext decoderContext) {
    Map<K, V> map = newInstance();
    if (BsonType.ARRAY.equals(reader.getCurrentBsonType())) {
        reader.readStartArray();
        while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
            if (BsonType.DOCUMENT.equals(reader.getCurrentBsonType())) {
                reader.readStartDocument();
                reader.readName(); // don't need the key == "key"
                K key = keyTypeCodec.decode(reader, decoderContext);
                reader.readName(); // don't need the key == "value"
                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();
            }
        }
        reader.readEndArray();
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.ARRAY, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return map;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:27,代码来源:ComplexMapTypeCodec.java

示例3: readList

import org.bson.BsonReader; //导入方法依赖的package包/类
private List<Object> readList(final BsonReader reader, final DecoderContext decoderContext) {
    reader.readStartArray();
    List<Object> list = new ArrayList<>();
    while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        list.add(readValue(reader, decoderContext));
    }
    reader.readEndArray();
    return list;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:10,代码来源:SpecialFieldsMapCodec.java

示例4: handleCollectionForBsonReader

import org.bson.BsonReader; //导入方法依赖的package包/类
Object handleCollectionForBsonReader(BsonReader bsonReader, Field field, BsonMapperConfig bsonMapperConfig) {
    Class<?> fieldType = field.getType();
    Class<?> implClass = Utils.giveImplClassIfSupport(fieldType);
    if (Utils.isUnableAddCollectionClazz(implClass)) {
        return null;
    }
    BsonArrayField bsonArrayField = Utils.getBsonArrayFieldAnnotation(field);
    Class<?> targetComponentClazz = bsonArrayField.componentType();

    Object collectionObject = Utils.newInstanceByClazz(implClass);
    Method method;
    try {
        method = implClass.getMethod("add", Object.class);
    } catch (NoSuchMethodException e) {
        throw new BsonMapperConverterException("NoSuchMethodException", e);
    }

    bsonReader.readStartArray();
    while (bsonReader.readBsonType() != BsonType.END_OF_DOCUMENT) {
        BsonType currentBsonType = bsonReader.getCurrentBsonType();
        if (currentBsonType == BsonType.NULL) {
            continue;
        }
        if (currentBsonType == BsonType.ARRAY) {
            Utils.methodInvoke(method, collectionObject, decode(bsonReader, field, bsonMapperConfig));
        } else {
            Object javaValue;
            if (currentBsonType == BsonType.DOCUMENT) {
                javaValue = BsonValueConverterRepertory.getBsonDocumentConverter().decode(bsonReader, targetComponentClazz, bsonMapperConfig);
            } else {
                javaValue = BsonValueConverterRepertory.getByteIOConverterByBsonType(currentBsonType).decode(bsonReader);
            }
            Utils.methodInvoke(method, collectionObject, javaValue);
        }
    }
    bsonReader.readEndArray();
    return collectionObject;
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:39,代码来源:BsonArrayConverter.java

示例5: decodeDimension

import org.bson.BsonReader; //导入方法依赖的package包/类
private Object decodeDimension(BsonReader reader, DecoderContext decoderContext, Class<?> componentType) {
    Object array = null;
    boolean decodeLastDimension;
    Class<?> childComponentType = componentType.getComponentType();
    decodeLastDimension = !childComponentType.isArray();

    if (childComponentType == byte.class) {
        array = arrayElementCodec.decode(reader, decoderContext);
    } else if (BsonType.ARRAY.equals(reader.getCurrentBsonType())) {
        reader.readStartArray();
        if (decodeLastDimension) {
            if (isPrimitive) {
                array = arrayElementCodec.decode(reader, decoderContext);
            } else {
                List list = new ArrayList();
                while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
                    list.add(arrayElementCodec.decode(reader, decoderContext));
                }
                array = Array.newInstance(childComponentType, list.size());
                for (int i = 0; i < list.size(); i++) {
                    Array.set(array, i, list.get(i));
                }
            }
        } else {
            List arrayList = new ArrayList();
            while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
                Object decoded = decodeDimension(reader, decoderContext, childComponentType);
                arrayList.add(decoded);
            }

            array = Array.newInstance(childComponentType, arrayList.size());
            for (int i = 0; i < arrayList.size(); i++) {
                Array.set(array, i, arrayList.get(i));
            }
        }
        reader.readEndArray();
    } else {
        LOGGER.warn("Expected {} from reader but got {}. Skipping value.", BsonType.ARRAY, reader.getCurrentBsonType());
        reader.skipValue();
    }
    return array;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:43,代码来源:ArrayCodec.java


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