Example usage for java.io IOException IOException

List of usage examples for java.io IOException IOException

Introduction

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

Prototype

public IOException(Throwable cause) 

Source Link

Document

Constructs an IOException with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static void makedirs(File file) throws IOException {
    checkFile(file);//from  ww  w .j av  a  2  s.  c  o  m
    File parentFile = file.getParentFile();
    if (parentFile != null) {
        if (!parentFile.exists() && !parentFile.mkdirs()) {
            throw new IOException("Creating directories " + parentFile.getPath() + " failed.");
        }
    }
}

From source file:ee.ioc.phon.android.inimesed.MyFileUtils.java

public static void saveFile(File f, String content) throws IOException {
    File dir = f.getParentFile();
    if (!dir.exists() && !dir.mkdirs()) {
        throw new IOException("Cannot create directory: " + dir);
    }/*www  . j ava 2  s .c  o m*/
    FileUtils.writeStringToFile(f, content, "UTF8");
}

From source file:Main.java

/**
 * Loads an XML document from the given file.
 * @param file XML file to load./*from   ww w.j a  va2  s. c o  m*/
 * @param isValidating true: XML doc is validated against the DTD specifed
 *   within the XML document, false: otherwise.
 *   This does not work for XML Schemata! See {@link #load(File, Schema)}
 *   for that.
 * @param isNamespaceAware true: XML doc is namespace aware, false: otherwise.
 * @return Returns an XML document.
 * @throws IOException Throws an exception if the file couldn't be read.
 */
static public Document load(File file, boolean isValidating, boolean isNamespaceAware) throws IOException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(isValidating);
        factory.setNamespaceAware(isNamespaceAware);
        DocumentBuilder builder = factory.newDocumentBuilder();
        return (builder.parse(file));
    } catch (ParserConfigurationException pce) {
        throw new IOException("Parser configuration error: " + pce);
    } catch (SAXException se) {
        throw new IOException("XML parsing error: " + se);
    }
}

From source file:com.qwarz.graph.GraphManager.java

public static void load(File directory) throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    INSTANCE = new GraphManager(directory);
}

From source file:Main.java

public static boolean isTrustAnchor(X509Certificate certificate) throws IOException {
    boolean trust_anchor = certificate.getSubjectX500Principal().equals(certificate.getIssuerX500Principal())
            && certificate.getBasicConstraints() >= 0;
    if (trust_anchor) {
        try {/*ww w.  j av  a2  s .  c o m*/
            certificate.verify(certificate.getPublicKey());
        } catch (Exception e) {
            throw new IOException(e);
        }
        return true;
    }
    return false;
}

From source file:Main.java

public static String[] getExtendedKeyUsage(X509Certificate certificate) throws IOException {
    try {/*from  w  ww .j  av a  2s  . c om*/
        List<String> eku = certificate.getExtendedKeyUsage();
        if (eku == null) {
            return null;
        }
        return eku.toArray(new String[0]);
    } catch (GeneralSecurityException gse) {
        throw new IOException(gse);
    }
}

From source file:jp.furplag.util.commons.FileUtils.java

private static boolean createNewFile(String filename, boolean printStackTrace) {
    try {//ww w. j  a  v a 2s.  c  om
        if (StringUtils.isSimilarToBlank(filename))
            throw new IOException("path must not be empty.");
        String path = normalize(filename);
        File file = new File(path);
        if (file.exists() && file.isDirectory())
            throw new IOException(normalize(file.getAbsolutePath()) + " is directory.");
        path = normalize(file.getAbsolutePath());
        forceMkdir(StringUtils.truncateLast(path, "/.*"));
        if (!file.exists())
            return file.createNewFile();

    } catch (Exception e) {
        if (printStackTrace)
            e.printStackTrace();
    }

    return false;
}

From source file:Main.java

public static void save(String filename, Document document) throws IOException {
    PrintStream out = null;//w w w  . j  av  a 2 s .  c  o m
    try {
        out = new PrintStream(new BufferedOutputStream(new FileOutputStream(filename)), true, "UTF-8");
        //traceNode(document, "");
        print(out, document);
    } catch (Exception ex) {
        throw new IOException(ex.getLocalizedMessage());
    } finally {
        if (out != null)
            try {
                out.close();
            } catch (Exception e) {
                // ignore
            }
    }
}

From source file:Main.java

static public void searchTag(XmlPullParser xpp, String tag) throws IOException, XmlPullParserException {

    int event;//from   w  w  w.j  a v  a  2 s .  c o  m
    while ((event = xpp.next()) != XmlPullParser.END_DOCUMENT) {
        if (event == XmlPullParser.START_TAG && !xpp.getName().equals(tag))
            return;
    }

    throw new IOException(String.format("tag '%s' not found", tag));
}

From source file:Main.java

public static Document parse(File file) throws IOException {
    try {/* w ww .j  a v  a 2  s . c o  m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setCoalescing(true);
        factory.setIgnoringComments(true);
        factory.setIgnoringElementContentWhitespace(true);
        factory.setNamespaceAware(true);
        DocumentBuilder parser = factory.newDocumentBuilder();
        return parser.parse(file);
    } catch (ParserConfigurationException e) {
        throw new IOException(e);
    } catch (SAXException e) {
        throw new IOException(e);
    }
}