Example usage for java.io IOException initCause

List of usage examples for java.io IOException initCause

Introduction

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

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:Main.java

/**
 * Parse a DOM Document from the given XML file. 
 * //from   www . j  a  va2s  .  c om
 * @param f File to parse as Document
 * @return Document
 * @throws IOException
 */
public static Document getDocument(File f) throws IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true); // never forget this!
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(f);
    } catch (ParserConfigurationException e) {
        IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
    } catch (SAXException e) {
        IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:Main.java

static void emitDocument(Document doc, OutputStream os, String encoding) throws IOException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;/*  w w w .  j a  v  a 2s .  com*/
    try {
        t = tf.newTransformer();
        //SF:no dtd            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
        assert (false);
    }
    DOMSource doms = new DOMSource(doc);
    StreamResult sr = new StreamResult(os);
    try {
        t.transform(doms, sr);
    } catch (TransformerException te) {
        IOException ioe = new IOException();
        ioe.initCause(te);
        throw ioe;
    }
}

From source file:Main.java

static void emitDocument(Document doc, OutputStream os, String encoding) throws IOException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;/* w ww  .j av  a 2s. c o  m*/
    try {
        t = tf.newTransformer();
        t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
        t.setOutputProperty(OutputKeys.INDENT, "yes");
        t.setOutputProperty(OutputKeys.METHOD, "xml");
        t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
        assert (false);
    }
    DOMSource doms = new DOMSource(doc);
    StreamResult sr = new StreamResult(os);
    try {
        t.transform(doms, sr);
    } catch (TransformerException te) {
        IOException ioe = new IOException();
        ioe.initCause(te);
        throw ioe;
    }
}

From source file:org.apache.hama.util.ClusterUtil.java

/**
 * Creates a {@link GroomServerThread}. Call 'start' on the returned thread to
 * make it run./*from ww w  .  j ava 2  s .com*/
 * 
 * @param c Configuration to use.
 * @param hrsc Class to create.
 * @param index Used distingushing the object returned.
 * @throws IOException
 * @return Groom server added.
 */
public static ClusterUtil.GroomServerThread createGroomServerThread(final Configuration c,
        final Class<? extends GroomServer> hrsc, final int index) throws IOException {
    GroomServer server;
    try {
        server = hrsc.getConstructor(Configuration.class).newInstance(c);
    } catch (Exception e) {
        IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
    }
    return new ClusterUtil.GroomServerThread(server, index);
}

From source file:Main.java

/** Parse an XML document using Saxon.
 *  @param filename The file name of the xml file to be read in
 *  The filename is passed to org.xml.sax.InputSource(String),
 *  so it may be a file name or a URL./*from   www.  j  av a2 s  .  c o m*/
 *  @return the parsed document.
 *  @exception ParserConfigurationException If there is a problem
 *  creating the DocumentBuilder.
 *  @exception IOException If the filename could not be parsed.
 */
public static Document parse(String filename) throws ParserConfigurationException, IOException {
    // FIXME: Throw something other than Exception
    //        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
    //                "net.sf.saxon.om.DocumentBuilderFactoryImpl");

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    // We use InputSource here so that we can specify the filename
    // argument as a jar url so that HSIFToMoML works under Web Start.
    try {
        return builder.parse(new InputSource(filename));
    } catch (SAXException ex) {
        // Rethrow this with the filename included.
        IOException exception = new IOException("Failed to parse '" + filename + "'");
        exception.initCause(ex);
        throw exception;
    }
}

From source file:com.chinamobile.bcbsp.util.ClusterUtil.java

/**
 * Creates a {@link WorkerManagerThread}. Call 'start' on the returned thread
 * to make it run./*w w w  .  j a v a  2 s  . c  om*/
 *
 * @param c
 *        Configuration to use.
 * @param hrsc
 *        Class to create.
 * @param index
 *        Used distingushing the object returned.
 * @throws IOException
 * @return Groom server added.
 */
public static ClusterUtil.WorkerManagerThread createWorkerManagerThread(final Configuration c,
        final Class<? extends WorkerManager> hrsc, final int index) throws IOException {
    WorkerManager server;
    try {
        server = hrsc.getConstructor(Configuration.class).newInstance(c);
    } catch (Exception e) {
        LOG.error("[createWorkerManagerThread]", e);
        IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
    }
    return new ClusterUtil.WorkerManagerThread(server, index);
}

From source file:org.crazydog.util.spring.FileSystemUtils.java

/**
 * Actually copy the contents of the {@code src} file/directory
 * to the {@code dest} file/directory.//  w w  w  .  j  ava2s .  c om
 *
 * @param src  the source directory
 * @param dest the destination directory
 * @throws IOException in the case of I/O errors
 */
private static void doCopyRecursively(File src, File dest) throws IOException {
    if (src.isDirectory()) {
        dest.mkdir();
        File[] entries = src.listFiles();
        if (entries == null) {
            throw new IOException("Could not list files in directory: " + src);
        }
        for (File entry : entries) {
            doCopyRecursively(entry, new File(dest, entry.getName()));
        }
    } else if (src.isFile()) {
        try {
            dest.createNewFile();
        } catch (IOException ex) {
            IOException ioex = new IOException("Failed to create file: " + dest);
            ioex.initCause(ex);
            throw ioex;
        }
        FileCopyUtils.copy(src, dest);
    } else {
        // Special File handle: neither a file not a directory.
        // Simply skip it when contained in nested directory...
    }
}

From source file:org.apache.camel.util.IOHelper.java

/**
 * A factory method which creates an {@link IOException} from the given
 * exception and message/*from  ww w  .j  av  a  2  s.co m*/
 */
public static IOException createIOException(String message, Throwable cause) {
    IOException answer = new IOException(message);
    answer.initCause(cause);
    return answer;
}

From source file:uk.digitalsquid.droidpad.layout.JsonDecoder.java

public static final ModeSpec decodeLayout(Reader reader) throws IOException {
    StringBuffer contents = new StringBuffer();
    char[] buf = new char[1024];
    int read = -1;
    while ((read = reader.read(buf)) != -1) {
        contents.append(buf, 0, read);//  ww  w . j a  va 2  s .  com
    }
    try {
        return decodeLayout(contents.toString());
    } catch (JSONException e) {
        IOException e1 = new IOException("Failed to parse JSON string from reader");
        e1.initCause(e);
        throw e1;
    }
}

From source file:org.jboss.spring.vfs.VFSResource.java

static Object getChild(URL url) throws IOException {
    try {/*from  w w  w.  j a  v  a2 s. c  o m*/
        return VFSUtil.invokeMethodWithExpectedExceptionType(VFSUtil.VFS_METHOD_GET_ROOT_URL, null,
                URISyntaxException.class, url);
    } catch (URISyntaxException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }
}