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

/**
 * Takes in the file stream to the offline file storage that is going to be written to and
 * the latest trip data that is going to be written to the offline storage file.
 * <p/>//from w  w w . j av  a 2  s.co  m
 * The new trip data will then be appended to the rest of the trip data.
 *
 * @param writer The output stream of the offline file for storage. Get this from {@link android.content.Context#openFileOutput}
 * @param line   The new trip data as a String
 */
public synchronized static void writeToOfflineStorage(FileOutputStream writer, String line) {
    try {
        line += "\n";
        writer.write(line.getBytes());
    } catch (IOException e) {
        //TODO: Handle IO exception
        Log.d("ERROR", "IO Exception in OfflineUtilities#writeToOfflineStorage: " + e.getMessage());
    }
}

From source file:com.github.ipaas.ideploy.plugin.core.ChineseFileNameFilter.java

public static void deleteChineseNameFile(String prePath, File rootFile) {
    if (CharUtil.isChinese(rootFile.getName())) {
        try {/*from w w  w  . jav  a  2s.c  o  m*/
            if (rootFile.isDirectory()) {
                ConsoleHandler.error("??:"
                        + StringUtils.removePrefix(rootFile.getAbsolutePath().replaceAll("\\\\", "/"), prePath)
                        + "  ?");
                FileUtils.deleteDirectory(rootFile);
            } else {
                ConsoleHandler.error("??:"
                        + StringUtils.removePrefix(rootFile.getAbsolutePath().replaceAll("\\\\", "/"), prePath)
                        + "  ?");
                FileUtils.forceDelete(rootFile);
            }
        } catch (IOException e) {
            ConsoleHandler.error(":" + e.getMessage());
        }
    }
    if (rootFile.isDirectory()) {
        File[] files = rootFile.listFiles();
        for (int i = 0; i < files.length; i++) {
            System.out.println(files[i].getAbsolutePath());
            deleteChineseNameFile(prePath, files[i]); // ?
        }
    }
}

From source file:it.cnr.ilc.ilcioutils.IlcInputToFile.java

/**
 * Creates a file with the content read from string
 * @param string the String with the content is
 * @return a File with the content from the URL
 *//*from  ww  w . j a  v a 2 s  .c om*/
public static File createAndWriteTempFileFromString(String string) {
    File tempOutputFile = null;
    String encoding = "UTF-8";
    String message;
    try {
        tempOutputFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
        FileUtils.writeStringToFile(tempOutputFile, string, encoding);

    } catch (IOException e) {
        message = String.format("Error in accessing String %s %s", string, e.getMessage());
        Logger.getLogger(CLASS_NAME).log(Level.SEVERE, message);
    }
    return tempOutputFile;

}

From source file:io.getlime.push.repository.serialization.JSONSerialization.java

/**
 * Parsing message from JSON to PushMessageBody object.
 *
 * @param message Message to parse// w  w w. ja v  a2  s.com
 * @return PushMessageBody
 */
public static PushMessageBody deserializePushMessageBody(String message) throws PushServerException {
    PushMessageBody pushMessageBody;
    try {
        pushMessageBody = new ObjectMapper().readValue(message, PushMessageBody.class);
    } catch (IOException e) {
        Logger.getLogger(PushCampaignController.class.getName()).log(Level.SEVERE, e.getMessage(), e);
        throw new PushServerException("Failed parsing from JSON");
    }
    return pushMessageBody;
}

From source file:att.jaxrs.util.Marshal.java

