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:de.neofonie.aiko.Runner.java

private static boolean runAllTests(final Context context) {
    boolean result = true;

    for (int i = 0; i < context.getTestGroups().size() && result; i++) {
        final Group group = context.getTestGroups().get(i);
        System.out.print("Group: '" + group.getName() + "': \n");

        try {/*from w ww  . ja va2 s  . c  om*/
            result = runTestsInGroup(context, group);
        } catch (IOException e) {
            System.out.println("[ERROR] Test execution failed. Reason: " + e.getMessage());
            e.printStackTrace();
            result = false;
        }

        System.out.println("\n");
    }

    if (FAILED_TEST_COUNTER > 0) {
        printFailedTestCounter();
    }

    return result;
}

From source file:info.magnolia.cms.util.RequestDispatchUtil.java

/**
 * Returns true if processing took place, even if it fails.
 *//*w w  w .j  a v  a2 s .  com*/
public static boolean dispatch(String targetUri, HttpServletRequest request, HttpServletResponse response) {

    if (targetUri == null) {
        return false;
    }

    if (targetUri.startsWith(REDIRECT_PREFIX)) {
        String redirectUrl = StringUtils.substringAfter(targetUri, REDIRECT_PREFIX);
        try {

            if (isInternal(redirectUrl)) {
                redirectUrl = request.getContextPath() + redirectUrl;
            }

            response.sendRedirect(response.encodeRedirectURL(redirectUrl));

        } catch (IOException e) {
            log.error("Failed to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(PERMANENT_PREFIX)) {
        String permanentUrl = StringUtils.substringAfter(targetUri, PERMANENT_PREFIX);
        try {

            if (isInternal(permanentUrl)) {
                if (isUsingStandardPort(request)) {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getContextPath() + permanentUrl).toExternalForm();
                } else {
                    permanentUrl = new URL(request.getScheme(), request.getServerName(),
                            request.getServerPort(), request.getContextPath() + permanentUrl).toExternalForm();
                }
            }

            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", permanentUrl);

        } catch (MalformedURLException e) {
            log.error("Failed to create permanent url to redirect to {}:{}", targetUri, e.getMessage());
        }
        return true;
    }

    if (targetUri.startsWith(FORWARD_PREFIX)) {
        String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
        try {
            request.getRequestDispatcher(forwardUrl).forward(request, response);
        } catch (Exception e) {
            log.error("Failed to forward to {} - {}:{}",
                    new Object[] { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
        }
        return true;
    }

    return false;
}

From source file:avantssar.aslanpp.testing.HTMLHelper.java

public static File toHTML(File textFile, boolean lineNumbers) {
    if (textFile != null) {
        File htmlFile = new File(textFile.getAbsolutePath() + ".html");
        try {//from  w w w . j a v a2s .c  o m
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(textFile)));
            PrintWriter writer = new PrintWriter(htmlFile);
            String line;
            writer.println("<html>");
            writer.println("<body>");
            writer.println("<pre>");
            int lineCount = 1;
            while ((line = reader.readLine()) != null) {
                if (lineNumbers) {
                    line = String.format("%4d:   %s", lineCount++, line);
                }
                writer.println(line);
            }
            writer.println("</pre>");
            writer.println("</body>");
            writer.println("</html>");
            reader.close();
            writer.close();
            return htmlFile;
        } catch (IOException ex) {
            System.out.println(
                    "Failed to convert to HTML file '" + textFile.getAbsolutePath() + "': " + ex.getMessage());
            Debug.logger.error(ex);
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.openkm.util.ImageUtils.java

/**
 * crop/* w w w. j  av  a2s  .  co  m*/
 */
public static byte[] crop(byte[] img, int x, int y, int width, int height) throws RuntimeException {
    log.debug("crop({}, {}, {}, {}, {})", new Object[] { img.length, x, y, width, height });
    ByteArrayInputStream bais = new ByteArrayInputStream(img);
    byte[] imageInByte;

    try {
        BufferedImage image = ImageIO.read(bais);
        BufferedImage croppedImage = image.getSubimage(x, y, width, height);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(croppedImage, "png", baos);
        baos.flush();
        imageInByte = baos.toByteArray();
        IOUtils.closeQuietly(baos);
    } catch (IOException e) {
        log.error(e.getMessage());
        throw new RuntimeException("IOException: " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(bais);
    }

    log.debug("crop: {}", imageInByte.length);
    return imageInByte;
}

From source file:es.tid.cep.esperanza.Utils.java

public static boolean DoHTTPPost(String urlStr, String content) {
    try {// w  w  w  .ja  v a  2 s  .  c o  m
        URL url = new URL(urlStr);
        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        OutputStreamWriter printout = new OutputStreamWriter(urlConn.getOutputStream(),
                Charset.forName("UTF-8"));
        printout.write(content);
        printout.flush();
        printout.close();

        int code = urlConn.getResponseCode();
        String message = urlConn.getResponseMessage();
        logger.debug("action http response " + code + " " + message);
        if (code / 100 == 2) {
            InputStream input = urlConn.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            for (String line; (line = reader.readLine()) != null;) {
                logger.debug("action response body: " + line);
            }
            input.close();
            return true;

        } else {
            logger.error("action response is not OK: " + code + " " + message);
            InputStream error = urlConn.getErrorStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(error));
            for (String line; (line = reader.readLine()) != null;) {
                logger.error("action error response body: " + line);
            }
            error.close();
            return false;
        }
    } catch (MalformedURLException me) {
        logger.error("exception MalformedURLException: " + me.getMessage());
        return false;
    } catch (IOException ioe) {
        logger.error("exception IOException: " + ioe.getMessage());
        return false;
    }
}

From source file:iplantappssplitter.IPlantAppsSplitter.java

/**
 * WriteFile writes the string jsonToWrite to the file filename
 * @param filename/*from w ww .  j av a2 s .  c om*/
 * @param jsonToWrite 
 */
public static void WriteFile(String filename, String jsonToWrite) {
    try {
        Files.write(Paths.get(myArgs.getOutputDirectory() + filename), jsonToWrite.getBytes());
    } catch (IOException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    }
}

From source file:com.elsevier.xml.XQueryProcessor.java

/**
 * Apply the xqueryExpression to the specified string and return a
 * serialized response.// w  w  w  .j  a  va 2  s .c  om
 * 
 * @param content
 *            String to which the xqueryExpression will be applied
 * @param xqueryExpression
 *            XQuery expression to apply to the content
 * 
 * @return Serialized response from the evaluation. If an error, the response will be "<error/>".
 */
public static String evaluateString(String content, String xqueryExpression) {

    try {

        return evaluate(new StreamSource(IOUtils.toInputStream(content, CharEncoding.UTF_8)), xqueryExpression);

    } catch (IOException e) {

        log.error("Problems processing the content.  " + e.getMessage(), e);
        return "<error/>";

    }

}

From source file:com.wegas.log.neo4j.Neo4jUtils.java

/**
 * Extracts the data part from the JSON result of a query. The data is
 * returned as a list of string(s). If no data was found, an empty list is
 * returned./*from  www.  j a  v a 2 s . c o  m*/
 *
 * @param result the result of a query
 * @return the data list as a Json object
 */
protected static ArrayNode extractListData(String result) {
    ArrayNode on = objectMapper.createArrayNode();
    ObjectMapper om = new ObjectMapper();
    try {
        JsonNode jn = om.readTree(result);
        JsonNode jnRes = jn.path("results");
        Iterator<JsonNode> ite1 = jnRes.elements();
        while (ite1.hasNext()) {
            JsonNode jn1 = ite1.next();
            JsonNode jnDat = jn1.path("data");
            Iterator<JsonNode> ite2 = jnDat.elements();
            while (ite2.hasNext()) {
                JsonNode jn2 = ite2.next();
                JsonNode jnRow = jn2.path("row");
                Iterator<JsonNode> ite3 = jnRow.elements();
                while (ite3.hasNext()) {
                    JsonNode jn3 = ite3.next();
                    on.add(jn3);
                }
            }
        }
    } catch (IOException ioe) {
        logger.debug("Error in extractListData: " + ioe.getMessage());
    }
    return on;
}

From source file:de.dkt.eservices.elucene.indexmanagement.SearchFiles.java

/**
 * Searches a query against a field of an index and return hitsToReturn documents.
 * @param index index where to search for the query text
 * @param field document field against what to match the query
 * @param queryString text of the input query
 * @param hitsToReturn number of documents to be returned
 * @return JSON format string containing the results information and content
 * @throws ExternalServiceFailedException
 *///from w  w w .  j  ava  2  s.  c om
public static JSONObject search(String index, String sFields, String sAnalyzers, String queryType,
        String queryString, String language, int hitsToReturn) throws ExternalServiceFailedException {
    try {
        //         System.out.println(index+"__"+sFields+"__"+sAnalyzers+"__"+queryType+"__"+language+"__"+hitsToReturn);
        //         System.out.println(indexDirectory);
        Date start = new Date();

        File f = FileFactory.generateFileInstance(indexDirectory + index);
        if (f == null || !f.exists()) {
            throw new ExternalServiceFailedException(
                    "Specified index [" + indexDirectory + index + "] does not exists.");
        }
        logger.info("Searching in folder: " + f.getAbsolutePath());
        Directory dir = FSDirectory.open(f);
        IndexReader reader = DirectoryReader.open(dir);
        IndexSearcher searcher = new IndexSearcher(reader);

        //         System.out.println(reader.docFreq(new Term("content", "madrid")));

        Document doc = reader.document(0);
        //         System.out.println(reader.numDocs());
        //         System.out.println(doc);

        String[] fields = sFields.split(";");
        String[] analyzers = sAnalyzers.split(";");
        if (fields.length != analyzers.length) {
            logger.error("The number of fields and analyzers is different");
            throw new BadRequestException("The number of fields and analyzers is different");
        }

        //System.out.println("CHECK IF THE QUERY IS WORKING PROPERLY: "+queryString);
        Query query = OwnQueryParser.parseQuery(queryType, queryString, fields, analyzers, language);

        //System.out.println("\t QUERY: "+query);

        TopDocs results = searcher.search(query, hitsToReturn);

        Explanation exp = searcher.explain(query, 0);
        //         System.out.println("EXPLANATION: "+exp);

        //         System.out.println("TOTAL HITS: " + results.totalHits);

        Date end = new Date();
        logger.info("Time: " + (end.getTime() - start.getTime()) + "ms");
        //         System.out.println("Time: "+(end.getTime()-start.getTime())+"ms");

        JSONObject resultModel = JSONLuceneResultConverter.convertResults(query, searcher, results);
        reader.close();
        return resultModel;
    } catch (IOException e) {
        e.printStackTrace();
        throw new ExternalServiceFailedException("IOException with message: " + e.getMessage());
    }
}

From source file:uk.ac.sanger.cgp.wwdocker.actions.Utils.java

public static Object jsonToObject(String json, Class classType) {
    ObjectMapper mapper = new ObjectMapper();
    Object obj;//from   ww  w  . ja  va  2 s .c o  m
    try {
        obj = mapper.readValue(json, classType);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return obj;
}