/**
   * Handles packets received from the repository after the start write request. It's looking for a
   * RepoInfo packet indicating a repository has responded.
   */
  public Interest handleContent(ContentObject co, Interest interest) {

    if (Log.isLoggable(Log.FAC_REPO, Level.INFO))
      Log.info(Log.FAC_REPO, "handleContent: got potential repo message: {0}", co.name());
    if (co.signedInfo().getType() != ContentType.DATA) return null;
    RepositoryInfo repoInfo = new RepositoryInfo();
    try {
      repoInfo.decode(co.content());
      switch (repoInfo.getType()) {
        case INFO:
          for (Client client : _clients) {
            if (client._name.isPrefixOf(co.name())) {
              if (Log.isLoggable(Log.FAC_REPO, Level.FINE))
                Log.fine(Log.FAC_REPO, "Marked client {0} initialized", client._name);
              synchronized (this) {
                client._initialized = true;
                notifyAll();
              }
            }
          }
          break;
        default:
          break;
      }
    } catch (ContentDecodingException e) {
      Log.info(
          Log.FAC_REPO,
          "ContentDecodingException parsing RepositoryInfo: {0} from content object {1}, skipping.",
          e.getMessage(),
          co.name());
    }

    return null;
  }
Example #2
0
  @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);
  }
Example #3
0
 public void updateFromInputStream(InputStream stream) throws RepositoryException {
   PolicyXML pxml;
   try {
     pxml = createPolicyXML(stream);
   } catch (ContentDecodingException e) {
     throw new RepositoryException(e.getMessage());
   }
   update(pxml, false);
   _pxml = pxml;
 }
Example #4
0
 public FaceInstance(byte[] raw) {
   ByteArrayInputStream bais = new ByteArrayInputStream(raw);
   XMLDecoder decoder = XMLCodecFactory.getDecoder(BinaryXMLCodec.CODEC_NAME);
   try {
     decoder.beginDecoding(bais);
     decode(decoder);
     decoder.endDecoding();
   } catch (ContentDecodingException e) {
     String reason = e.getMessage();
     Log.fine("Unexpected error decoding FaceInstance from bytes.  reason: " + reason + "\n");
     Log.warningStackTrace(e);
     throw new IllegalArgumentException(
         "Unexpected error decoding FaceInstance from bytes.  reason: " + reason);
   }
 }