/** @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); }
/** @param args */ public static void main(String[] args) { String extraUsage = ""; Log.setDefaultLevel(Level.WARNING); try { int offset = 0; SaveType type = SaveType.REPOSITORY; for (int i = 0; i < args.length; i++) { if (i == 0 && args[0].startsWith("[")) { extraUsage = args[0]; offset++; continue; } else if (args[i].equals("-h")) { usage(extraUsage); System.exit(0); } else if (!args[i].startsWith("-")) break; if (args[i].equals("-q")) { Log.setDefaultLevel(Level.WARNING); offset++; } if (args[i].equals("-r")) { type = SaveType.RAW; offset++; } } if (args.length - offset < 2) { usage(extraUsage); System.exit(1); } boolean hasAs = false; if (args.length - offset > 2) { if (args[offset + 2].equals("-as")) hasAs = true; else { usage(extraUsage); System.exit(1); } } ContentName linkName = ContentName.fromURI(args[offset++]); ContentName targetName = ContentName.fromURI(args[offset++]); Tuple<Integer, CCNHandle> tuple = null; if (hasAs) { tuple = CreateUserData.handleAs(args, offset); if (null == tuple) { usage(extraUsage); System.exit(1); } } // Can also use command line system properties and environment variables to // point this handle to the correct user. CCNHandle handle = ((null == tuple) || (null == tuple.second())) ? CCNHandle.getHandle() : tuple.second(); LinkObject theLink = new LinkObject(linkName, new Link(targetName), type, handle); theLink.save(); theLink.close(); System.out.println("Created link: " + theLink); handle.close(); } catch (Exception e) { handleException("Error: cannot initialize device. ", e); System.exit(-3); } }