Esempio n. 1
0
 public EnumeratedNameList(ContentName namePrefix, boolean startEnumerating, CCNHandle handle)
     throws IOException {
   if (null == namePrefix) {
     throw new IllegalArgumentException("namePrefix cannot be null!");
   }
   if (null == handle) {
     try {
       handle = CCNHandle.open();
     } catch (ConfigurationException e) {
       throw new IOException(
           "ConfigurationException attempting to open a handle: " + e.getMessage());
     }
   }
   _namePrefix = namePrefix;
   if (startEnumerating) {
     _enumerating = true;
     _hasEnumerated = true;
     _enumerator = new CCNNameEnumerator(namePrefix, handle, this);
   } else {
     _enumerator = new CCNNameEnumerator(handle, this);
   }
 }
  @Before
  public void setUp() {
    try {

      names = new ArrayList<ContentName>();

      _putHandle = CCNHandle.open();
      _getHandle = CCNHandle.open();
      _fileHandle = CCNHandle.open();

      getne = new CCNNameEnumerator(_getHandle, this);

      putne = new CCNNameEnumerator(_putHandle, this);

      helper = new CCNTestHelper(this.getClass().getName());

      _prefix = helper.getClassNamespace();

      _class = ContentName.fromNative(_prefix, "classResponder");
      _class2 = ContentName.fromNative(_prefix, "classResponder2");
      _repo = ContentName.fromNative(_prefix, "repoResponder");

      updated = false;

      putne.registerNameSpace(_prefix);
      Log.info("registering namespace prefix: {0} count: {1}", _prefix, _prefix.count());

      putNERegisterName(_class);

      addContentToRepo(_repo);

    } catch (ConfigurationException e) {
      Assert.fail("Configuration Exception when setting up test. " + e.getMessage());
    } catch (IOException e) {
      Assert.fail("IOException when setting up test. " + e.getMessage());
    }
  }
Esempio n. 3
0
  /** @param args */
  public void write(String[] args) {
    Log.setDefaultLevel(Level.WARNING);

    for (int i = 0; i < args.length - 2; i++) {
      if (args[i].equals("-local")) {
        CommonParameters.local = true;
      } else if (args[i].equals(("-raw"))) {
        CommonParameters.rawMode = true;
      } else {
        if (!CommonArguments.parseArguments(args, i, ccnputfile)) {
          usage();
        }
        if (CommonParameters.startArg > i + 1) i = CommonParameters.startArg - 1;
      }
      if (CommonParameters.startArg <= i) CommonParameters.startArg = i + 1;
    }

    if (args.length < CommonParameters.startArg + 2) {
      usage();
    }

    long starttime = System.currentTimeMillis();
    try {
      // If we get one file name, put as the specific name given.
      // If we get more than one, put underneath the first as parent.
      // Ideally want to use newVersion to get latest version. Start
      // with random version.
      ContentName argName = ContentName.fromURI(args[CommonParameters.startArg]);

      CCNHandle handle = CCNHandle.open();

      if (args.length == (CommonParameters.startArg + 2)) {
        if (CommonParameters.verbose)
          Log.info("ccnputfile: putting file " + args[CommonParameters.startArg + 1]);

        doPut(handle, args[CommonParameters.startArg + 1], argName);
        System.out.println("Inserted file " + args[CommonParameters.startArg + 1] + ".");
        if (CommonParameters.verbose)
          System.out.println(
              "ccnputfile took: " + (System.currentTimeMillis() - starttime) + " ms");
        System.exit(0);
      } else {
        for (int i = CommonParameters.startArg + 1; i < args.length; ++i) {

          // put as child of name
          ContentName nodeName = ContentName.fromURI(argName, args[i]);

          doPut(handle, args[i], nodeName);
          // leave this one as always printing for now
          System.out.println("Inserted file " + args[i] + ".");
        }
        if (CommonParameters.verbose)
          System.out.println(
              "ccnputfile took: " + (System.currentTimeMillis() - starttime) + " ms");
        System.exit(0);
      }
    } catch (ConfigurationException e) {
      System.out.println("Configuration exception in put: " + e.getMessage());
      e.printStackTrace();
    } catch (MalformedContentNameStringException e) {
      System.out.println(
          "Malformed name: " + args[CommonParameters.startArg] + " " + e.getMessage());
      e.printStackTrace();
    } catch (IOException e) {
      System.out.println("Cannot put file. " + e.getMessage());
      e.printStackTrace();
    } catch (InvalidKeyException e) {
      System.out.println("Cannot publish invalid key: " + e.getMessage());
      e.printStackTrace();
    }
    System.exit(1);
  }