Package org.bson.types

Examples of org.bson.types.Binary


        } else if (b.containsField("$uuid")) {
            o = UUID.fromString((String) b.get("$uuid"));
        } else if (b.containsField("$binary")) {
            int type = (Integer) b.get("$type");
            byte[] bytes = (new Base64Codec()).decode((String) b.get("$binary"));
            o = new Binary((byte) type, bytes);
        } else if (b.containsField("$numberLong")) {
            o = Long.valueOf((String) b.get("$numberLong"));
        }

        if (!isStackEmpty()) {
View Full Code Here


            super(serializer);
        }

        @Override
        public void serialize(Object obj, StringBuilder buf) {
            Binary bin = (Binary) obj;
            serialize(bin.getData(), bin.getType(), buf);
        }
View Full Code Here

        MaxKey key2 = (MaxKey) objectInputStream.readObject();
    }

    @Test
    public void testSerializeBinary() throws Exception {
        Binary binary = new Binary((byte)0x00 , "hello world".getBytes());

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

        objectOutputStream.writeObject(binary);

        ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
        Binary binary2 = (Binary) objectInputStream.readObject();
       
        assertArrayEquals(binary.getData(), binary2.getData());
        assertEquals(binary.getType(), binary2.getType());
    }
View Full Code Here

  @Test
  public void parseBinary() throws Exception {
    byte[] b = new byte[] { 1, 2, 3, 4, 5 };
    BSONObject o = new BasicBSONObject();
    o.put("b1", b);
    o.put("b2", new Binary(BsonConstants.SUBTYPE_BINARY, b));
    o.put("uuid", new UUID(1L, 2L));
   
    Map<?, ?> data = parseBsonObject(o);
    assertEquals(3, data.size());
    assertArrayEquals(b, (byte[])data.get("b1"));
View Full Code Here

      ByteArrayOutputStream out = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(out);
      oos.writeObject(obj);
      oos.flush();
      oos.close();
      data = new Binary(out.toByteArray());
      return;
    }

    // 好吧,啥都不是? 转Json!!
    type = "json";
View Full Code Here

TOP

Related Classes of org.bson.types.Binary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.