public static <T> T unmarshal(Class<T> xmlType, InputStream inputStream) {
    System.out.println("unmarshalling input stream");
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    StringBuilder out = new StringBuilder();
    try {/*from  w w  w .  jav  a 2  s  . c  om*/
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
    String namespace = out.toString();

    namespace = namespace.replaceAll(Constants.DATA_SERVICE_XMLNS, "");

    InputStream stream = Util.getInputStreamFromString(namespace);
    JAXBContext jaxbContext;
    XmlRootElement doc = null;
    try {
        jaxbContext = JAXBContext.newInstance(xmlType);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        doc = (XmlRootElement) unmarshaller.unmarshal(stream);
        System.out.println("unmarshall successful");
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return (T) doc;
}

From source file:com.jdy.ddj.common.utils.PropertiesLoader.java

/**
 * , Spring Resource?./*from  w w w .  ja v  a  2 s  . c  om*/
 */
public static Properties loadProperties(String... resourcesPaths) throws IOException {
    Properties props = new Properties();

    for (String location : resourcesPaths) {

        logger.debug("Loading properties file from:" + location);

        InputStream is = null;
        try {
            Resource resource = resourceLoader.getResource(location);
            is = resource.getInputStream();
            props.load(is);
        } catch (IOException ex) {
            logger.info("Could not load properties from path:" + location + ", " + ex.getMessage());
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return props;
}

From source file:com.homesoft.component.report.pdf.XhtmlPdfGenerator.java

protected static void init() {
    instance = new XhtmlPdfGenerator();
    fmConfigFactory = new FreeMarkerConfigurationFactory();
    try {/*from  w ww . j  a v a  2  s.  c om*/
        fmConfig = fmConfigFactory.createConfiguration();
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (TemplateException e) {
        log.error(e.getMessage(), e);
    }
}

From source file:dk.dbc.rawrepo.oai.ResumptionToken.java

/**
 * Decode a base64 string (or a json string) into a json object
 *
 * @param token resumption token//from w ww. j a v  a 2  s  .c  o  m
 * @return object
 * @throws java.io.IOException Unlikely, ByteArrayInputStream is broken
 */
public static ObjectNode decode(String token) throws IOException {
    if (!token.startsWith("{")) {
        long now = Instant.now().toEpochMilli() / 1000L;
        String decoded = PackText.decode(token);
        int indexOf = decoded.indexOf('{');
        long epoch = Long.parseLong(decoded.substring(0, indexOf), 16);
        if (epoch < now) {
            throw new OAIException(OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN, "ResumptionToken expired");
        }
        token = decoded.substring(indexOf);
    }
    try {
        return (ObjectNode) OBJECT_MAPPER.readTree(token);
    } catch (IOException ex) {
        log.error("Exception:" + ex.getMessage());
        log.debug("Exception:", ex);
        throw new OAIException(OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN, "bad token");
    }
}

From source file:org.dataconservancy.ui.it.support.HttpRequestLogger.java

public static void logResponse(HttpResponse res) {
    StringBuilder msg = new StringBuilder("HTTP Response:\n");
    msg.append(res.getStatusLine().toString()).append("\n");
    for (Header h : res.getAllHeaders()) {
        msg.append(h.getName()).append(": ").append(h.getValue()).append("\n");
    }//from w  w w . j  av  a 2s .c  o  m
    msg.append("\n");

    HttpEntity entity = res.getEntity();

    try {
        msg.append(IOUtils.toString(entity.getContent(), "UTF-8"));
        msg.append("\n");
    } catch (IOException e) {
        msg.append("** Cannot display entity body: ").append(e.getMessage());
    }

    msg.append("\n\n");
    LOG.error(msg.toString());
}

From source file:io.confluent.support.metrics.utils.WebClient.java

/**
 * Sends a POST request to a web server/*  www .j a  va 2  s .co m*/
 * @param customerId: customer Id on behalf of which the request is sent
 * @param bytes: request payload
 * @param httpPost: A POST request structure
 * @return an HTTP Status code
 */
public static int send(String customerId, byte[] bytes, HttpPost httpPost) {
    int statusCode = DEFAULT_STATUS_CODE;
    if (bytes != null && bytes.length > 0 && httpPost != null && customerId != null) {

        // add the body to the request
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addTextBody("cid", customerId);
        builder.addBinaryBody("file", bytes, ContentType.DEFAULT_BINARY, "filename");
        httpPost.setEntity(builder.build());

        // set the HTTP config
        final RequestConfig config = RequestConfig.custom().setConnectTimeout(requestTimeoutMs)
                .setConnectionRequestTimeout(requestTimeoutMs).setSocketTimeout(requestTimeoutMs).build();

        // send request
        try (CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultRequestConfig(config)
                .build(); CloseableHttpResponse response = httpclient.execute(httpPost)) {
            log.debug("POST request returned {}", response.getStatusLine().toString());
            statusCode = response.getStatusLine().getStatusCode();
        } catch (IOException e) {
            log.debug("Could not submit metrics to Confluent: {}", e.getMessage());
        }
    } else {
        statusCode = HttpStatus.SC_BAD_REQUEST;
    }
    return statusCode;
}