List of usage examples for java.util List add
boolean add(E e);
From source file:com.home.ln_spring.ch8.sample.AnnotationJdbcDaoSample.java
public static void main(String[] args) { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.load("classpath:ch8/app-context-annotation.xml"); context.refresh();/*from ww w. j ava 2 s . c o m*/ ContactDao contactDao = context.getBean("contactDao", ContactDao.class); List<Contact> contacts = contactDao.findAll(); listContacts(contacts); System.out.println("Find by first name: "); contacts = contactDao.findByFirstName("Clarence"); listContacts(contacts); // System.out.println("Update contact with id : "); // Contact contact = new Contact(); // contact.setId(2); // contact.setFirstName("Jack"); // contact.setLastName("Rodwell"); // contact.setBirthDate( // new Date((new GregorianCalendar(1987, 1, 8)).getTime().getTime())); // contactDao.update(contact); // // contacts = contactDao.findAll(); // listContacts(contacts); // System.out.println("Insert contact"); // System.out.println(); // Contact contact1 = new Contact(); // contact1.setFirstName("Rod"); // contact1.setLastName("Johnson"); // contact1.setBirthDate( // new Date((new GregorianCalendar(1987, 1, 8)).getTime().getTime())); // contactDao.insert(contact1); // // contacts = contactDao.findAll(); // listContacts(contacts); System.out.println("Insert with BatchSqlUpdate"); System.out.println(); Contact contact2 = new Contact(); contact2.setFirstName("Michael"); contact2.setLastName("Jackson"); contact2.setBirthDate(new Date((new GregorianCalendar(1964, 10, 1)).getTime().getTime())); List<ContactTelDetail> contactTelDetails = new ArrayList<ContactTelDetail>(); ContactTelDetail contactTelDetail = new ContactTelDetail(); contactTelDetail.setTelType("Home"); contactTelDetail.setTelNumber("111111"); contactTelDetails.add(contactTelDetail); contactTelDetail = new ContactTelDetail(); contactTelDetail.setTelType("Mobile"); contactTelDetail.setTelNumber("222222"); contactTelDetails.add(contactTelDetail); contact2.setContactTelDetails(contactTelDetails); contactDao.insertWithDetail(contact2); contacts = contactDao.findAllWithDetail(); listContacts(contacts); }
From source file:com.turn.ttorrent.cli.TorrentMain.java
/** * Torrent reader and creator./* w w w . j av a 2s .com*/ * * <p> * You can use the {@code main()} function of this class to read or create * torrent files. See usage for details. * </p> * */ public static void main(String[] args) { BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p: %m%n"))); CmdLineParser parser = new CmdLineParser(); CmdLineParser.Option help = parser.addBooleanOption('h', "help"); CmdLineParser.Option filename = parser.addStringOption('t', "torrent"); CmdLineParser.Option create = parser.addBooleanOption('c', "create"); CmdLineParser.Option pieceLength = parser.addIntegerOption('l', "length"); CmdLineParser.Option announce = parser.addStringOption('a', "announce"); try { parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage()); usage(System.err); System.exit(1); } // Display help and exit if requested if (Boolean.TRUE.equals((Boolean) parser.getOptionValue(help))) { usage(System.out); System.exit(0); } String filenameValue = (String) parser.getOptionValue(filename); if (filenameValue == null) { usage(System.err, "Torrent file must be provided!"); System.exit(1); } Integer pieceLengthVal = (Integer) parser.getOptionValue(pieceLength); if (pieceLengthVal == null) { pieceLengthVal = Torrent.DEFAULT_PIECE_LENGTH; } else { pieceLengthVal = pieceLengthVal * 1024; } logger.info("Using piece length of {} bytes.", pieceLengthVal); Boolean createFlag = (Boolean) parser.getOptionValue(create); //For repeated announce urls @SuppressWarnings("unchecked") Vector<String> announceURLs = (Vector<String>) parser.getOptionValues(announce); String[] otherArgs = parser.getRemainingArgs(); if (Boolean.TRUE.equals(createFlag) && (otherArgs.length != 1 || announceURLs.isEmpty())) { usage(System.err, "Announce URL and a file or directory must be " + "provided to create a torrent file!"); System.exit(1); } OutputStream fos = null; try { if (Boolean.TRUE.equals(createFlag)) { if (filenameValue != null) { fos = new FileOutputStream(filenameValue); } else { fos = System.out; } //Process the announce URLs into URIs List<URI> announceURIs = new ArrayList<URI>(); for (String url : announceURLs) { announceURIs.add(new URI(url)); } //Create the announce-list as a list of lists of URIs //Assume all the URI's are first tier trackers List<List<URI>> announceList = new ArrayList<List<URI>>(); announceList.add(announceURIs); File source = new File(otherArgs[0]); 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()) { List<File> files = new ArrayList<File>( FileUtils.listFiles(source, TrueFileFilter.TRUE, TrueFileFilter.TRUE)); Collections.sort(files); torrent = Torrent.create(source, files, pieceLengthVal, announceList, creator); } else { torrent = Torrent.create(source, pieceLengthVal, announceList, creator); } torrent.save(fos); } else { Torrent.load(new File(filenameValue), true); } } catch (Exception e) { logger.error("{}", e.getMessage(), e); System.exit(2); } finally { if (fos != System.out) { IOUtils.closeQuietly(fos); } } }
From source file:com.ok2c.lightmtp.examples.SendMailExample.java
public static void main(final String[] args) throws Exception { if (args.length < 3) { System.out.println("Usage: sender recipient1[;recipient2;recipient3;...] file"); System.exit(0);/*from w w w . j a v a 2 s. co m*/ } String sender = args[0]; List<String> recipients = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(args[1], ";"); while (tokenizer.hasMoreTokens()) { String s = tokenizer.nextToken(); s = s.trim(); if (s.length() > 0) { recipients.add(s); } } File src = new File(args[2]); if (!src.exists()) { System.out.println("File '" + src + "' does not exist"); System.exit(0); } DeliveryRequest request = new BasicDeliveryRequest(sender, recipients, new FileSource(src)); MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT); mua.start(); try { InetSocketAddress address = new InetSocketAddress("localhost", 2525); Future<DeliveryResult> future = mua.deliver(new SessionEndpoint(address), 0, request, null); DeliveryResult result = future.get(); System.out.println("Delivery result: " + result); } finally { mua.shutdown(); } }
From source file:com.playonlinux.utils.cab.Cabfile.java
public static void main(String[] args) throws CabException, IOException { File tahoma32 = new File("/Users/tinou/Downloads/arial32.exe"); Cabfile cabfile = new Cabfile(tahoma32); int offset = cabfile.findCabOffset(); System.out.println(offset);//from ww w. java 2 s .c o m CFHeader header = cabfile.getHeader(); List<CFFolder> cfFolders = new ArrayList<>(); for (int i = 0; i < header.getNumberOfFolders(); i++) { CFFolder cfFolder = cabfile.getFolder(); cfFolders.add(cfFolder); System.out.println(cfFolder); } cabfile.jumpTo(header.coffFiles[0]); List<CFFile> cfiles = new ArrayList<>(); for (int i = 0; i < header.getNumberOfFiles(); i++) { CFFile cfile = cabfile.getFile(); cfiles.add(cfile); System.out.println(cfile); } CFData cfData = cabfile.getData(CompressionType.NONE); System.out.println(cfData); System.out.println(Hex.encodeHexString(cfData.ab)); CFData cfData2 = cabfile.getData(CompressionType.NONE); System.out.println(cfData2); System.out.println(Hex.encodeHexString(cfData2.ab)); /* for(CFFile cfFile: cfiles) { if("fontinst.inf".equals(cfFile.getFilename())) { CFFolder cfFolder = cfFolders.get((int) cfFile.getFolderIndex()); long dataIndex = cfFolder.getOffsetStartData() + cfFile.getOffsetStartDataInsideFolder(); System.out.print("Index: "); System.out.println(dataIndex); cabfile.jumpTo(dataIndex); CFData cfData = cabfile.getData(); cfFolder.dump(); System.out.println(cfFile); System.out.println(cfData); File test = new File("/tmp/test"); FileOutputStream stream = new FileOutputStream(test); stream.write(cfData.ab); System.out.println(Arrays.toString(cfData.ab)); } } */ }
From source file:edu.harvard.med.screensaver.io.screens.StudyCreator.java
@SuppressWarnings("static-access") public static void main(String[] args) { final CommandLineApplication app = new CommandLineApplication(args); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name") .withLongOpt("lead-screener-first-name").create("lf")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name") .withLongOpt("lead-screener-last-name").create("ll")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email") .withLongOpt("lead-screener-email").create("le")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name") .withLongOpt("lab-head-first-name").create("hf")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name") .withLongOpt("lab-head-last-name").create("hl")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email") .withLongOpt("lab-head-email").create("he")); List<String> desc = new ArrayList<String>(); for (ScreenType t : EnumSet.allOf(ScreenType.class)) desc.add(t.name()); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("screen type") .withLongOpt("screen-type").withDescription(StringUtils.makeListString(desc, ", ")).create("y")); desc.clear();// w w w . j a v a 2s . co m for (StudyType t : EnumSet.allOf(StudyType.class)) desc.add(t.name()); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("study type") .withLongOpt("study-type").withDescription(StringUtils.makeListString(desc, ", ")).create("yy")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("summary").withLongOpt("summary").create("s")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("title").withLongOpt("title").create("t")); app.addCommandLineOption( OptionBuilder.hasArg().withArgName("protocol").withLongOpt("protocol").create("p")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("#").withLongOpt("facilityId").create("i")); app.addCommandLineOption(OptionBuilder.hasArg(false).withLongOpt("replace") .withDescription("replace an existing Screen with the same facilityId").create("r")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-wellkey") .withDescription("default value is to key by reagent vendor id").create("keyByWellId")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-facility-id") .withDescription("default value is to key by reagent vendor id").create("keyByFacilityId")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-compound-name") .withDescription("default value is to key by reagent vendor id").create("keyByCompoundName")); app.addCommandLineOption(OptionBuilder.withDescription( "optional: pivot the input col/rows so that the AT names are in Col1, and the AT well_id/rvi's are in Row1") .withLongOpt("annotation-names-in-col1").create("annotationNamesInCol1")); app.addCommandLineOption(OptionBuilder.hasArg().withArgName("file").withLongOpt("data-file").create("f")); app.addCommandLineOption(OptionBuilder.withArgName("parseLincsSpecificFacilityID") .withLongOpt("parseLincsSpecificFacilityID").create("parseLincsSpecificFacilityID")); app.processOptions(/* acceptDatabaseOptions= */true, /* acceptAdminUserOptions= */true); execute(app); }
From source file:com.martinlamas.dicomserver.DicomServer.java
public static void main(String[] args) { int port = DEFAULT_PORT; String aeTitle = DEFAULT_AE_TITLE; File storageDirectory = new File(DEFAULT_STORAGE_DIRECTORY); try {/*w ww . j a v a2 s.c om*/ CommandLine line = new DefaultParser().parse(getOptions(), args); if (line.hasOption("p")) port = Integer.valueOf(line.getOptionValue("p")); if (line.hasOption("d")) storageDirectory = new File(line.getOptionValue("d")); if (line.hasOption("t")) aeTitle = line.getOptionValue("t"); List<DicomServerApplicationEntity> applicationEntities = new ArrayList<DicomServerApplicationEntity>(); DicomServerApplicationEntity applicationEntity = new DicomServerApplicationEntity(aeTitle, storageDirectory); applicationEntities.add(applicationEntity); showBanner(); IDicomStoreSCPServer server = new DicomStoreSCPServer(port, applicationEntities); server.start(); } catch (ParseException e) { printUsage(); } catch (Exception e) { logger.error("Unable to start DICOM server: " + e.getMessage()); e.printStackTrace(); } }
From source file:alluxio.fuse.AlluxioFuse.java
/** * Running this class will mount the file system according to * the options passed to this function {@link #parseOptions(String[])}. * The user-space fuse application will stay on the foreground and keep * the file system mounted. The user can unmount the file system by * gracefully killing (SIGINT) the process. * * @param args arguments to run the command line */// ww w . j a v a2s .c o m public static void main(String[] args) { final AlluxioFuseOptions opts = parseOptions(args); if (opts == null) { System.exit(1); } final FileSystem tfs = FileSystem.Factory.get(); final AlluxioFuseFileSystem fs = new AlluxioFuseFileSystem(tfs, opts); final List<String> fuseOpts = opts.getFuseOpts(); // Force direct_io in FUSE: writes and reads bypass the kernel page // cache and go directly to alluxio. This avoids extra memory copies // in the write path. fuseOpts.add("-odirect_io"); try { fs.mount(Paths.get(opts.getMountPoint()), true, opts.isDebug(), fuseOpts.toArray(new String[0])); } finally { fs.umount(); } }
From source file:de.pniehus.odal.App.java
public static void main(String[] args) throws IOException { List<Filter> filters = new ArrayList<Filter>(); filters.add(new RegexFilter()); filters.add(new FileTypeFilter()); filters.add(new KeywordFilter()); filters.add(new BlacklistFilter()); Profile p = parseArgs(args, filters); String fileName = "log-" + new Date().toString().replace(":", "-") + ".txt"; fileName = fileName.replace(" ", "-"); File logPath = new File(p.getLogDirectory() + fileName); if (!logPath.getParentFile().isDirectory() && !logPath.getParentFile().mkdirs()) { logPath = new File(fileName); }//from w w w .j av a 2s . com if (logPath.getParentFile().canWrite() || logPath.getParentFile().setWritable(true)) { SimpleLoggingSetup.configureRootLogger(logPath.getAbsolutePath(), p.getLogLevel(), !p.isSilent()); } else { Logger root = Logger.getLogger(""); for (Handler h : root.getHandlers()) { // Removing default console handlers if (h instanceof ConsoleHandler) { root.removeHandler(h); } } ConsolePrintLogHandler cplh = new ConsolePrintLogHandler(); cplh.setFormatter(new ScribblerLogFormat(SimpleLoggingSetup.DEFAULT_DATE_FORMAT)); root.addHandler(cplh); System.out.println("Unable to create log: insufficient permissions!"); } Logger.getLogger("").setLevel(p.getLogLevel()); mainLogger = Logger.getLogger(App.class.getCanonicalName()); untrustedSSLSetup(); mainLogger.info("Successfully intitialized ODAL"); if (!p.isLogging()) mainLogger.setLevel(Level.OFF); if (p.isWindowsConsoleMode() && !p.isLogging()) { Logger root = Logger.getLogger(""); for (Handler h : root.getHandlers()) { if (h instanceof FileHandler) { root.removeHandler(h); // Removes FileHandler to allow console output through logging } } } OdalGui ogui = new OdalGui(p, filters); }
From source file:net.paissad.jcamstream.utils.FTPUtils.java
public static void main(String[] args) throws SocketException, IOException, FTPException { String user = "user"; String password = "pass"; String host = "ftp-server"; int port = FTPClient.DEFAULT_PORT; String dir = "/subdir/another_dir/foo/bar"; List<File> files = new ArrayList<File>(); files.add(new File("pom.xml")); files.add(new File("stuffs.txt")); FTPUtils ftp = new FTPUtils(user, password, host, port, dir); try {/*from w ww . jav a2 s . c o m*/ ftp.estabishConnection(); ftp.uploadFiles(files); } finally { ftp.logoutAndDisconnect(); } }
From source file:edu.uchicago.mpcs53013.crime_topology.CrimeTopology.java
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException { String zkIp = "hadoop-w-1.c.mpcs53013-2015.internal"; String zookeeperHost = zkIp + ":2181"; ZkHosts zkHosts = new ZkHosts(zookeeperHost); List<String> zkServers = new ArrayList<String>(); zkServers.add(zkIp); SpoutConfig kafkaConfig = new SpoutConfig(zkHosts, "acidreflux-crime-events", "/acidreflux-crime-events", "test_id"); kafkaConfig.scheme = new SchemeAsMultiScheme(new StringScheme()); kafkaConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime(); kafkaConfig.zkServers = zkServers;// ww w . j ava 2 s. co m kafkaConfig.zkRoot = "/acidreflux-crime-events"; kafkaConfig.zkPort = 2181; kafkaConfig.forceFromStart = true; KafkaSpout kafkaSpout = new KafkaSpout(kafkaConfig); TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("raw-crime-events", kafkaSpout, 1); builder.setBolt("filter-reports", new FilterReportsBolt(), 1).shuffleGrouping("raw-crime-events"); builder.setBolt("update-table", new UpdateCrimesBolt(), 1).fieldsGrouping("filter-reports", new Fields("ward")); Map conf = new HashMap(); conf.put(backtype.storm.Config.TOPOLOGY_WORKERS, 4); conf.put(backtype.storm.Config.TOPOLOGY_DEBUG, true); if (args != null && args.length > 0) { StormSubmitter.submitTopology(args[0], conf, builder.createTopology()); } else { LocalCluster cluster = new LocalCluster(); cluster.submitTopology("crime-topology", conf, builder.createTopology()); } }