Example usage for java.io IOException getMessage

List of usage examples for java.io IOException getMessage

Introduction

In this page you can find the example usage for java.io IOException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

/**
 * Load a raw string resource./*  ww  w . j av  a  2  s .  com*/
 * @param context The current context.
 * @param resourceId The resource id.
 * @return The loaded string.
 */
public static String getStringFromRawResource(Context context, int resourceId) {
    String result = null;

    InputStream is = context.getResources().openRawResource(resourceId);
    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException e) {
            Log.w("ApplicationUtils",
                    String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                Log.w("ApplicationUtils",
                        String.format("Unable to load resource %s: %s", resourceId, e.getMessage()));
            }
        }
        result = sb.toString();
    } else {
        result = "";
    }

    return result;
}

From source file:com.lightbox.android.bitmap.BitmapLoader.java

private static Bitmap getBitmapFromNetwork(BitmapSource bitmapSource, BitmapSource.Type type, Config config) {
    Bitmap bitmap = null;/*from   w  w w.  j a v  a2s . co m*/
    URI uri = bitmapSource.getUri(type);
    if (uri != null) {
        FileOutputStream fos = null;
        try {
            File file = new File(bitmapSource.getAbsoluteFileName(type));

            // Ensure that the directory exist
            file.getParentFile().mkdirs();

            HttpResponse httpResponse = HttpHelper.getInstance().call(HttpMethod.GET, uri, null);

            fos = new FileOutputStream(file);

            IOUtils.copy(httpResponse.getEntity().getContent(), fos);

            bitmap = BitmapCache.getInstance().getFromDisk(bitmapSource.getAbsoluteFileName(type), config)
                    .getData();
        } catch (IOException e) {
            DebugLog.d("", e.getMessage());
            // Return null
        } finally {
            IOUtils.closeQuietly(fos);
        }
    }
    return bitmap;
}

From source file:com.microsoft.alm.client.utils.JsonHelper.java

public static String serializeRequestToString(final Object entity) {
    try {// w w  w .j av  a  2 s. co m
        return objectMapper.writeValueAsString(entity);
    } catch (final IOException e) {
        log.error(e.getMessage(), e);
        throw new IllegalArgumentException(
                MessageFormat.format(Messages.getString("JsonHelper.CannotSerializeContentFormat"), //$NON-NLS-1$
                        entity.getClass().getName()),
                e);
    }
}

From source file:com.fccfc.framework.common.utils.PropertyHolder.java

private static void load(InputStream inputStream, Map<String, String> map) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"))) {
        String line;/*from   w  w w. j a v a  2 s  . co m*/
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if ("".equals(line) || line.startsWith("#")) {
                continue;
            }
            int index = line.indexOf("=");
            if (index == -1) {
                log.error("?" + line);
                continue;
            }
            if (index > 0 && line.length() > index + 1) {
                String key = line.substring(0, index).trim();
                String value = line.substring(index + 1, line.length()).trim();
                map.put(key, value);
            } else {
                log.error("?" + line);
            }
        }
    } catch (IOException ex) {
        log.error("?:" + ex.getMessage());
        throw new RuntimeException(ex);
    }
}

From source file:eu.optimis.mi.aggregator.util.ConfigManager.java

private static void createDefaultConfigFile(File fileObject) throws IOException {
    log.debug("File " + fileObject.getAbsolutePath() + " didn't exist. Creating one with default values...");

    //Create parent directories.
    log.debug("Creating parent directories.");
    new File(fileObject.getParent()).mkdirs();

    //Create an empty file to copy the contents of the default file.
    log.debug("Creating empty file.");
    new File(fileObject.getAbsolutePath()).createNewFile();

    //Copy file./*from  w w w.ja  v a 2s  . c  o  m*/
    log.debug("Copying file " + fileObject.getName() + "into path: " + fileObject.getAbsolutePath());
    InputStream streamIn = ConfigManager.class.getResourceAsStream("/" + fileObject.getName());
    FileOutputStream streamOut = new FileOutputStream(fileObject.getAbsolutePath());
    byte[] buf = new byte[8192];
    while (true) {
        int length = streamIn.read(buf);
        if (length < 0) {
            break;
        }
        streamOut.write(buf, 0, length);
    }

    //Close streams after copying.
    try {
        streamIn.close();
    } catch (IOException ex) {
        log.error("Couldn't close input stream");
        log.error(ex.getMessage());
        throw new IOException();
    }
    try {
        streamOut.close();
    } catch (IOException ex) {
        log.error("Couldn't close file output stream");
        log.error(ex.getMessage());
        throw new IOException();
    }
}

