List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.KratuMain.java
/** * Main method.//www. j a v a 2 s . c o m * * @param args the command line arguments. */ public static void main(String args[]) { // Proxy JaxWsProxySelector ps = new JaxWsProxySelector(ProxySelector.getDefault()); ProxySelector.setDefault(ps); Options options = createCommandLineOptions(); boolean errors = false; String propertiesPath = CLASSPATH_AW_REPORT_MODEL_PROPERTIES_LOCATION; try { CommandLineParser parser = new BasicParser(); CommandLine cmdLine = parser.parse(options, args); if (cmdLine.hasOption("file")) { propertiesPath = cmdLine.getOptionValue("file"); } System.out.println("Using properties from: " + propertiesPath); if (cmdLine.hasOption("startServer")) { // Start the Rest Server System.out.println("Starting Rest Server..."); initApplicationContextAndProperties(propertiesPath); updateAccounts(); RestServer.createRestServer(appCtx, propertiesPath); } else { if (cmdLine.hasOption("startDate") && cmdLine.hasOption("endDate")) { if (cmdLine.hasOption("processKratus")) { // Process Kratus, this process runs for the whole MCC // within the given dates and creates a daily Kratu per account. System.out.println("Starting Process Kratus..."); initApplicationContextAndProperties(propertiesPath); updateAccounts(); KratuProcessor kratuProcessor = appCtx.getBean(KratuProcessor.class); kratuProcessor.processKratus(cmdLine.getOptionValue("startDate"), cmdLine.getOptionValue("endDate")); System.exit(0); } else { // Download Reports, // this porcess downloads 7 report types for each account under the MCC System.out.println("Starting Download Reports porcess..."); AwReporting.main(args); System.exit(0); } } else { errors = true; System.out.println("Configuration incomplete. Missing options for command line."); } } } catch (IOException e) { errors = true; System.out.println("Properties file (" + propertiesPath + ") not found: " + e.getMessage()); } catch (ParseException e) { errors = true; System.out.println("Error parsing the values for the command line options: " + e.getMessage()); } catch (Exception e) { errors = true; System.out.println("Unexpected error: " + e.getMessage()); } if (errors) { printHelpMessage(options); System.exit(1); } }
From source file:com.mgmtp.perfload.perfmon.PerfMon.java
public static void main(final String[] args) { CommandLine cmd = parseArgs(args);//w ww. ja v a 2 s . c om if (cmd != null) { final Sigar sigar = new Sigar(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { sigar.close(); } }); if (cmd.hasOption('s')) { shutdown(sigar); return; } long interval = Long.parseLong(cmd.getOptionValue('i', "5")); String fileName = cmd.getOptionValue('f'); boolean java = cmd.hasOption('j'); boolean tcp = cmd.hasOption('t'); boolean netstat = cmd.hasOption('n'); OutputHandler outputHandler = fileName != null ? new FileOutputHandler(fileName) : new ConsoleOutputHandler(); try { outputHandler.open(); // Initialize Sigar libraries in order to fail fast. // Lazy initialization would cause perfMon to keep running logging errors all the time. // See https://github.com/mgm-tp/perfload/issues/3 Sigar.load(); SigarProxy sigarProxy = SigarProxyCache.newInstance(sigar); List<BasePerfMonCommand> commands = createCommandsList(java, tcp, netstat); final PerfMon perfMon = new PerfMon(sigarProxy, interval, commands, outputHandler); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { perfMon.runShutdownHook(); } }); perfMon.writeHeader(); perfMon.scheduleInformationGathering(); } catch (IOException ex) { LOG.error("Error opening output file: " + fileName, ex); } catch (SigarException ex) { LOG.error(ex.getMessage(), ex); } } }
From source file:com.netflix.suro.SuroServer.java
public static void main(String[] args) throws IOException { final AtomicReference<Injector> injector = new AtomicReference<Injector>(); try {//from w ww. ja va2 s .c o m // Parse the command line Options options = createOptions(); final CommandLine line = new BasicParser().parse(options, args); // Load the properties file final Properties properties = new Properties(); if (line.hasOption('p')) { properties.load(new FileInputStream(line.getOptionValue('p'))); } // Bind all command line options to the properties with prefix "SuroServer." for (Option opt : line.getOptions()) { String name = opt.getOpt(); String value = line.getOptionValue(name); String propName = PROP_PREFIX + opt.getArgName(); if (propName.equals(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY)) { properties.setProperty(DynamicPropertyRoutingMapConfigurator.ROUTING_MAP_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertySinkConfigurator.SINK_PROPERTY)) { properties.setProperty(DynamicPropertySinkConfigurator.SINK_PROPERTY, FileUtils.readFileToString(new File(value))); } else if (propName.equals(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY)) { properties.setProperty(DynamicPropertyInputConfigurator.INPUT_CONFIG_PROPERTY, FileUtils.readFileToString(new File(value))); } else { properties.setProperty(propName, value); } } create(injector, properties); injector.get().getInstance(LifecycleManager.class).start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } catch (IOException e) { // do nothing because Closeables.close will swallow IOException } } }); waitForShutdown(getControlPort(properties)); } catch (Throwable e) { System.err.println("SuroServer startup failed: " + e.getMessage()); System.exit(-1); } finally { Closeables.close(injector.get().getInstance(LifecycleManager.class), true); } }
From source file:eu.ensure.aging.AgingSimulator.java
public static void main(String[] args) { Options options = new Options(); options.addOption("n", "flip-bit-in-name", true, "Flip bit in first byte of name of first file"); options.addOption("u", "flip-bit-in-uname", true, "Flip bit in first byte of username of first file"); options.addOption("c", "update-checksum", true, "Update header checksum (after prior bit flips)"); Properties properties = new Properties(); CommandLineParser parser = new PosixParser(); try {//from w w w. j a v a 2s .c o m CommandLine line = parser.parse(options, args); // if (line.hasOption("flip-bit-in-name")) { properties.put("flip-bit-in-name", line.getOptionValue("flip-bit-in-name")); } else { // On by default (if not explicitly de-activated above) properties.put("flip-bit-in-name", "true"); } // if (line.hasOption("flip-bit-in-uname")) { properties.put("flip-bit-in-uname", line.getOptionValue("flip-bit-in-uname")); } else { properties.put("flip-bit-in-uname", "false"); } // if (line.hasOption("update-checksum")) { properties.put("update-checksum", line.getOptionValue("update-checksum")); } else { properties.put("update-checksum", "false"); } String[] fileArgs = line.getArgs(); if (fileArgs.length < 1) { printHelp(options, System.err); System.exit(1); } String srcPath = fileArgs[0]; File srcAIP = new File(srcPath); if (!srcAIP.exists()) { String info = "The source path does not locate a file: " + srcPath; System.err.println(info); System.exit(1); } if (srcAIP.isDirectory()) { String info = "The source path locates a directory, not a file: " + srcPath; System.err.println(info); System.exit(1); } if (!srcAIP.canRead()) { String info = "Cannot read source file: " + srcPath; System.err.println(info); System.exit(1); } boolean doReplace = false; File destAIP = null; if (fileArgs.length > 1) { String destPath = fileArgs[1]; destAIP = new File(destPath); if (destAIP.exists()) { String info = "The destination path locates an existing file: " + destPath; System.err.println(info); System.exit(1); } } else { doReplace = true; try { destAIP = File.createTempFile("tmp-aged-aip-", ".tar"); } catch (IOException ioe) { String info = "Failed to create temporary file: "; info += ioe.getMessage(); System.err.println(info); System.exit(1); } } String info = "Age simulation\n"; info += " Reading from " + srcAIP.getName() + "\n"; if (doReplace) { info += " and replacing it's content"; } else { info += " Writing to " + destAIP.getName(); } System.out.println(info); // InputStream is = null; OutputStream os = null; try { is = new BufferedInputStream(new FileInputStream(srcAIP)); os = new BufferedOutputStream(new FileOutputStream(destAIP)); simulateAging(srcAIP.getName(), is, os, properties); } catch (FileNotFoundException fnfe) { info = "Could not locate file: " + fnfe.getMessage(); System.err.println(info); } finally { try { if (null != os) os.close(); if (null != is) is.close(); } catch (IOException ignore) { } } // if (doReplace) { File renamedOriginal = new File(srcAIP.getName() + "-backup"); srcAIP.renameTo(renamedOriginal); ReadableByteChannel rbc = null; WritableByteChannel wbc = null; try { rbc = Channels.newChannel(new FileInputStream(destAIP)); wbc = Channels.newChannel(new FileOutputStream(srcAIP)); FileIO.fastChannelCopy(rbc, wbc); } catch (FileNotFoundException fnfe) { info = "Could not locate temporary output file: " + fnfe.getMessage(); System.err.println(info); } catch (IOException ioe) { info = "Could not copy temporary output file over original AIP: " + ioe.getMessage(); System.err.println(info); } finally { try { if (null != wbc) wbc.close(); if (null != rbc) rbc.close(); destAIP.delete(); } catch (IOException ignore) { } } } } catch (ParseException pe) { String info = "Failed to parse command line: " + pe.getMessage(); System.err.println(info); printHelp(options, System.err); System.exit(1); } }
From source file:edu.harvard.mcz.dwcaextractor.DwCaExtractor.java
public static void main(String[] args) { int exitState = 0; DwCaExtractor extractor = new DwCaExtractor(); if (extractor.setup(args)) { try {//from w w w.ja v a 2s . c o m extractor.extract(); } catch (IOException e) { logger.error(e.getMessage(), e); exitState = 2; } } else { logger.error("Failed to setup for extraction."); exitState = 1; } System.exit(exitState); }
From source file:com.google.api.services.samples.youtube.cmdline.data.Topics.java
/** * Execute a search request that starts by calling the Freebase API to * retrieve a topic ID matching a user-provided term. Then initialize a * YouTube object to search for YouTube videos and call the YouTube Data * API's youtube.search.list method to retrieve a list of videos associated * with the selected Freebase topic and with another search query term, * which the user also enters. Finally, display the titles, video IDs, and * thumbnail images for the first five videos in the YouTube Data API * response.//from www .j a v a 2 s. c o m * * @param args This application does not use command line arguments. */ public static void main(String[] args) { // Read the developer key from the properties file. Properties properties = new Properties(); try { InputStream in = Topics.class.getResourceAsStream("/" + PROPERTIES_FILENAME); properties.load(in); } catch (IOException e) { System.err.println("There was an error reading " + PROPERTIES_FILENAME + ": " + e.getCause() + " : " + e.getMessage()); System.exit(1); } try { // Retrieve a Freebase topic ID based on a user-entered query term. String topicsId = getTopicId(); if (topicsId.length() < 1) { System.out.println("No topic id will be applied to your search."); } // Prompt the user to enter a search query term. This term will be // used to retrieve YouTube search results related to the topic // selected above. String queryTerm = getInputQuery("search"); // This object is used to make YouTube Data API requests. The last // argument is required, but since we don't need anything // initialized when the HttpRequest is initialized, we override // the interface and provide a no-op function. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() { public void initialize(HttpRequest request) throws IOException { } }).setApplicationName("youtube-cmdline-search-sample").build(); YouTube.Search.List search = youtube.search().list("id,snippet"); // Set your developer key from the {{ Google Cloud Console }} for // non-authenticated requests. See: // {{ https://cloud.google.com/console }} String apiKey = properties.getProperty("youtube.apikey"); search.setKey(apiKey); search.setQ(queryTerm); if (topicsId.length() > 0) { search.setTopicId(topicsId); } // Restrict the search results to only include videos. See: // https://developers.google.com/youtube/v3/docs/search/list#type search.setType("video"); // To increase efficiency, only retrieve the fields that the // application uses. search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)"); search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED); SearchListResponse searchResponse = search.execute(); List<SearchResult> searchResultList = searchResponse.getItems(); if (searchResultList != null) { prettyPrint(searchResultList.iterator(), queryTerm, topicsId); } else { System.out.println("There were no results for your query."); } } catch (GoogleJsonResponseException e) { System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage()); e.printStackTrace(); } }
From source file:com.google.api.services.samples.youtube.cmdline.Topics.java
/** * Execute a search request that starts by calling the Freebase API to * retrieve a topic ID matching a user-provided term. Then initialize a * YouTube object to search for YouTube videos and call the YouTube Data * API's youtube.search.list method to retrieve a list of videos associated * with the selected Freebase topic and with another search query term, * which the user also enters. Finally, display the titles, video IDs, and * thumbnail images for the first five videos in the YouTube Data API * response.//from ww w .ja va2 s . c o m * * @param args This application does not use command line arguments. */ public static void main(String[] args) { // Read the developer key from the properties file. Properties properties = new Properties(); try { InputStream in = Topics.class.getResourceAsStream("/" + PROPERTIES_FILENAME); properties.load(in); } catch (IOException e) { System.err.println("There was an error reading " + PROPERTIES_FILENAME + ": " + e.getCause() + " : " + e.getMessage()); System.exit(1); } try { // Retrieve a Freebase topic ID based on a user-entered query term. String topicsId = getTopicId(); if (topicsId.length() < 1) { System.out.println("No topic id will be applied to your search."); } // Prompt the user to enter a search query term. This term will be // used to retrieve YouTube search results related to the topic // selected above. String queryTerm = getInputQuery("search"); // This object is used to make YouTube Data API requests. The last // argument is required, but since we don't need anything // initialized when the HttpRequest is initialized, we override // the interface and provide a no-op function. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() { public void initialize(HttpRequest request) throws IOException { } }).setApplicationName("youtube-cmdline-search-sample").build(); YouTube.Search.List search = youtube.search().list("id,snippet"); // Set your developer key from the Google Developers Console for // non-authenticated requests. See: // https://cloud.google.com/console String apiKey = properties.getProperty("youtube.apikey"); search.setKey(apiKey); search.setQ(queryTerm); if (topicsId.length() > 0) { search.setTopicId(topicsId); } // Restrict the search results to only include videos. See: // https://developers.google.com/youtube/v3/docs/search/list#type search.setType("video"); // To increase efficiency, only retrieve the fields that the // application uses. search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)"); search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED); SearchListResponse searchResponse = search.execute(); List<SearchResult> searchResultList = searchResponse.getItems(); if (searchResultList != null) { prettyPrint(searchResultList.iterator(), queryTerm, topicsId); } else { System.out.println("There were no results for your query."); } } catch (GoogleJsonResponseException e) { System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage()); e.printStackTrace(); } }
From source file:com.mycompany.javaapplicaton3.LerArquivo2.java
/** * @param args/*from w ww. j av a 2s .com*/ * @throws Exception */ public static void main(String[] args) throws Exception { String SAMPLE_PERSON_DATA_FILE_PATH = "C:/Users/lprates/Documents/arquivo2013.xlsx"; // Input File initialize File file = new File(SAMPLE_PERSON_DATA_FILE_PATH); InputStream inputStream = new FileInputStream(file); // Excel Cell Mapping Map<String, String> cellMapping0150 = new HashMap<String, String>(); cellMapping0150.put("HEADER", "REG,COD_PART,NOME,COD_PAIS,CNPJ,CPF,IE,COD_MUN,SUFRAMA,END,NUM,COMPL,BAIRRO,BPE_VIGENCIA_FIN"); cellMapping0150.put("A", "reg"); cellMapping0150.put("B", "codPart"); cellMapping0150.put("C", "nome"); cellMapping0150.put("D", "codPais"); cellMapping0150.put("E", "cnpj"); cellMapping0150.put("F", "cpf"); cellMapping0150.put("G", "ie"); cellMapping0150.put("H", "codMun"); cellMapping0150.put("I", "suframa"); cellMapping0150.put("J", "end"); cellMapping0150.put("K", "num"); cellMapping0150.put("L", "compl"); cellMapping0150.put("M", "bairro"); cellMapping0150.put("N", "bpeVigenciaFin"); // Excel Cell Mapping Map<String, String> cellMapping0200 = new HashMap<String, String>(); cellMapping0200.put("HEADER", "REG,COD_ITEM,DESCR_ITEM,COD_BARRA,COD_ANT_ITEM,UNID_INV,TIPO_ITEM,COD_NCM,EX_IPI,COD_GEN,COD_LST,ALIQ_ICMS"); cellMapping0200.put("A", "reg"); cellMapping0200.put("B", "codItem"); cellMapping0200.put("C", "descrItem"); cellMapping0200.put("D", "codBarra"); cellMapping0200.put("E", "codAntItem"); cellMapping0200.put("F", "unidInv"); cellMapping0200.put("G", "tipoItem"); cellMapping0200.put("H", "codNcm"); cellMapping0200.put("I", "exIpi"); cellMapping0200.put("J", "codGen"); cellMapping0200.put("K", "codLst"); cellMapping0200.put("L", "aliqIcms"); // Excel Cell Mapping Map<String, String> cellMappingC100_C170 = new HashMap<String, String>(); cellMappingC100_C170.put("A", "campo1"); cellMappingC100_C170.put("B", "campo2"); cellMappingC100_C170.put("C", "campo3"); cellMappingC100_C170.put("D", "campo4"); cellMappingC100_C170.put("E", "campo5"); cellMappingC100_C170.put("F", "campo6"); cellMappingC100_C170.put("G", "campo7"); cellMappingC100_C170.put("H", "campo8"); cellMappingC100_C170.put("I", "campo9"); cellMappingC100_C170.put("J", "campo10"); cellMappingC100_C170.put("K", "campo11"); cellMappingC100_C170.put("L", "campo12"); cellMappingC100_C170.put("M", "campo13"); cellMappingC100_C170.put("N", "campo14"); cellMappingC100_C170.put("O", "campo15"); cellMappingC100_C170.put("P", "campo16"); cellMappingC100_C170.put("Q", "campo17"); cellMappingC100_C170.put("R", "campo18"); cellMappingC100_C170.put("S", "campo19"); cellMappingC100_C170.put("T", "campo20"); cellMappingC100_C170.put("U", "campo21"); cellMappingC100_C170.put("V", "campo22"); cellMappingC100_C170.put("W", "campo23"); cellMappingC100_C170.put("X", "campo24"); cellMappingC100_C170.put("Y", "campo25"); cellMappingC100_C170.put("Z", "campo26"); cellMappingC100_C170.put("AA", "campo27"); cellMappingC100_C170.put("AB", "campo28"); cellMappingC100_C170.put("AC", "campo29"); cellMappingC100_C170.put("AD", "campo30"); cellMappingC100_C170.put("AE", "campo31"); cellMappingC100_C170.put("AF", "campo32"); cellMappingC100_C170.put("AG", "campo33"); cellMappingC100_C170.put("AH", "campo34"); cellMappingC100_C170.put("AI", "campo35"); cellMappingC100_C170.put("AJ", "campo36"); cellMappingC100_C170.put("AK", "campo37"); cellMappingC100_C170.put("AL", "campo38"); cellMappingC100_C170.put("AM", "campo39"); cellMappingC100_C170.put("AN", "campo40"); cellMappingC100_C170.put("AO", "campo41"); cellMappingC100_C170.put("AP", "campo42"); cellMappingC100_C170.put("AQ", "campo43"); cellMappingC100_C170.put("AR", "campo44"); cellMappingC100_C170.put("AS", "campo45"); cellMappingC100_C170.put("AT", "campo46"); cellMappingC100_C170.put("AU", "campo47"); cellMappingC100_C170.put("AV", "campo48"); cellMappingC100_C170.put("AW", "campo49"); cellMappingC100_C170.put("AX", "campo50"); cellMappingC100_C170.put("AY", "campo51"); cellMappingC100_C170.put("AZ", "campo52"); cellMappingC100_C170.put("BA", "campo53"); cellMappingC100_C170.put("BB", "campo54"); cellMappingC100_C170.put("BC", "campo55"); cellMappingC100_C170.put("BD", "campo56"); cellMappingC100_C170.put("BE", "campo57"); cellMappingC100_C170.put("BF", "campo58"); cellMappingC100_C170.put("BG", "campo59"); cellMappingC100_C170.put("BH", "campo60"); cellMappingC100_C170.put("BI", "campo61"); cellMappingC100_C170.put("BJ", "campo62"); cellMappingC100_C170.put("BK", "campo63"); cellMappingC100_C170.put("BL", "campo64"); cellMappingC100_C170.put("BM", "campo65"); cellMappingC100_C170.put("BN", "campo66"); cellMappingC100_C170.put("BO", "campo67"); cellMappingC100_C170.put("BP", "campo68"); cellMappingC100_C170.put("BQ", "campo69"); cellMappingC100_C170.put("BR", "campo70"); cellMappingC100_C170.put("BS", "campo71"); // The package open is instantaneous, as it should be. OPCPackage pkg = null; try { ExcelWorkSheetHandler<Reg0150> workSheetHandler = new ExcelWorkSheetHandler<Reg0150>(Reg0150.class, cellMapping0150); pkg = OPCPackage.open(inputStream); ExcelSheetCallback sheetCallback = new ExcelSheetCallback() { private int sheetNumber = 0; public void startSheet(int sheetNum, String sheetName) { this.sheetNumber = sheetNum; System.out.println("Started processing sheet number=" + sheetNumber + " and Sheet Name is '" + sheetName + "'"); } @Override public void endSheet() { System.out.println("Processing completed for sheet number=" + sheetNumber); } public void startSheet(int sheetNum) { System.out.println("Started processing sheet number=" + sheetNum); } }; /*** Leitura Registro 0150 ***/ System.out.println("Constructor: pkg, workSheetHandler, sheetCallback"); ExcelReader example1 = new ExcelReader(pkg, workSheetHandler, sheetCallback); example1.process("0150"); if (workSheetHandler.getValueList().isEmpty()) { // No data present LOG.error("sHandler.getValueList() is empty"); } else { LOG.info(workSheetHandler.getValueList().size() + " no. of records read from given excel worksheet successfully."); // Displaying data ead from Excel file displayPersonList(workSheetHandler.getValueList()); } /*** Leitura Registro 0200 ***/ ExcelWorkSheetHandler<Reg0200> workSheetHandler0200 = new ExcelWorkSheetHandler<Reg0200>(Reg0200.class, cellMapping0200); ExcelReader example2 = new ExcelReader(pkg, workSheetHandler0200, null); example2.process("0200"); if (workSheetHandler0200.getValueList().isEmpty()) { LOG.error("sHandler.getValueList() is empty"); } else { LOG.info(workSheetHandler0200.getValueList().size() + " no. of records read from given excel worksheet successfully."); displayPersonList0200(workSheetHandler0200.getValueList()); } /*** Leitura Registro C100 e C170 ***/ ExcelWorkSheetHandler<RegC100_C170> workSheetHandlerC100_C170 = new ExcelWorkSheetHandler<RegC100_C170>( RegC100_C170.class, cellMappingC100_C170, 4); workSheetHandlerC100_C170.setVerifiyHeader(false); ExcelReader example3 = new ExcelReader(pkg, workSheetHandlerC100_C170, null); example3.process("201302"); if (workSheetHandlerC100_C170.getValueList().isEmpty()) { LOG.error("sHandler.getValueList() is empty"); } else { LOG.info(workSheetHandlerC100_C170.getValueList().size() + " no. of records read from given excel worksheet successfully."); displayPersonListC100_C170(workSheetHandlerC100_C170.getValueList()); } } catch (RuntimeException are) { LOG.error(are.getMessage(), are.getCause()); } catch (InvalidFormatException ife) { LOG.error(ife.getMessage(), ife.getCause()); } catch (IOException ioe) { LOG.error(ioe.getMessage(), ioe.getCause()); } finally { IOUtils.closeQuietly(inputStream); try { if (null != pkg) { pkg.close(); } } catch (IOException e) { // just ignore IO exception } } }
From source file:com.google.api.services.samples.youtube.cmdline.youtube_cmdline_topics_sample.Topics.java
/** * Method kicks off a search via the Freebase API for a topics id. It initializes a YouTube * object to search for videos on YouTube (Youtube.Search.List) using that topics id to make the * search more specific. The program then prints the names and thumbnails of each of the videos * (only first 5 videos). Please note, user input is taken for both search on Freebase and on * YouTube./* w ww . ja v a 2s .co m*/ * * @param args command line args not used. */ public static void main(String[] args) { // Read the developer key from youtube.properties Properties properties = new Properties(); try { InputStream in = Topics.class.getResourceAsStream("/" + PROPERTIES_FILENAME); properties.load(in); } catch (IOException e) { System.err.println("There was an error reading " + PROPERTIES_FILENAME + ": " + e.getCause() + " : " + e.getMessage()); System.exit(1); } try { // Gets a topic id via the Freebase API based on user input. String topicsId = getTopicId(); if (topicsId.length() < 1) { System.out.println("No topic id will be applied to your search."); } /* * Get query term from user. The "search" parameter is just used as output to clarify that * we want a "search" term (vs. a "topics" term). */ String queryTerm = getInputQuery("search"); /* * The YouTube object is used to make all API requests. The last argument is required, but * because we don't need anything initialized when the HttpRequest is initialized, we * override the interface and provide a no-op function. */ youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() { public void initialize(HttpRequest request) throws IOException { } }).setApplicationName("youtube-cmdline-search-sample").build(); YouTube.Search.List search = youtube.search().list("id,snippet"); /* * It is important to set your developer key from the Google Developer Console for * non-authenticated requests (found under the API Access tab at this link: * code.google.com/apis/). This is good practice and increases your quota. */ String apiKey = properties.getProperty("youtube.apikey"); search.setKey(apiKey); search.setQ(queryTerm); if (topicsId.length() > 0) { search.setTopicId(topicsId); } /* * We are only searching for videos (not playlists or channels). If we were searching for * more, we would add them as a string like this: "video,playlist,channel". */ search.setType("video"); /* * This method reduces the info returned to only the fields we need. It makes things more * efficient, because we are transmitting less data. */ search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)"); search.setMaxResults(NUMBER_OF_VIDEOS_RETURNED); SearchListResponse searchResponse = search.execute(); List<SearchResult> searchResultList = searchResponse.getItems(); if (searchResultList != null) { prettyPrint(searchResultList.iterator(), queryTerm, topicsId); } else { System.out.println("There were no results for your query."); } } catch (GoogleJsonResponseException e) { System.err.println( "There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("There was an IO error: " + e.getCause() + " : " + e.getMessage()); e.printStackTrace(); } }
From source file:de.micromata.genome.tpsb.executor.GroovyShellExecutor.java
public static void main(String[] args) { String methodName = null;//from w w w . j a v a 2 s . c o m if (args.length > 0 && StringUtils.isNotBlank(args[0])) { methodName = args[0]; } GroovyShellExecutor exec = new GroovyShellExecutor(); //System.out.println("GroovyShellExecutor start"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line; StringBuffer code = new StringBuffer(); try { while ((line = in.readLine()) != null) { if (line.equals("--EOF--") == true) { break; } code.append(line); code.append("\n"); //System.out.flush(); } } catch (IOException ex) { throw new RuntimeException("Failure reading std in: " + ex.toString(), ex); } try { exec.executeCode(code.toString(), methodName); } catch (Throwable ex) { // NOSONAR "Illegal Catch" framework warn("GroovyShellExecutor failed with exception: " + ex.getClass().getName() + ": " + ex.getMessage() + "\n" + ExceptionUtils.getStackTrace(ex)); } System.out.println("--EOP--"); System.out.flush(); }