List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:com.nanosheep.bikeroute.parser.GoogleElevationParser.java
/** * Convert an inputstream to a string./* www . j a va 2 s .c o m*/ * @param input inputstream to convert. * @return a String of the inputstream. */ private static String convertStreamToString(final InputStream input) { final BufferedReader reader = new BufferedReader(new InputStreamReader(input)); final StringBuilder sBuf = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sBuf.append(line); } } catch (IOException e) { Log.e(e.getMessage(), "Google parser, stream2string"); } finally { try { input.close(); } catch (IOException e) { Log.e(e.getMessage(), "Google parser, stream2string"); } } return sBuf.toString(); }
From source file:de.xirp.report.ReportManager.java
/** * This method opens the contained PDF data of the * given {@link de.xirp.report.ReportDescriptor} * in the default viewer of the underlying operating system. * /*from w w w .j a va 2 s. com*/ * @param rd * The report descriptor to open. */ public static void viewReport(ReportDescriptor rd) { File tmp = new File(Constants.TMP_DIR, "report_temp_xirp2.pdf"); //$NON-NLS-1$ try { tmp.createNewFile(); FileUtils.writeByteArrayToFile(tmp, rd.getPdfData()); SWTUtil.openFile(tmp); } catch (IOException e) { logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$ } if (tmp != null) { DeleteManager.deleteOnShutdown(tmp); } }
From source file:net.krotscheck.util.ResourceUtil.java
/** * Read the resource found at a specific path into a string. * * @param resourcePath The path to the resource. * @return The resource as a string, or an empty string if the resource was * not found./*from w w w . java 2 s.co m*/ */ public static String getResourceAsString(final String resourcePath) { File resource = getFileForResource(resourcePath); if (!resource.exists() || resource.isDirectory()) { logger.error("Cannot read resource, does not exist" + " (or is a directory)."); return ""; } try { return FileUtils.readFileToString(resource); } catch (IOException ioe) { logger.error(ioe.getMessage()); return ""; } }
From source file:net.krotscheck.util.ResourceUtil.java
/** * Read the resource found at the given path into a stream. * * @param resourcePath The path to the resource. * @return The resource as an input stream. If the resource was not found, * this will be the NullInputStream./* www . j a v a 2 s . c o m*/ */ public static InputStream getResourceAsStream(final String resourcePath) { File resource = getFileForResource(resourcePath); if (!resource.exists() || resource.isDirectory()) { logger.error("Cannot read resource, does not exist" + " (or is a directory)."); return new NullInputStream(0); } try { return new FileInputStream(resource); } catch (IOException ioe) { logger.error(ioe.getMessage()); return new NullInputStream(0); } }
From source file:app.utils.ImageUtilities.java
public static void saveHistogramToFile(JFreeChart chart) { try {// ww w. j a v a 2 s . c o m File chartFile = new File(DEFAULT_FILE_SAVE_PATH + "histogram" + "." + DEFAULT_FILE_EXTENSION); ChartUtilities.saveChartAsJPEG(chartFile, chart, 400, 250); } catch (IOException ioe) { LOG.error("Error while saving chart to file.\n" + ioe.getMessage()); } }
From source file:com.ebay.spine.Launcher.java
private static Map<String, String> getVMtoTemplateMapping(String file) throws FileNotFoundException { // load VM mapping // format:/* ww w .j ava2s. c o m*/ // spine-linux1:421ec33e-4cc6-a747-76f5-cc460ba7f03f:linux // name:id:template Map<String, String> vmsMapping = new HashMap<String, String>(); BufferedReader buffreader = new BufferedReader(new FileReader(file)); String line; try { while ((line = buffreader.readLine()) != null) { String[] pieces = line.split(":"); if (pieces.length == 3) { vmsMapping.put(pieces[1], pieces[2]); } } } catch (IOException e) { throw new GridConfigurationException("Cannot read node file " + e.getMessage(), e); } return vmsMapping; }
From source file:gridool.communication.transport.tcp.GridSocketPoolingClient.java
private static ByteBuffer toBuffer(final GridCommunicationMessage msg) { final long startTime = System.currentTimeMillis(); final FastByteArrayOutputStream out = new FastByteArrayOutputStream(); try {/*from w w w. j ava 2s .co m*/ IOUtils.writeInt(0, out);// allocate first 4 bytes for size ObjectUtils.toStreamVerbose(msg, out); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new IllegalStateException(e); } final byte[] b = out.toByteArray(); final int objsize = b.length - 4; Primitives.putInt(b, 0, objsize); if (LOG.isDebugEnabled()) { final long elapsedTime = System.currentTimeMillis() - startTime; LOG.debug("Elapsed time for serializing (including lazy evaluation) a GridCommunicationMessage [" + msg.getMessageId() + "] of " + b.length + " bytes: " + DateTimeFormatter.formatTime(elapsedTime)); } final ByteBuffer buf = ByteBuffer.wrap(b); return buf; }
From source file:de.steilerdev.myVerein.server.apns.PushService.java
/** * This function creates a new APNS instance. If the function returns null, APNS is not supported. * @return The current APNS instance. If null APNS is not supported by this server. */// w ww . ja va2s. c om public static PushManager<SimpleApnsPushNotification> getInstanced() { if (pushManager == null) { logger.debug("Creating new APNS instance"); try { Resource settingsResource = new ClassPathResource(apnsSettingsFile); Properties settings = PropertiesLoaderUtils.loadProperties(settingsResource); InputStream certFile = Thread.currentThread().getContextClassLoader() .getResourceAsStream(settings.getProperty(fileKey)); pushManager = new PushManager<>(ApnsEnvironment.getSandboxEnvironment(), SSLContextUtil.createDefaultSSLContext(certFile, settings.getProperty(passwordKey)), null, // Optional: custom event loop group null, // Optional: custom ExecutorService for calling listeners null, // Optional: custom BlockingQueue implementation new PushManagerConfiguration(), "ExamplePushManager"); logger.debug("Created new APNS instance, starting"); //pushManager.start(); } catch (IOException e) { logger.warn("Unable to load APNS settings file: {}", e.getMessage()); return null; } catch (Exception e) { logger.warn("An unknown error occurred: {}", e.getMessage()); } } logger.info("Returning APNS instance"); return pushManager; }
From source file:com.cmput301w15t15.travelclaimsapp.elasticsearch.parseResponse.java
/** * Gets rid of elastic search header and returns saved user. * @param response//from w w w . j a v a2 s . com * @return SearchHit<User> */ public static SearchHit<User> userHit(HttpResponse response) { try { String json = getEntityContent(response); Type searchHitType = new TypeToken<SearchHit<User>>() { }.getType(); SearchHit<User> sr = gson.fromJson(json, searchHitType); return sr; } catch (IOException e) { Log.d(TAG, "parseUseHit could not work: " + e.getMessage()); } return null; }
From source file:com.bytelightning.opensource.pokerface.ProxySpecificTest.java
/** * Context handler for the SunHttpServer *//*from w w w . j a v a 2 s.c o m*/ protected static void OnRemoteTargetRequest(HttpExchange exchange) { Headers rspHdrs = exchange.getResponseHeaders(); rspHdrs.set("Date", Utils.GetHTTPDateFormater().format(new Date())); rspHdrs.set("Content-Type", "text/html"); try { exchange.sendResponseHeaders(200, 0); OutputStream out = exchange.getResponseBody(); out.write("<htm><head><title>TEST</title></head><body>TEST</body></html>".getBytes("utf-8")); out.close(); } catch (IOException e) { Assert.fail(e.getMessage()); } }