org.bson.BsonBinarySubType Java Examples
The following examples show how to use
org.bson.BsonBinarySubType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UuidProvidedStrategy.java From mongo-kafka with Apache License 2.0 | 5 votes |
@Override public BsonValue generateId(final SinkDocument doc, final SinkRecord orig) { BsonValue id = super.generateId(doc, orig); if (id.isBinary() && BsonBinarySubType.isUuid(id.asBinary().getType())) { return id; } else if (id.isString()) { return new BsonBinary( constructUuidObjectFromString(id.asString().getValue()), UuidRepresentation.STANDARD); } throw new DataException(format("UUID cannot be constructed from provided value: `%s`", id)); }
Example #2
Source File: ArrayCodec.java From morphia with Apache License 2.0 | 5 votes |
private Object readValue(final BsonReader reader, final DecoderContext decoderContext) { BsonType bsonType = reader.getCurrentBsonType(); if (bsonType == BsonType.NULL) { reader.readNull(); return null; } else if (bsonType == BsonType.BINARY && BsonBinarySubType.isUuid(reader.peekBinarySubType()) && reader.peekBinarySize() == 16) { return mapper.getCodecRegistry().get(UUID.class).decode(reader, decoderContext); } return mapper.getCodecRegistry().get(type.getComponentType()).decode(reader, decoderContext); }
Example #3
Source File: WritecontextTest.java From pinpoint with Apache License 2.0 | 4 votes |
@Test public void parseBsonArrayWithValues() throws IOException { BsonValue a = new BsonString("stest"); BsonValue b = new BsonDouble(111); BsonValue c = new BsonBoolean(true); BsonDocument document = new BsonDocument() .append("int32", new BsonInt32(12)) .append("int64", new BsonInt64(77L)) .append("bo\"olean", new BsonBoolean(true)) .append("date", new BsonDateTime(new Date().getTime())) .append("double", new BsonDouble(12.3)) .append("string", new BsonString("pinpoint")) .append("objectId", new BsonObjectId(new ObjectId())) .append("code", new BsonJavaScript("int i = 10;")) .append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))) .append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")) .append("symbol", new BsonSymbol("wow")) .append("timestamp", new BsonTimestamp(0x12345678, 5)) .append("undefined", new BsonUndefined()) .append("binary1", new BsonBinary(new byte[]{(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20})) .append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[]{1, 1, 1, 1, 1})) .append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))) .append("document", new BsonDocument("a", new BsonInt32(77))) .append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())) .append("null", new BsonNull()) .append("decimal128", new BsonDecimal128(new Decimal128(55))); BasicDBObject query = new BasicDBObject(); query.put("ComplexBson", document); logger.debug("document:{}", document); NormalizedBson stringStringValue = MongoUtil.parseBson(new Object[]{query}, true); logger.debug("val:{}", stringStringValue); List list = objectMapper.readValue("[" + stringStringValue.getNormalizedBson() + "]", List.class); Assert.assertEquals(list.size(), 1); Map<String, ?> query1Map = (Map<String, ?>) list.get(0); checkValue(query1Map); }
Example #4
Source File: WritecontextTest.java From pinpoint with Apache License 2.0 | 4 votes |
@Test public void parseTestAbbreviation_BsonValueArray() throws IOException { BsonInt32[] bsonInt32s = new BsonInt32[40]; for (int i = 0; i < 40; i++) { bsonInt32s[i] = new BsonInt32(i + 1); } BsonDocument document = new BsonDocument() .append("double", new BsonDouble(12.3)) .append("arrayInt", new BsonArray(Arrays.asList(bsonInt32s))) // .append("arrayInt", new BsonArray({1,1,1,1,1,1,1,1,1,1,1}) .append("binary1", new BsonBinary(new byte[]{(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d, (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20, (byte) 0xea, 0x3a, 0x69, 0x10, (byte) 0xa2, (byte) 0xd8, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d})) .append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[]{1, 1, 1, 1, 1})); BasicDBObject query = new BasicDBObject(); query.put("ComplexBson", document); logger.debug("document:{}", document); NormalizedBson stringStringValue = MongoUtil.parseBson(new Object[]{query}, true); logger.debug("val:{}", stringStringValue); List list = objectMapper.readValue("[" + stringStringValue.getNormalizedBson() + "]", List.class); Assert.assertEquals(list.size(), 1); Map<String, ?> query1Map = (Map<String, ?>) list.get(0); checkValue(query1Map); }
Example #5
Source File: PhotoService.java From tutorials with MIT License | 4 votes |
public String addPhoto(String title, MultipartFile file) throws IOException { Photo photo = new Photo(title); photo.setImage(new Binary(BsonBinarySubType.BINARY, file.getBytes())); photo = photoRepo.insert(photo); return photo.getId(); }