コード例 #1
0
ファイル: ContentNameTest.java プロジェクト: truedat101/ccnx
  @Test
  public void testDecodeInputStream() {
    byte[][] arr = new byte[4][];
    arr[0] = baseName.getBytes();
    arr[1] = subName1.getBytes();
    arr[2] = document1.getBytes();
    arr[3] = document3;
    ContentName name = new ContentName(arr);
    System.out.println("Encoding name: " + name);
    assertNotNull(name);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      name.encode(baos);
    } catch (ContentEncodingException e) {
      System.out.println("Exception " + e.getClass().getName() + ", message: " + e.getMessage());
      e.printStackTrace();
    }
    System.out.println("Encoded name: ");
    System.out.println(baos.toString());

    System.out.println("Decoding name: ");
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ContentName name2 = new ContentName();
    try {
      name2.decode(bais);
    } catch (ContentDecodingException e) {
      System.out.println("Exception " + e.getClass().getName() + ", message: " + e.getMessage());
      e.printStackTrace();
    }
    System.out.println("Decoded name: " + name2);
    assertEquals(name, name2);
  }
コード例 #2
0
ファイル: RepoSingleFileTester.java プロジェクト: hamhei/ccnx
 public ContentObject put(ContentObject co) throws IOException {
   if (_fos != null) {
     try {
       WirePacket packet = new WirePacket(co);
       _fos.write(packet.encode());
     } catch (ContentEncodingException e) {
       e.printStackTrace();
     }
   }
   return co;
 }