List of usage examples for com.google.common.collect Lists newArrayList
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements)
From source file:cn.com.warlock.streaming.JavaNetworkWordCount.java
public static void main(String[] args) { if (args.length < 2) { System.err.println("Usage: JavaNetworkWordCount <hostname> <port>"); System.exit(1);/*from w ww .j a v a 2 s .c om*/ } SparkConf sparkConf = new SparkConf().setAppName("JavaNetworkWordCount"); // StreamingContext,?? JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, Durations.seconds(1)); // socket stream JavaReceiverInputDStream<String> lines = ssc.socketTextStream(args[0], Integer.parseInt(args[1]), StorageLevels.MEMORY_AND_DISK_SER); JavaDStream<String> words = lines.flatMap(new FlatMapFunction<String, String>() { @Override public Iterable<String> call(String x) { return Lists.newArrayList(SPACE.split(x)); } }); JavaPairDStream<String, Integer> wordCounts = words.mapToPair(new PairFunction<String, String, Integer>() { @Override public Tuple2<String, Integer> call(String s) { return new Tuple2<String, Integer>(s, 1); } }).reduceByKey(new Function2<Integer, Integer, Integer>() { @Override public Integer call(Integer i1, Integer i2) { return i1 + i2; } }); wordCounts.print(); ssc.start(); ssc.awaitTermination(); }
From source file:com.wiwit.eplweb.test.MyUploads.java
/** * Authorize the user, call the youtube.channels.list method to retrieve * the playlist ID for the list of videos uploaded to the user's channel, * and then call the youtube.playlistItems.list method to retrieve the * list of videos in that playlist./*from w w w . j a va2 s. co m*/ * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for read-only access to the // authenticated user's account, but not other types of account access. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "youtube"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("eplweb").build(); // Call the API's channels.list method to retrieve the // resource that represents the authenticated user's channel. // In the API response, only include channel information needed for // this use case. The channel's contentDetails part contains // playlist IDs relevant to the channel, including the ID for the // list that contains videos uploaded to the channel. YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails"); channelRequest.setMine(true); channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo"); ChannelListResponse channelResult = channelRequest.execute(); System.out.println("totalResult " + channelResult.getPageInfo().getResultsPerPage()); List<Channel> channelsList = channelResult.getItems(); if (channelsList != null) { // The user's default channel is the first item in the list. // Extract the playlist ID for the channel's videos from the // API response. String uploadPlaylistId = channelsList.get(0).getContentDetails().getRelatedPlaylists() .getUploads(); System.out.println("uploadPlaylistId : " + uploadPlaylistId); // Define a list to store items in the list of uploaded videos. List<PlaylistItem> playlistItemList = new ArrayList<PlaylistItem>(); // Retrieve the playlist of the channel's uploaded videos. YouTube.PlaylistItems.List playlistItemRequest = youtube.playlistItems() .list("id,contentDetails,snippet"); playlistItemRequest.setPlaylistId(uploadPlaylistId); // Only retrieve data used in this application, thereby making // the application more efficient. See: // https://developers.google.com/youtube/v3/getting-started#partial playlistItemRequest.setFields( "items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo"); String nextToken = ""; // Call the API one or more times to retrieve all items in the // list. As long as the API response returns a nextPageToken, // there are still more items to retrieve. do { playlistItemRequest.setPageToken(nextToken); PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute(); playlistItemList.addAll(playlistItemResult.getItems()); nextToken = playlistItemResult.getNextPageToken(); } while (nextToken != null); // Prints information about the results. prettyPrint(playlistItemList.size(), playlistItemList.iterator()); } } catch (GoogleJsonResponseException e) { e.printStackTrace(); System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.google.api.services.samples.youtube.cmdline.reporting.CreateReportingJob.java
/** * Create a reporting job./*from www. ja va 2s. co m*/ * * @param args command line args (not used). */ public static void main(String[] args) { /* * This OAuth 2.0 access scope allows for read access to the YouTube Analytics monetary reports for * authenticated user's account. Any request that retrieves earnings or ad performance metrics must * use this scope. */ List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/yt-analytics-monetary.readonly"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "createreportingjob"); // This object is used to make YouTube Reporting API requests. youtubeReporting = new YouTubeReporting.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-createreportingjob-sample").build(); // Prompt the user to specify the name of the job to be created. String name = getNameFromUser(); if (listReportTypes()) { createReportingJob(getReportTypeIdFromUser(), name); } } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } catch (Throwable t) { System.err.println("Throwable: " + t.getMessage()); t.printStackTrace(); } }
From source file:tv.icntv.log.tools.Tools.java
public static void main(String[] args) throws ParseException, IOException { CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(init(), args); Api api = new FileApi(); long time = System.nanoTime(); String input = line.getOptionValue("I"); List<String> inputStr = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().split(input)); // List<Path> paths = Lists.transform(inputStr,new Function<String, Path>() { // @Override // public Path apply(java.lang.String input) { // System.out.println("input ="+input); // try{ // Path path = new Path(input); //To change body of implemented methods use File | Settings | File Templates. // }catch (Exception e){ // return null; // } // if() // } // }); FileSystem fileSystem = FileSystem.get(new Configuration()); List<Path> paths = Lists.newArrayList(); for (String str : inputStr) { Path path = null;/*from w ww. j av a 2 s. c o m*/ try { path = new Path(str); if (fileSystem.exists(path)) { System.out.println(" add path .." + str); paths.add(path); } } catch (Exception e) { continue; } } if (null == paths || paths.isEmpty()) { System.out.println("input 2 path null"); } String regular = line.getOptionValue("R"); if (Strings.isNullOrEmpty(regular)) { regular = "part-m-\\d*.lzo"; } System.out.println("regular = " + regular); boolean test = api.writeDat(paths.toArray(new Path[paths.size()]), regular, new Path(line.getOptionValue("Out"))); System.out.println(test + "\t" + (System.nanoTime() - time) / Math.pow(10, 9)); }
From source file:pl.edu.icm.cermine.bx.DocumentNumberOfZonesFilter.java
public static void main(String[] args) throws TransformationException, IOException, AnalysisException, ParseException, CloneNotSupportedException { Options options = new Options(); options.addOption("input", true, "input path"); options.addOption("output", true, "output path"); CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); String inDir = line.getOptionValue("input"); String outDir = line.getOptionValue("output"); File dir = new File(inDir); Collection<File> files = FileUtils.listFiles(dir, new String[] { "xml" }, true); int i = 1;/*from w w w.ja va2s . c o m*/ for (File f : files) { TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); List<BxPage> pages = tvReader.read(new FileReader(f)); BxDocument doc = new BxDocument().setPages(pages); doc.setFilename(f.getName()); int size = Lists.newArrayList(doc.asZones()).size(); System.out.println(doc.getFilename() + " " + size + " " + (i * 100. / files.size())); File f2 = new File(outDir + doc.getFilename().replaceAll("cerm.xml", size + ".cerm.xml")); FileUtils.copyFile(f, f2); i++; } }
From source file:com.google.api.services.samples.youtube.cmdline.data.InvideoProgramming.java
/** * This code sample demonstrates different ways that the API can be used to * promote your channel content. It includes code for the following tasks: * <ol>//from ww w. j a va 2 s.co m * <li>Feature a video.</li> * <li>Feature a link to a social media channel.</li> * <li>Set a watermark for videos on your channel.</li> * </ol> * * @param args command line args (not used). */ public static void main(String[] args) { // This OAuth 2.0 access scope allows for full read/write access to the // authenticated user's account. List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "invideoprogramming"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName("youtube-cmdline-invideoprogramming-sample").build(); // Construct a request to retrieve the current user's channel ID. // In the API response, only include channel information needed for // this use case. The channel's uploads playlist identifies the // channel's most recently uploaded video. // See https://developers.google.com/youtube/v3/docs/channels/list ChannelListResponse channelListResponse = youtube.channels().list("id,contentDetails").setMine(true) .setFields("items(contentDetails/relatedPlaylists/uploads,id)").execute(); // The user's default channel is the first item in the list. If the // user does not have a channel, this code should throw a // GoogleJsonResponseException explaining the issue. Channel myChannel = channelListResponse.getItems().get(0); String channelId = myChannel.getId(); // The promotion appears 15000ms (15 seconds) before the video ends. InvideoTiming invideoTiming = new InvideoTiming(); invideoTiming.setOffsetMs(BigInteger.valueOf(15000l)); invideoTiming.setType("offsetFromEnd"); // This is one type of promotion and promotes a video. PromotedItemId promotedItemId = new PromotedItemId(); promotedItemId.setType("video"); promotedItemId.setVideoId(FEATURED_VIDEO_ID); // Set a custom message providing additional information about the // promoted video or your channel. PromotedItem promotedItem = new PromotedItem(); promotedItem.setCustomMessage("Check out this video about WebM!"); promotedItem.setId(promotedItemId); // Construct an object representing the invideo promotion data, and // add it to the channel. InvideoPromotion invideoPromotion = new InvideoPromotion(); invideoPromotion.setDefaultTiming(invideoTiming); invideoPromotion.setItems(Lists.newArrayList(promotedItem)); Channel channel = new Channel(); channel.setId(channelId); channel.setInvideoPromotion(invideoPromotion); Channel updateChannelResponse = youtube.channels().update("invideoPromotion", channel).execute(); // Print data from the API response. System.out.println("\n================== Updated Channel Information ==================\n"); System.out.println("\t- Channel ID: " + updateChannelResponse.getId()); InvideoPromotion promotions = updateChannelResponse.getInvideoPromotion(); promotedItem = promotions.getItems().get(0); // We only care about the first item System.out.println("\t- Invideo promotion video ID: " + promotedItem.getId().getVideoId()); System.out.println("\t- Promotion message: " + promotedItem.getCustomMessage()); // In-video programming can also be used to feature links to // associated websites, merchant sites, or social networking sites. // The code below overrides the promotional video set above by // featuring a link to the YouTube Developers Twitter feed. PromotedItemId promotedTwitterFeed = new PromotedItemId(); promotedTwitterFeed.setType("website"); promotedTwitterFeed.setWebsiteUrl("https://twitter.com/youtubedev"); promotedItem = new PromotedItem(); promotedItem.setCustomMessage("Follow us on Twitter!"); promotedItem.setId(promotedTwitterFeed); invideoPromotion.setItems(Lists.newArrayList(promotedItem)); channel.setInvideoPromotion(invideoPromotion); // Call the API to set the in-video promotion data. updateChannelResponse = youtube.channels().update("invideoPromotion", channel).execute(); // Print data from the API response. System.out.println("\n================== Updated Channel Information ==================\n"); System.out.println("\t- Channel ID: " + updateChannelResponse.getId()); promotions = updateChannelResponse.getInvideoPromotion(); promotedItem = promotions.getItems().get(0); System.out.println("\t- Invideo promotion URL: " + promotedItem.getId().getWebsiteUrl()); System.out.println("\t- Promotion message: " + promotedItem.getCustomMessage()); // This example sets a custom watermark for the channel. The image // used is the watermark.jpg file in the "resources/" directory. InputStreamContent mediaContent = new InputStreamContent("image/jpeg", InvideoProgramming.class.getResourceAsStream("/watermark.jpg")); // Indicate that the watermark should display during the last 15 // seconds of the video. InvideoTiming watermarkTiming = new InvideoTiming(); watermarkTiming.setType("offsetFromEnd"); watermarkTiming.setDurationMs(BigInteger.valueOf(15000l)); watermarkTiming.setOffsetMs(BigInteger.valueOf(15000l)); InvideoBranding invideoBranding = new InvideoBranding(); invideoBranding.setTiming(watermarkTiming); youtube.watermarks().set(channelId, invideoBranding, mediaContent).execute(); } catch (GoogleJsonResponseException e) { System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); e.printStackTrace(); } }
From source file:io.urmia.job.JobZkPublish.java
public static void main(String[] args) throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_SERVER, new ExponentialBackoffRetry(1000, 3)); client.start();/* w w w .j av a2s . c o m*/ // create my node String hostname = InetAddress.getLocalHost().getHostName(); String jobs = "/urmia/1/" + hostname + "/jobs"; JobExec lsJob = new JobExec.Shell("ls"); JobDefinition.Phase lsJobPhase = new JobDefinition.Phase(lsJob); JobDefinition jobDef = new JobDefinition("tck", Lists.newArrayList(lsJobPhase)); byte[] lsJobBytes = jobDef.toString().getBytes(); if (client.checkExists().forPath(jobs) == null) client.create().withMode(CreateMode.PERSISTENT).forPath(jobs); String i = new RandomUuidImpl().next(); log.info("creating job: {}", i); String p = jobs + "/" + i; client.create().withMode(CreateMode.PERSISTENT).forPath(p, lsJobBytes); String ip = p + "/live/in"; QueueBuilder<JobInput> builder = QueueBuilder.builder(client, null, serializer, ip); Thread.sleep(500); DistributedQueue<JobInput> q = builder.buildQueue(); q.start(); q.put(new LineJobInput("/")); q.put(new LineJobInput("/tmp")); q.put(END); q.flushPuts(1, TimeUnit.SECONDS); Thread.sleep(1000); }
From source file:com.weibangong.spark.mllib.JavaFPGrowthExample.java
public static void main(String[] args) { String inputFile;/*w ww .j a v a 2s .c o m*/ double minSupport = 0.3; int numPartition = -1; if (args.length < 1) { System.err.println("Usage: JavaFPGrowth <input_file> [minSupport] [numPartition]"); System.exit(1); } inputFile = args[0]; if (args.length >= 2) { minSupport = Double.parseDouble(args[1]); } if (args.length >= 3) { numPartition = Integer.parseInt(args[2]); } SparkConf sparkConf = new SparkConf().setAppName("JavaFPGrowthExample"); JavaSparkContext sc = new JavaSparkContext(sparkConf); JavaRDD<ArrayList<String>> transactions = sc.textFile(inputFile) .map(new Function<String, ArrayList<String>>() { @Override public ArrayList<String> call(String s) { return Lists.newArrayList(s.split(" ")); } }); FPGrowthModel<String> model = new FPGrowth().setMinSupport(minSupport).setNumPartitions(numPartition) .run(transactions); for (FPGrowth.FreqItemset<String> s : model.freqItemsets().toJavaRDD().collect()) { System.out.println("[" + Joiner.on(",").join(s.javaItems()) + "], " + s.freq()); } sc.stop(); }
From source file:org.apache.distributedlog.basic.ConsoleProxyMultiWriter.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;/*from w w w. j a v a 2s.c om*/ } String finagleNameStr = args[0]; final String streamList = args[1]; DistributedLogClient client = DistributedLogClientBuilder.newBuilder() .clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer") .thriftmux(true).finagleNameStr(finagleNameStr).build(); String[] streamNameList = StringUtils.split(streamList, ','); DistributedLogMultiStreamWriter multiStreamWriter = DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList(streamNameList)).bufferSize(0).client(client).flushIntervalMs(0) .firstSpeculativeTimeoutMs(10000).maxSpeculativeTimeoutMs(20000).requestTimeoutMs(50000).build(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() { @Override public void onFailure(Throwable cause) { System.out.println("Encountered error on writing data"); cause.printStackTrace(System.err); Runtime.getRuntime().exit(0); } @Override public void onSuccess(DLSN value) { // done } }); } multiStreamWriter.close(); client.close(); }
From source file:com.twitter.distributedlog.basic.ConsoleProxyMultiWriter.java
public static void main(String[] args) throws Exception { if (2 != args.length) { System.out.println(HELP); return;/* w w w. j av a 2s . co m*/ } String finagleNameStr = args[0]; final String streamList = args[1]; DistributedLogClient client = DistributedLogClientBuilder.newBuilder() .clientId(ClientId.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true) .finagleNameStr(finagleNameStr).build(); String[] streamNameList = StringUtils.split(streamList, ','); DistributedLogMultiStreamWriter multiStreamWriter = DistributedLogMultiStreamWriter.newBuilder() .streams(Lists.newArrayList(streamNameList)).bufferSize(0).client(client).flushIntervalMs(0) .firstSpeculativeTimeoutMs(10000).maxSpeculativeTimeoutMs(20000).requestTimeoutMs(50000).build(); // Setup Terminal Terminal terminal = Terminal.setupTerminal(); ConsoleReader reader = new ConsoleReader(); String line; while ((line = reader.readLine(PROMPT_MESSAGE)) != null) { multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))) .addEventListener(new FutureEventListener<DLSN>() { @Override public void onFailure(Throwable cause) { System.out.println("Encountered error on writing data"); cause.printStackTrace(System.err); Runtime.getRuntime().exit(0); } @Override public void onSuccess(DLSN value) { // done } }); } multiStreamWriter.close(); client.close(); }