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:com.surfs.storage.common.util.CmdUtils.java

public static String executeCmdForString(String cmd) {
    BufferedReader bufRead = null;
    try {// ww w  .jav a  2s.c o  m
        bufRead = executeCmdForReader(cmd);
        return bufRead.readLine();
    } catch (IOException e) {
        LogFactory.error(e.getMessage());
    } finally {
        if (bufRead != null)
            try {
                bufRead.close();
            } catch (IOException e) {
                LogFactory.error(e.getMessage());
            }
    }
    return null;
}

From source file:com.qcadoo.model.internal.utils.JdomUtils.java

public static byte[] documentToByteArray(final Document document) {
    try {/*from ww  w .j  a  v a2 s  .  c o  m*/
        XMLOutputter outputter = new XMLOutputter();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        outputter.output(document, out);
        return out.toByteArray();
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:com.qcadoo.model.internal.utils.JdomUtils.java

public static Document inputStreamToDocument(final InputStream stream) {
    try {//from  ww w . ja  v  a2  s  .co  m
        SAXBuilder builder = new SAXBuilder();
        return builder.build(stream);
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    } catch (JDOMException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:Main.java

public static String convertStreamToString(InputStream is) {
    if (is != null) {
        StringBuilder sb = new StringBuilder();
        String line;/*ww w. ja  va  2s.c  o  m*/

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException e) {
            Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
            }
        }
        return sb.toString();
    } else {
        return "";
    }
}

From source file:Main.java

public static String parseHelpFile(String filename) {
    String output;/*w w  w  .j  av a2  s  .  co m*/
    InputStream is = null;
    try {
        is = assetFiles.open("txt/" + filename);
        output = readTextFile(is);
    } catch (IOException e) {
        output = "Sorry, help file not found.";
        Log.i("IO error", e.getMessage());
    }
    return output;
}

From source file:edu.wustl.cab2b.common.authentication.GTSSynchronizer.java

private static void copyCACertificates(URL inFileURL) {
    int index = inFileURL.getPath().lastIndexOf('/');
    if (index > -1) {
        String fileName = inFileURL.getPath().substring(index + 1).trim();
        File destination = new File(
                gov.nih.nci.cagrid.common.Utils.getTrustedCerificatesDirectory() + File.separator + fileName);

        try {/*w w w.ja  v  a 2  s. c o m*/
            FileUtils.copyURLToFile(inFileURL, destination);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            throw new AuthenticationException(
                    "Unable to copy CA certificates to [user.home]/.globus: " + e.getMessage(), e,
                    ErrorCodeConstants.CDS_003);
        }
    }
}

From source file:net.formio.portlet.MockPortletRequests.java

/**
 * Creates new portlet request that contains given resource as multi part.
 * @param paramName/*from  www .j av a2s. c  o m*/
 * @param resourceName
 * @return
 */
public static MockMultipartActionRequest newRequest(String paramName, String resourceName, String mimeType) {
    try {
        MockMultipartActionRequest request = new MockMultipartActionRequest();
        // Load resource being uploaded
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Streams.copy(MockPortletRequests.class.getResourceAsStream(resourceName), bos, true);
        byte[] fileContent = bos.toByteArray();

        // Create part & entity from resource
        Part[] parts = new Part[] { new FilePart(paramName, new ByteArrayPartSource(resourceName, fileContent),
                mimeType, (String) null) };
        MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts,
                new PostMethod().getParams());

        ByteArrayOutputStream requestContent = new ByteArrayOutputStream();
        multipartRequestEntity.writeRequest(requestContent);
        request.setContent(requestContent.toByteArray());
        // Set content type of request (important, includes MIME boundary string)
        String contentType = multipartRequestEntity.getContentType();
        request.setContentType(contentType);
        return request;
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}

From source file:disono.webmons.com.clean_architecture.storage.networks.ErrorUtils.java

public static String converter(ResponseBody errorBody) {
    StringBuilder sb = new StringBuilder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(errorBody.byteStream()));
    String line;// www. j a  v  a 2s .c om

    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException e) {
        WBConsole.e(TAG, e.getMessage());
    }

    try {
        JSONObject mapper = new JSONObject(sb.toString());

        if (mapper.optJSONObject("errors") != null) {
            JSONObject object = mapper.getJSONObject("errors");
            String errors = "";

            Iterator x = object.keys();
            JSONArray jsonArray = new JSONArray();

            while (x.hasNext()) {
                String key = (String) x.next();
                jsonArray.put(object.get(key));
            }

            for (int i = 0; i < jsonArray.length(); i++) {
                errors += ((i > 0) ? "\n" : "") + "- " + jsonArray.getString(i);
            }

            return errors;
        }

        return mapper.getString("errors");
    } catch (JSONException e) {
        WBConsole.e(TAG, e.getMessage());
    }

    return null;
}

From source file:net.formio.servlet.MockServletRequests.java

/**
 * Creates new servlet request that contains given resource as multi part.
 * @param paramName//from   www .  j av  a2 s.c o  m
 * @param resourceName
 * @return
 */
public static MockHttpServletRequest newRequest(String paramName, String resourceName, String mimeType) {
    try {
        MockHttpServletRequest request = new MockHttpServletRequest();
        // Load resource being uploaded
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Streams.copy(MockServletRequests.class.getResourceAsStream(resourceName), bos, true);
        byte[] fileContent = bos.toByteArray();

        // Create part & entity from resource
        Part[] parts = new Part[] { new FilePart(paramName, new ByteArrayPartSource(resourceName, fileContent),
                mimeType, (String) null) };
        MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts,
                new PostMethod().getParams());

        ByteArrayOutputStream requestContent = new ByteArrayOutputStream();
        multipartRequestEntity.writeRequest(requestContent);
        request.setContent(requestContent.toByteArray());
        // Set content type of request (important, includes MIME boundary string)
        String contentType = multipartRequestEntity.getContentType();
        request.setContentType(contentType);
        request.setMethod("POST");
        return request;
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}

From source file:de.qaware.cloud.deployer.commons.config.util.FileUtil.java

/**
 * Reads the content of the specified file into a string.
 *
 * @param file The file whose content will be returned.
 * @return The content of the file.//from  ww  w  . j a v  a  2s.c om
 * @throws ResourceConfigException If a problem with the file occurs.
 */
public static String readFileContent(File file) throws ResourceConfigException {
    try {
        if (file == null) {
            throw new ResourceConfigException(
                    COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_INVALID_FILENAME"));
        } else if (!file.exists()) {
            throw new ResourceConfigException(
                    COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_MISSING_FILE", file.getName()));
        }
        return FileUtils.readFileToString(file, Charset.defaultCharset()).trim();
    } catch (IOException e) {
        throw new ResourceConfigException(e.getMessage(), e);
    }
}