Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.nuvolect.deepdive.util.FileUtil.java

public static void writeFile(File file, String fileContents) {

    try {/*from  w w w .j a va2s  .  com*/
        OutputStream out = null;

        FileUtils.forceMkdirParent(file);

        out = new BufferedOutputStream(new FileOutputStream(file));

        out.write(fileContents.getBytes());

        if (out != null)
            out.close();
    } catch (IOException e) {
        LogUtil.log(FileUtil.class, "File write failed: " + e.toString());
    }
}

From source file:ConnectionUtil.java

/** Get a Connection for the given config using the default or set property file name */
public static Connection getConnection(String config) throws Exception {
    try {/*from w  w  w.  j av a 2 s .c  o m*/
        Properties p = new Properties();
        p.load(new FileInputStream(configFileName));
        return getConnection(p, config);
    } catch (IOException ex) {
        throw new Exception(ex.toString());
    }
}

From source file:Main.java

/**
 * Decodes the given Base64 encoded String to a new byte array. The byte array holding the
 * decoded data is returned./*from  w  w w  .j  a v  a  2  s .  c  om*/
 */

public static byte[] decode(String s) {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        decode(s, bos);
    } catch (IOException e) {
        throw new RuntimeException();
    }
    byte[] decodedBytes = bos.toByteArray();
    try {
        bos.close();
        bos = null;
    } catch (IOException ex) {
        System.err.println("Error while decoding BASE64: " + ex.toString());
    }
    return decodedBytes;
}

From source file:org.gephi.statistics.plugin.ChartUtils.java

public static String renderChart(JFreeChart chart, String fileName) {
    String imageFile = "";
    try {//  ww w.  java  2  s  .  co m
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        TempDir tempDir = TempDirUtils.createTempDir();
        File file1 = tempDir.createFile(fileName);
        imageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>";
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return imageFile;
}

From source file:Main.java

public static String saveImageToTemporaryDirectory(Bitmap image) {
    Log.d(TAG, "[AirImagePickerUtils] Entering saveImageToTemporaryDirectory");
    String path = "";
    FileOutputStream outputStream;
    try {//w w w .jav  a  2s . c  o m
        File file = getTemporaryFile(".jpg");
        outputStream = new FileOutputStream(file);
        outputStream.write(getJPEGRepresentationFromBitmap(image));
        outputStream.close();
        path = file.getAbsolutePath();
        Log.d(TAG, "[AirImagePickerUtils] saveImageToTemporaryDirectory path:" + path);
    } catch (IOException e) {
        Log.e(TAG, "[AirImagePickerUtils] saveImageToTemporaryDirectory error:" + e.toString());
        // Error while creating file
    }
    Log.d(TAG, "[AirImagePickerUtils] Exiting saveImageToTemporaryDirectory");
    return path;
}

From source file:org.apache.storm.elasticsearch.common.EsTestUtil.java

/**
 * Stop the given Elasticsearch node and clear the data directory.
 * @param node/*from   w w  w .j  ava 2  s.c  o m*/
 */
public static void stopEsNode(Node node) {
    node.close();
    try {
        FileUtils.deleteDirectory(new File("./data"));
    } catch (IOException e) {
        LOG.warn(e.toString());
    }
}

From source file:com.cloudera.sqoop.testutil.SeqFileReader.java

public static Object getFirstValue(String filename) throws IOException {
    Reader r = null;// www . j a v  a  2s  . c  om
    try {
        // read from local filesystem
        Configuration conf = new Configuration();
        if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
            conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
        }
        FileSystem fs = FileSystem.get(conf);
        r = new SequenceFile.Reader(fs, new Path(filename), conf);
        Object key = ReflectionUtils.newInstance(r.getKeyClass(), conf);
        Object val = ReflectionUtils.newInstance(r.getValueClass(), conf);
        LOG.info("Reading value of type " + r.getValueClassName() + " from SequenceFile " + filename);
        r.next(key);
        r.getCurrentValue(val);
        LOG.info("Value as string: " + val.toString());
        return val;
    } finally {
        if (null != r) {
            try {
                r.close();
            } catch (IOException ioe) {
                LOG.warn("IOException during close: " + ioe.toString());
            }
        }
    }
}

From source file:eu.digitisation.idiomaident.utils.ExtractTestSamples.java

private static void extractSamples(int numSamples, File inFolder, File outFile) {
    FileOutputStream fileOS = null;
    OutputStreamWriter outSWriter = null;

    try {/*from   w  w  w  . j  a v a  2  s. com*/
        fileOS = new FileOutputStream(outFile);
        outSWriter = new OutputStreamWriter(fileOS, Charset.forName("UTF8"));

        int num = 0;
        while (num < numSamples) {
            String sample = nextSample(inFolder);

            if (sample == null)
                continue;

            outSWriter.write(sample);
            num++;
            System.out.println("Generating " + num + " of " + numSamples + " samples");
        }

        outSWriter.flush();

    } catch (IOException ex) {
        System.out.println(ex.toString());
    } finally {
        try {
            if (outSWriter != null) {
                outSWriter.close();
            }
        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
    }

}

From source file:Main.java

/**
 *
 *
 * @param in .../*from  w  ww .j a  v a2  s.c  o m*/
 *
 * @return ...
 *
 * @throws RuntimeException ...
 */
public static Document parse(InputStream in) throws RuntimeException {
    DocumentBuilder d = getDocumentBuilder();

    try {
        Document doc = d.parse(in);

        doc.normalize();

        return doc;
    } catch (SAXException e) {
        throw new RuntimeException("Bad xml-code: " + e.toString());
    } catch (IOException f) {
        throw new RuntimeException("Could not read Xml: " + f.toString());
    }
}

From source file:Main.java

/**
 *
 *
 * @param in .../*from   w  ww. j a  v a  2 s  .com*/
 *
 * @return ...
 *
 * @throws RuntimeException ...
 */
public static Document parse(InputSource in) throws RuntimeException {
    DocumentBuilder d = getDocumentBuilder();

    try {
        Document doc = d.parse(in);

        doc.normalize();

        return doc;
    } catch (SAXException e) {
        throw new RuntimeException("Bad xml-code: " + e.toString());
    } catch (IOException f) {
        throw new RuntimeException("Could not read Xml: " + f.toString());
    }
}