Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:be.roots.taconic.pricingguide.util.HttpUtil.java

public static byte[] readByteArray(String urlAsString, String userName, String password) {

    try {//from w w w .ja v  a 2s . c  om
        final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password);
        final BufferedInputStream in = new BufferedInputStream(con.getInputStream());
        final byte[] response = IOUtils.toByteArray(in);
        IOUtils.closeQuietly(in);
        return response;
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return null;
}

From source file:be.roots.taconic.pricingguide.util.HttpUtil.java

public static String readString(String urlAsString, String userName, String password) {

    try {//from   ww w . ja va  2  s  .c  o m
        final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password);
        final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        final String response = IOUtils.toString(in);
        IOUtils.closeQuietly(in);
        return response;
    } catch (IOException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }
    return null;

}

From source file:Main.java

public static boolean creteEntity(Object entity, String fileName) {
    boolean flag = false;
    try {/*from w ww.  java 2s.c  o  m*/
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse(fileName);

        Class clazz = entity.getClass();
        Field[] fields = clazz.getDeclaredFields();
        Node EntityElement = document.getElementsByTagName(clazz.getSimpleName() + "s").item(0);

        Element newEntity = document.createElement(clazz.getSimpleName());
        EntityElement.appendChild(newEntity);

        for (Field field : fields) {
            field.setAccessible(true);
            Element element = document.createElement(field.getName());
            element.appendChild(document.createTextNode(field.get(entity).toString()));
            newEntity.appendChild(element);
        }

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource domSource = new DOMSource(document);
        StreamResult streamResult = new StreamResult(new File(fileName));
        transformer.transform(domSource, streamResult);
        flag = true;
    } catch (ParserConfigurationException pce) {
        System.out.println(pce.getLocalizedMessage());
        pce.printStackTrace();
    } catch (TransformerException te) {
        System.out.println(te.getLocalizedMessage());
        te.printStackTrace();
    } catch (IOException ioe) {
        System.out.println(ioe.getLocalizedMessage());
        ioe.printStackTrace();
    } catch (SAXException sae) {
        System.out.println(sae.getLocalizedMessage());
        sae.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return flag;
}

From source file:com.github.drbookings.io.Backup.java

public static void make(final File file) {
    if (file.exists() && file.length() != 0) {
        try {//from   www  .  j ava  2  s .c om
            final File backupFile = new File(file.getParentFile(), file.getName() + ".bak");
            FileUtils.copyFile(file, backupFile);
            if (logger.isInfoEnabled()) {
                logger.info("Backup created as " + backupFile);
            }
        } catch (final IOException e) {
            if (logger.isErrorEnabled()) {
                logger.error(e.getLocalizedMessage(), e);
            }
        }
    }
}

From source file:com.checkoutcrypto.api.HttpUtils.java

public static String getErrorResponse(HttpURLConnection urlConnection) {
    InputStream errorStream = urlConnection.getErrorStream();

    try {//from  w  w w .j a  va2  s .  co  m
        if (errorStream != null) {
            byte[] responseBytes = getContent(errorStream).toByteArray();
            return new String(responseBytes, "UTF-8");
        }
    } catch (IOException e) {
        return "Failed to get error response: " + e.getLocalizedMessage();
    }

    return null;
}

From source file:com.wealdtech.configuration.ConfigurationSource.java

private static String readFile(final String filename) {
    final StringBuilder content = new StringBuilder();
    final String linefeed = System.getProperty("line.separator");
    try (BufferedReader reader = getReader(filename)) {
        if (reader == null) {
            throw new DataError("Failed to find resource \"" + filename + "\"");
        }/*ww  w  .  j  a v a  2  s  .co m*/
        String line;
        while ((line = reader.readLine()) != null) {
            content.append(line).append(linefeed);
        }
    } catch (IOException e) {
        LOGGER.warn("Failed to read file: {}", e.getLocalizedMessage());
        LOGGER.warn("Stack trace: {}", e);
        throw new DataError("Failed to read file: " + e.getLocalizedMessage(), e);
    }
    return content.toString();
}

From source file:com.difference.historybook.importer.crawler.Crawler.java

/**
 * Fetch the body for a given HistoryRecord and add it to the record
 * /*from  w  w w .ja  v a  2 s  .  c  o  m*/
 * @param record HistoryRecord containing a URL to fetch
 * @return
 */
protected static HistoryRecord fetchBody(HistoryRecord record) {
    try {
        Content content = Request.Get(encodeSpecialChars(record.getUrl())).execute().returnContent();
        if (content != null) {
            record.setBody(content.asString(Charsets.UTF_8));
        }
    } catch (IOException e) {
        System.err.println("Failed to fetch " + record.getUrl() + ": " + e.getLocalizedMessage());
    }
    return record;
}

From source file:com.ibm.soatf.tool.FileSystem.java

public static String readContentFromFile(String fileName) {
    String content = null;//from  w ww. j a  va  2 s. c  om
    try {
        content = readFileToString(new File(fileName));
    } catch (IOException ex) {
        logger.error("Error while trying read content of file: " + ex.getLocalizedMessage());
    }
    return content;
}

From source file:com.indexoutofbounds.util.ClassPathInputStreamUtils.java

/**
 * Creates an InputStream from the path which can be either something on
 * the file system, a remote system, or a classpath entry.
 * @param path//from ww w .ja v  a 2 s .c  om
 * @return
 * @throws Exception
 */
public final static InputStream getInputStream(final String path) throws IOException {

    if (StringUtils.isEmpty(path)) {
        throw new IOException("Unable to locate empty config file parameter");
    }

    final URL url = locateURL(path);
    if (url == null) {
        throw new IOException("Unable to locate config file: " + path);
    }

    try {

        return new BufferedInputStream(url.openStream());
    } catch (IOException e) {
        throw new IOException("Unable to open config file: " + path + ", " + e.getLocalizedMessage());
    }
}

From source file:com.almende.eve.agent.AgentProxyFactory.java

/**
 * Gen proxy.//from  w  w w .  ja  v a  2 s . c  om
 * 
 * @param <T>
 *            the generic type
 * @param sender
 *            the sender
 * @param receiverUrl
 *            the receiver url
 * @param proxyInterface
 *            the interface this proxy implements
 * @return the t
 */
@SuppressWarnings("unchecked")
public static <T> T genProxy(final Agent sender, final URI receiverUrl, final Class<T> proxyInterface) {
    // http://docs.oracle.com/javase/1.4.2/docs/guide/reflection/proxy.html
    final T proxy = (T) Proxy.newProxyInstance(proxyInterface.getClassLoader(), new Class[] { proxyInterface },
            new InvocationHandler() {

                private Map<Method, Boolean> cache = new HashMap<Method, Boolean>();

                @Override
                public Object invoke(final Object proxy, final Method method, final Object[] args) {
                    boolean doSync = true;
                    if (cache.containsKey(method)) {
                        doSync = cache.get(method);
                    } else {
                        AnnotatedClass clazz = AnnotationUtil.get(proxyInterface);
                        if (clazz != null) {
                            List<AnnotatedMethod> list = clazz.getMethods(method.getName());
                            for (AnnotatedMethod m : list) {
                                if (m.getAnnotation(NoReply.class) != null) {
                                    doSync = false;
                                }
                            }
                            if (doSync && method.getReturnType().equals(void.class)
                                    && clazz.getAnnotation(NoReply.class) != null) {
                                doSync = false;
                            }
                        }
                        cache.put(method, doSync);
                    }
                    SyncCallback<JsonNode> callback = null;
                    if (doSync) {
                        callback = new SyncCallback<JsonNode>() {
                        };
                    }
                    try {
                        sender.call(receiverUrl, method, args, callback);
                    } catch (final IOException e) {
                        throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e.getLocalizedMessage(), e);
                    }
                    if (callback != null) {
                        try {
                            return TypeUtil.inject(callback.get(), method.getGenericReturnType());
                        } catch (final Exception e) {
                            throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e.getLocalizedMessage(), e);
                        }
                    }
                    return null;
                }
            });
    return proxy;
}