예제 #1
0
파일: App.java 프로젝트: naphaso/cbor-java
  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);
  }
예제 #2
0
파일: App.java 프로젝트: naphaso/cbor-java
  public void testWrite2() throws IOException {
    FileOutputStream fos = new FileOutputStream("test.cbor");
    Output output = new StreamOutput(fos);
    CborWriter writer = new CborWriter(output);

    Map<String, String> someMap = new HashMap<String, String>();
    someMap.put("hello", "world");
    someMap.put("one", "two");
    someMap.put("test", "catch");

    writer.write(someMap);

    output.close();
  }
예제 #3
0
파일: App.java 프로젝트: naphaso/cbor-java
  public void testWrite() throws IOException {
    FileOutputStream fos = new FileOutputStream("test.cbor");
    Output output = new StreamOutput(fos);
    CborWriter writer = new CborWriter(output);

    writer.writeMap(2);

    // key 1
    writer.writeString("hello");
    // value 1
    writer.writeInt(
        new BigInteger(
            "5126378562348346534857632482374652582763453486542735654325645832478457363787456436263574"));

    // key 2
    writer.writeString("world");
    // value 2
    writer.writeArray(1);
    writer.writeString("hihihi");

    output.close();
  }