List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:jef.tools.chinese.CFJUtil.java
/** * ??/* w w w. j av a 2 s . co m*/ * @return ?? */ public static CFJUtil getInstance() { if (instance == null) { try { instance = new CFJUtil(); } catch (IOException e) { throw new RuntimeException(e.getMessage()); } } return instance; }
From source file:org.sead.repositories.reference.util.SEADAuthenticator.java
static public HttpClientContext authenticate(String server) { boolean authenticated = false; log.info("Authenticating"); String accessToken = SEADGoogleLogin.getAccessToken(); // Now login to server and create a session CloseableHttpClient httpclient = HttpClients.createDefault(); try {// ww w . j av a 2s .co m // //DoLogin is the auth endpoint when using the AUthFilter, versus // the api/authenticate endpoint when connecting to the ACR directly HttpPost seadAuthenticate = new HttpPost(server + "/DoLogin"); List<NameValuePair> nvpList = new ArrayList<NameValuePair>(1); nvpList.add(0, new BasicNameValuePair("googleAccessToken", accessToken)); seadAuthenticate.setEntity(new UrlEncodedFormEntity(nvpList)); CloseableHttpResponse response = httpclient.execute(seadAuthenticate, localContext); try { if (response.getStatusLine().getStatusCode() == 200) { HttpEntity resEntity = response.getEntity(); if (resEntity != null) { // String seadSessionId = // EntityUtils.toString(resEntity); authenticated = true; } } else { // Seems to occur when google device id is not set on server // - with a Not Found response... log.error("Error response from " + server + " : " + response.getStatusLine().getReasonPhrase()); } } finally { response.close(); httpclient.close(); } } catch (IOException e) { log.error("Cannot read sead-google.json"); log.error(e.getMessage()); } // localContext should have the cookie with the SEAD session key, which // nominally is all that's needed. // FixMe: If there is no activity for more than 15 minutes, the session // may expire, in which case, // re-authentication using the refresh token to get a new google token // to allow SEAD login again may be required // also need to watch the 60 minutes google token timeout - project // spaces will invalidate the session at 60 minutes even if there is // activity authTime = System.currentTimeMillis(); if (authenticated) { return localContext; } return null; }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * Example Hierarchy/*w w w . jav a2 s .c om*/ * orgConfig.apiProducts * * Returns List of * [ {apiProduct1}, {apiProduct2}, {apiProduct3} ] */ // TODO convert parse exception error message more human friendly public static List getOrgConfig(File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray configs = (JSONArray) parser.parse(bufferedReader); if (configs == null) return null; out = new ArrayList(); for (Object config : configs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:com.recomdata.transmart.data.export.util.FTPUtil.java
/** * Performs the login operation for the provided user credentials * // w w w . j av a 2s. com * @throws FTPAuthenticationException */ private static void login() throws FTPAuthenticationException { try { if (StringUtils.isNotEmpty(FTP_SERVER_USER_NAME) && StringUtils.isNotEmpty(FTP_SERVER_PASSWORD)) { if (!ftp.login(FTP_SERVER_USER_NAME, FTP_SERVER_PASSWORD)) { ftp.logout(); throw new FTPAuthenticationException("Credentials failed to Authenticate on the FTP server"); } System.out.println("Remote system is " + ftp.getSystemType()); } } catch (IOException e) { log.error(e.getMessage(), e); } }
From source file:de.micromata.genome.util.runtime.Log4JInitializer.java
private static boolean initViaFile(File log4jfile) { File devFile = findDevFile(log4jfile); Properties props = new Properties(); try {//from w w w . jav a2 s . c o m try (InputStream is = new FileInputStream(log4jfile)) { props.load(is); } if (devFile != null) { try (InputStream is = new FileInputStream(devFile)) { props.load(is); } } } catch (IOException ex) { LOG.error("Cannot read log4jfiles: " + ex.getMessage(), ex); return false; } new PropertyConfigurator().doConfigure(props, LogManager.getLoggerRepository()); if ((propWatchDoc == null || propWatchDoc.isAlive() == false)) { propWatchDoc = new PropertyWatchdog(log4jfile.getAbsolutePath(), log4jMonitorTimeInMs); propWatchDoc.start(); } if (devFile != null && (propDevWatchDoc == null || propDevWatchDoc.isAlive() == false)) { propDevWatchDoc = new PropertyWatchdog(log4jfile.getAbsolutePath(), log4jMonitorTimeInMs); propDevWatchDoc.start(); } return true; }
From source file:de.thischwa.pmcms.tool.ChecksumTool.java
/** * Reading the checksums directly from a zip file. *///from w ww .j a v a 2s.co m public static Map<String, String> getFromZip(final File zip, final String filename) { try { return get(Zip.getInputStream(zip, filename)); } catch (IOException e) { throw new FatalException("Error while reading checksum zip file: " + e.getMessage(), e); } }
From source file:com.afrisoftech.lib.PDF2ExcelConverter.java
public static void convertPDf2Excel(String pdfFile2Convert) throws Exception { if (pdfFile2Convert.length() < 3) { System.out.println("File to convert is mandatory!"); javax.swing.JOptionPane.showMessageDialog(null, "File to convert is mandatory!"); } else {/* w w w.ja v a2 s. c o m*/ final String apiKey = "ktxpfvf0i5se"; final String format = "xlsx-single".toLowerCase(); final String pdfFilename = pdfFile2Convert; if (!formats.contains(format)) { System.out.println("Invalid output format: \"" + format + "\""); } // Avoid cookie warning with default cookie configuration RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build(); File inputFile = new File(pdfFilename); if (!inputFile.canRead()) { System.out.println("Can't read input PDF file: \"" + pdfFilename + "\""); javax.swing.JOptionPane.showMessageDialog(null, "File to convert is mandatory!"); } try (CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(globalConfig) .build()) { HttpPost httppost = new HttpPost("https://pdftables.com/api?format=" + format + "&key=" + apiKey); FileBody fileBody = new FileBody(inputFile); HttpEntity requestBody = MultipartEntityBuilder.create().addPart("f", fileBody).build(); httppost.setEntity(requestBody); System.out.println("Sending request"); try (CloseableHttpResponse response = httpclient.execute(httppost)) { if (response.getStatusLine().getStatusCode() != 200) { System.out.println(response.getStatusLine()); javax.swing.JOptionPane.showMessageDialog(null, "Internet connection is a must. Consult IT administrator for further assistance"); } HttpEntity resEntity = response.getEntity(); if (resEntity != null) { final String outputFilename = getOutputFilename(pdfFilename, format.replaceFirst("-.*$", "")); System.out.println("Writing output to " + outputFilename); final File outputFile = new File(outputFilename); FileUtils.copyInputStreamToFile(resEntity.getContent(), outputFile); if (java.awt.Desktop.isDesktopSupported()) { try { java.awt.Desktop.getDesktop().open(outputFile); } catch (IOException ex) { javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage()); ex.printStackTrace(); //Exceptions.printStackTrace(ex); } } } else { System.out.println("Error: file missing from response"); javax.swing.JOptionPane.showMessageDialog(null, "Error: file missing from response! Internet connection is a must."); } } } } }
From source file:com.omertron.slackbot.functions.Meetup.java
/** * Retrieve and process the MeetUps from the site. * * @param pageSize/* w ww . jav a 2 s .c om*/ * @throws ApiException */ public static void readMeetUp(int pageSize) throws ApiException { MEETUPS.clear(); if (StringUtils.isBlank(BASE_URL)) { throw new ApiException(ApiExceptionType.INVALID_URL, "Meetup URL is not set in the properties file! Use the property " + Constants.MEETUP_URL); } try { URL url = HttpTools.createUrl(BASE_URL + pageSize); List<MeetupDetails> meetups = MAPPER.readValue(url, new TypeReference<List<MeetupDetails>>() { }); MEETUPS.addAll(meetups); } catch (IOException ex) { LOG.warn("Failed to read MeetUp data: {}", ex.getMessage(), ex); return; } catch (ApiException ex) { LOG.warn("Failed to convert URL: {}", ex.getMessage(), ex); return; } LOG.info("Processed {} MeetUp events", MEETUPS.size()); }
From source file:com.baidu.api.client.core.DownloadUtil.java
/** * Download the file pointed by the url and return the content as byte array. * * @param strUrl The Url to be downloaded. * @param connectTimeout Connect timeout in milliseconds. * @param readTimeout Read timeout in milliseconds. * @param maxFileSize Max file size in BYTE. * @return The file content as byte array. *//* w w w .ja va 2 s . com*/ public static byte[] downloadFile(String strUrl, int connectTimeout, int readTimeout, int maxFileSize) { InputStream in = null; try { URL url = new URL(strUrl); // URL? URLConnection ucon = url.openConnection(); ucon.setConnectTimeout(connectTimeout); ucon.setReadTimeout(readTimeout); ucon.connect(); if (ucon.getContentLength() > maxFileSize) { String msg = "File " + strUrl + " size [" + ucon.getContentLength() + "] too large, download stoped."; throw new ClientInternalException(msg); } if (ucon instanceof HttpURLConnection) { HttpURLConnection httpCon = (HttpURLConnection) ucon; if (httpCon.getResponseCode() > 399) { String msg = "Failed to download file " + strUrl + " server response " + httpCon.getResponseMessage(); throw new ClientInternalException(msg); } } in = ucon.getInputStream(); // ? byte[] byteBuf = new byte[BUFFER_SIZE]; byte[] ret = null; int count, total = 0; // ?? while ((count = in.read(byteBuf, total, BUFFER_SIZE - total)) > 0) { total += count; if (total + 124 >= BUFFER_SIZE) break; } if (total < BUFFER_SIZE - 124) { ret = ArrayUtils.subarray(byteBuf, 0, total); } else { ByteArrayOutputStream bos = new ByteArrayOutputStream(MATERIAL_SIZE); count = total; total = 0; do { bos.write(byteBuf, 0, count); total += count; if (total > maxFileSize) { String msg = "File " + strUrl + " size exceed [" + maxFileSize + "] download stoped."; throw new ClientInternalException(msg); } } while ((count = in.read(byteBuf)) > 0); ret = bos.toByteArray(); } if (ret.length < MIN_SIZE) { String msg = "File " + strUrl + " size [" + maxFileSize + "] too small."; throw new ClientInternalException(msg); } return ret; } catch (IOException e) { String msg = "Failed to download file " + strUrl + " msg=" + e.getMessage(); throw new ClientInternalException(msg); } finally { try { if (in != null) in.close(); } catch (IOException e) { // ? System.out.println("Exception while close url - " + e.getMessage()); } } }