示例#1
0
  /**
   * Reads binary data from the input stream
   *
   * @return the json token read
   * @throws IOException if an I/O error occurs
   */
  protected JsonToken handleBinary() throws IOException {
    int size = _in.readInt();
    byte subtype = _in.readByte();
    Context ctx = getContext();
    switch (subtype) {
      case BsonConstants.SUBTYPE_BINARY_OLD:
        int size2 = _in.readInt();
        byte[] buf2 = new byte[size2];
        _in.readFully(buf2);
        ctx.value = buf2;
        break;

      case BsonConstants.SUBTYPE_UUID:
        long l1 = _in.readLong();
        long l2 = _in.readLong();
        ctx.value = new UUID(l1, l2);
        break;

      default:
        byte[] buf = new byte[size];
        _in.readFully(buf);
        ctx.value = buf;
        break;
    }

    return JsonToken.VALUE_EMBEDDED_OBJECT;
  }