Exemplo n.º 1
0
  public void test2() throws IOException {
    CborObject a = new CborShort(123);
    CborObject b = new CborString("hello");

    HashMap<CborObject, CborObject> m = new HashMap<CborObject, CborObject>();
    m.put(b, a);

    CborMap map = new CborMap(m);
    map.setTag(new CborShort(123));

    System.out.println(map);

    FileOutputStream fos = new FileOutputStream("test.cbor");
    Output output = new StreamOutput(fos);
    CborWriter writer = new CborWriter(output);
    map.write(writer);
    output.close();

    // read
    FileInputStream fis = new FileInputStream("test.cbor");
    Input input = new StreamInput(fis);
    CborReader reader = new CborReader(input);
    CborDebugListener listener = new CborDebugListener();
    reader.setListener(listener);
    reader.run();

    // parse
    fis.close();
    fis = new FileInputStream("test.cbor");
    input = new StreamInput(fis);
    CborParser parser = new CborParser();
    parser.parse(input);
  }
Exemplo n.º 2
0
  public void testRead() throws IOException {
    FileInputStream fis = new FileInputStream("test.cbor");
    Input input = new StreamInput(fis);
    CborReader reader = new CborReader(input);
    CborDebugListener listener = new CborDebugListener();

    reader.setListener(listener);

    reader.run();
  }