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(String message, Throwable cause) 

Source Link

Document

Constructs an IOException with the specified detail message and cause.

Usage

From source file:Main.java

public static Document newDomDocument() throws IOException {
    try {//from w w  w.j  a v  a2 s  .co m
        DocumentBuilderFactory factory = newDocumentBuilderFactory();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException("Can't create new DOM-document.", e);
    }
}

From source file:Main.java

/**
 * Stores object into file.//from  w  w w  .ja v a 2  s .c o  m
 *
 * @param m marshaller
 * @param out output file
 * @param o object to be stored
 * @throws IOException if some error occurs
 */
private static void marshal(Marshaller m, File out, Object o) throws IOException {
    try (FileOutputStream fos = new FileOutputStream(out)) {
        m.marshal(o, fos);
    } catch (JAXBException ex) {
        throw new IOException("Cannot write object to file - " + ex.getMessage(), ex);
    }
}

From source file:Main.java

public static Document newDocument() throws IOException {
    try {//  w w  w  .  ja  v a2 s. c  o  m
        return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage(), e);
    }
}

From source file:Main.java

@Nonnull
public static Document newDomDocument() throws IOException {
    try {//  w  ww.  java 2s  .  c  o  m
        DocumentBuilderFactory factory = newDocumentBuilderFactory();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException("Can't create new DOM-document.", e);
    }
}

From source file:Main.java

public static Document load(InputStream data) throws SAXException, IOException {
    try {//from  w  w w  .jav  a 2  s  . c  om
        return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(data);
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage(), e);
    }
}

From source file:Main.java

public static String getDataDirectory(Context context) throws IOException {
    try {//from www.j  ava  2 s .c om
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.dataDir;
    } catch (PackageManager.NameNotFoundException nnfe) {
        throw new IOException("Cannot access to data directory", nnfe);
    }
}

From source file:Main.java

public static File getRobotCacheFile(Context context, String assetname) throws IOException {
    File cacheFile = new File(context.getCacheDir(), assetname);
    try {/*  www. ja  v  a2  s  .  com*/
        InputStream inputStream = context.getAssets().open(assetname);
        try {
            FileOutputStream outputStream = new FileOutputStream(cacheFile);
            try {
                byte[] buf = new byte[1024];
                int len;
                while ((len = inputStream.read(buf)) > 0) {
                    outputStream.write(buf, 0, len);
                }
            } finally {
                outputStream.close();
            }
        } finally {
            inputStream.close();
        }
    } catch (IOException e) {
        throw new IOException("Could not open " + assetname, e);
    }
    return cacheFile;
}

From source file:net.es.nsi.topology.translator.http.Decoder.java

public static Document decode(String source) throws IOException {
    byte[] encoded = Base64.getDecoder().decode(source);
    byte[] xml = decompress(encoded);

    try {//from  ww  w.j  a  va  2  s.  c  om
        Document doc = DomParser.xml2Dom(new ByteArrayInputStream(xml));
        return doc;
    } catch (ParserConfigurationException | SAXException ex) {
        log.error("decode: failed to parse document", ex);
        throw new IOException(ex.getMessage(), ex.getCause());
    }
}

From source file:com.carmatech.maven.utils.MergeUtils.java

public static PropertiesConfiguration toProperties(final File propertiesFile) throws IOException {
    try {/*  w ww.  j a  va2s. c  o  m*/
        return new PropertiesConfiguration(propertiesFile);
    } catch (ConfigurationException e) {
        throw new IOException("Unable to load properties file " + propertiesFile, e);
    }
}

From source file:Main.java

/**
 * @param is//from w w  w. j  a  v  a  2s .co m
 * @return
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
public static Document parseInputStream(InputStream is) throws IOException {
    try {
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(false);
        domFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        return builder.parse(is);
    } catch (Exception e) {
        throw new IOException("Error parsing XML Stream", e);
    }
}