public static void main(String[] args) {
		BasicConfigurator.configure(new ConsoleAppender(
			new PatternLayout("%d [%-25t] %-5p: %m%n")));

		if (args.length != 1 && args.length != 3) {
			System.err.println("usage: Torrent <torrent> [announce url] " +
				"[file|directory]");
			System.exit(1);
		}

		try {
			File outfile = new File(args[0]);

			/*
			 * If only one argument is provided, we just want to get
			 * information about the torrent. Load the torrent to trigger the
			 * information dump and exit.
			 */
			if (args.length == 1) {
				logger.info("Dumping information on torrent {}...",
					outfile.getAbsolutePath());
				Torrent.load(outfile, null);
				System.exit(0);
			}

			URL announce = new URL(args[1]);
			File source = new File(args[2]);
			if (!source.exists() || !source.canRead()) {
				throw new IllegalArgumentException(
					"Cannot access source file or directory " +
					source.getName());
			}

			String creator = String.format("%s (ttorrent)",
				System.getProperty("user.name"));

			Torrent torrent = null;
			if (source.isDirectory()) {
				torrent = Torrent.create(source,
					Arrays.asList(source.listFiles()),
					announce, creator);
			} else {
				torrent = Torrent.create(source, announce, creator);
			}

			torrent.save(outfile);
		} catch (Exception e) {
			logger.error("{}", e.getMessage(), e);
			System.exit(2);
		}
	}