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

/**
 * Read the text from a file//w w  w .j  a v  a  2 s. c  om
 *
 * @param file the file to read text from
 * @return the loaded text
 */
public static String loadTextFromFile(File file) {

    if (file.exists()) {

        InputStreamReader isr = null;
        FileInputStream fis = null;
        try {

            fis = new FileInputStream(file);
            isr = new InputStreamReader(fis, StandardCharsets.UTF_8);

            StringBuilder stringBuilder = new StringBuilder();

            int i;
            while ((i = isr.read()) != -1) {
                stringBuilder.append((char) i);
            }
            return stringBuilder.toString();

        } catch (IOException ignored) {
        } finally {
            if (isr != null) {
                try {
                    isr.close();
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
        }
    }

    return "";
}

From source file:cloudlens.parser.FileReader.java

public static InputStream readFiles(String[] fileNames) throws IOException {
    try {//from  w w w.  ja  v  a 2  s  .  com
        final List<InputStream> streams = new ArrayList<>();
        for (final String name : fileNames) {
            streams.add(new FileInputStream(new File(name)));
        }
        final Enumeration<InputStream> files = Collections.enumeration(streams);
        return new SequenceInputStream(files);
    } catch (final IOException e) {
        throw new CLException(e.getMessage());
    }
}

From source file:be.vdab.util.Programma.java

private static TreeSet<Voertuig> lees(String file) {//gekozen voor treeSet , zo duidelijk dat er een TreeSet uitkomt (die serialiseerbaar is)
    TreeSet<Voertuig> voertuigen = null;
    ObjectInputStream ois = null;
    try {//from  w  w w.  j  a  v a  2s  .c om
        FileInputStream fis = new FileInputStream(file);
        ois = new ObjectInputStream(fis);
        voertuigen = (TreeSet<Voertuig>) ois.readObject();//je moet exact weten wat er is ingegaan, anders kan je object niet casten naar juiste klasse!?
    } catch (FileNotFoundException fnfe) {
        System.out.println(fnfe.getMessage());
    } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
    } catch (ClassNotFoundException cnfe) {
        System.out.println(cnfe.getMessage());
    } finally {
        try {
            ois.close();
        } catch (IOException ioe) {
            System.err.println(" ioe.getMessage()");
        }
    }

    return voertuigen;
}

From source file:io.servicecomb.swagger.generator.core.unittest.UnitTestSwaggerUtils.java

public static String loadExpect(String resPath) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(resPath);
    if (url == null) {
        return "can not found res " + resPath;
    }/* w w w.j a v a  2 s  . c om*/

    try {
        return IOUtils.toString(url);
    } catch (IOException e) {
        return e.getMessage();
    }
}

From source file:org.gbif.portal.web.util.ChartUtils.java

/**
 * Writes out the image using the supplied file name.
 * /*from w ww  . j  a va 2  s.c  o  m*/
 * @param legend
 * @param fileName
 * @return
 */
public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) {

    String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension;
    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName + defaultExtension;
    }

    final DefaultPieDataset data = new DefaultPieDataset();
    Set<String> keys = legend.keySet();
    for (String key : keys) {
        logger.info("Adding key : " + key);
        data.setValue(key, legend.get(key));
    }

    // create a pie chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false);

    PiePlot piePlot = (PiePlot) chart.getPlot();
    piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    piePlot.setLabelBackgroundPaint(Color.WHITE);

    LegendTitle lt = chart.getLegend();
    lt.setBackgroundPaint(Color.WHITE);
    lt.setWidth(300);
    lt.setBorder(0, 0, 0, 0);
    lt.setItemFont(new Font("Arial", Font.PLAIN, 11));

    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250);

    // draw
    chart.draw(g2, chartArea, null, null);

    try {
        FileOutputStream fOut = new FileOutputStream(fileToCheck);
        ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250);
        return fileToCheck.getName();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:io.github.bluemarlin.util.BluemarlineUtil.java

public static String loadFromClassPath(Class<?> clazz, String classPath) {
    System.out.println("loadFromClassPath: " + classPath);
    String page = "";
    try {/*from ww w. jav a2 s .  c o m*/
        InputStream is = clazz.getResourceAsStream(classPath);
        page = IOUtils.toString(is);
    } catch (IOException e) {
        System.out.println("Exception" + e.getMessage());
        // won't likely happen since file is in classpath
        e.printStackTrace();
    }
    return page;
}

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

/**
 * Creates a file with the content read from the URL
 * @param theUrl the URL where the content is
 * @return a File with the content from the URL
 *///from   w w w  .j  ava  2  s .  c o m
public static File createAndWriteTempFileFromUrl(String theUrl) {
    File tempOutputFile = null;
    String message;
    try {
        tempOutputFile = File.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);

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

}

From source file:com.github.tomakehurst.wiremock.common.Json.java

public static <T> T read(String json, Class<T> clazz) {
    try {/*from  w ww . j av a2s  .com*/
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        return mapper.readValue(json, clazz);
    } catch (IOException ioe) {
        throw new RuntimeException(
                "Unable to bind JSON to object. Reason: " + ioe.getMessage() + "  JSON:" + json, ioe);
    }
}

From source file:com.pkrete.xrd4j.rest.util.ClientUtil.java

/**
 * Extracts the response string from the given HttpEntity.
 * @param entity HttpEntity that contains the response
 * @return response String//from   ww  w  .  ja  va2s .c o  m
 */
public static String getResponseString(HttpEntity entity) {
    StringBuilder builder = new StringBuilder();
    if (entity != null) {
        String inputLine;
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(entity.getContent()));
            while ((inputLine = in.readLine()) != null) {
                builder.append(inputLine);
            }
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }
    return builder.toString();
}

From source file:idgs.client.util.JsonUtil.java

/**
 * read json file content to StringBuilder
 * @param file//from  w  w w  .  jav a 2  s  . com
 * @return
 * @throws IOException
 */
public static StringBuilder getJsonFromFile(File file) throws IOException {
    BufferedReader br = null;
    StringBuilder builder = new StringBuilder();
    String line = null;
    FileInputStream fs = new FileInputStream(file);
    try {
        br = new BufferedReader(new InputStreamReader(fs));
        while ((line = br.readLine()) != null) {
            builder.append(line).append("\r\n");
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        if (br != null) {
            try {
                br.close();
                fs.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }
    return builder;
}