From source file:fr.paris.lutece.plugins.seo.service.sitemap.SitemapService.java

/**
 * Generate Sitemap//  w  w w  . j  a va  2s .co  m
 * @return The sitemap content
 */
public static String generateSitemap() {
    List<FriendlyUrl> list = getSitemapUrls();
    Map<String, Object> model = new HashMap<String, Object>();

    model.put(MARK_URLS_LIST, list);

    HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_SITEMAP_XML, Locale.getDefault(),
            model);

    String strXmlSitemap = templateList.getHtml();
    String strSiteMapFilePath = AppPathService.getWebAppPath() + FILE_SITEMAP;
    File fileSiteMap = new File(strSiteMapFilePath);

    String strResult = "OK";

    try {
        FileUtils.writeStringToFile(fileSiteMap, strXmlSitemap);
    } catch (IOException e) {
        AppLogService.error("Error writing Sitemap file : " + e.getMessage(), e.getCause());
        strResult = "Error : " + e.getMessage();
    }

    String strDate = DateFormat.getDateTimeInstance().format(new Date());
    Object[] args = { strDate, list.size(), strResult };
    String strLogFormat = I18nService.getLocalizedString(PROPERTY_SITEMAP_LOG, Locale.getDefault());
    String strLog = MessageFormat.format(strLogFormat, args);
    DatastoreService.setDataValue(SEODataKeys.KEY_SITEMAP_UPDATE_LOG, strLog);

    return strLog;
}

From source file:com.nanosheep.bikeroute.parser.GoogleDirectionsParser.java

/**
 * Convert an inputstream to a string.//w  w w. j  a  v  a  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;
    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:com.google.gct.stats.GoogleUsageTracker.java

private static void sendPing(@NotNull final List<? extends NameValuePair> postData) {
    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        public void run() {
            CloseableHttpClient client = HttpClientBuilder.create().build();
            HttpPost request = new HttpPost(ANALYTICS_URL);

            try {
                request.setEntity(new UrlEncodedFormEntity(postData));
                CloseableHttpResponse response = client.execute(request);
                StatusLine status = response.getStatusLine();
                if (status.getStatusCode() >= 300) {
                    LOG.debug("Non 200 status code : " + status.getStatusCode() + " - "
                            + status.getReasonPhrase());
                }/*  w w w  . j  ava2  s . c  o m*/
            } catch (IOException ex) {
                LOG.debug("IOException during Analytics Ping", new Object[] { ex.getMessage() });
            } finally {
                HttpClientUtils.closeQuietly(client);
            }

        }
    });
}

From source file:ca.tbcn.greenp.GreenParkingApp.java

/**
 * Load JSONObject from json file/*from  www.j av a2  s. co  m*/
 * 
 * @param context
 * @return
 */
public static JSONObject getCarparksJson(Context context) {
    InputStream is = null;
    String jsonString = null;
    JSONObject json = null;

    try {

        jsonString = "{\"carparks\": " + getJsonFileContents(context) + "}";
        json = new JSONObject(jsonString);

    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }

    return json;
}

From source file:com.leprechaun.solveig.http.RequestExecutor.java

public static ResponseEntity simpleExecutor(String host, String port, String query) {

    ResponseEntity responseEntity = new ResponseEntity();

    HttpClient client = new DefaultHttpClient();

    String url = "http://" + host + ":" + port + "/query?q=" + query;

    System.out.println(url);/*from   www .j a  v a 2  s.  c om*/

    HttpGet get = new HttpGet(url);

    try {
        HttpResponse response = client.execute(get);
        HttpEntity entity = response.getEntity();
        String responseString = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseString);

        responseEntity.setCode(response.getStatusLine().toString());
        responseEntity.setBody(responseString);
    } catch (IOException e) {
        System.out.println(e.getMessage());

        responseEntity.setCode("ERROR");
        responseEntity.setBody(e.getMessage());
    }

    return responseEntity;
}