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

private static Element findElement(Element root, String tag) throws IOException {
    NodeList elements = root.getElementsByTagName(tag);

    if (elements.getLength() == 0) {
        throw new IOException("Tag " + tag + " was expected and not found.");
    } else if (elements.getLength() != 1) {
        throw new IOException("Tag " + tag + " cannot have multiple definitions.");
    }//from w  ww  .j a v a 2s . c  o  m

    return (Element) elements.item(0);
}

From source file:Main.java

/**
 * @throws IOException if {@code f} does not exists.
 *///  w  w  w .  j  a va  2  s  . com
public static void validateExists(File f) throws IOException {
    if (!f.exists()) {
        throw new IOException(
                String.format("Error: %s doesn't exist, please choose another file\n", f.toString()));
    }
}

From source file:Main.java

static String fileUrlToFilePath(String mediaPath) throws IOException {
    try {//from   w w w .  ja  v  a  2  s  .  co  m
        return new File(new URL(mediaPath).toURI()).getAbsolutePath();
    } catch (IllegalArgumentException e) {
        throw new IOException("Unable to determine file path of file url " + mediaPath);
    } catch (Exception e) {
        throw new IOException("Unable to determine file path of file url " + mediaPath);
    }
}

From source file:Main.java

public static File createTempDir() throws IOException {
    File temp;/*from  w  w  w.j  ava  2  s.  com*/

    temp = File.createTempFile("encfs-java-tmp", Long.toString(System.nanoTime()));
    if (!temp.delete()) {
        throw new IOException("Could not delete temporary file " + temp.getAbsolutePath());
    }

    if (!temp.mkdir()) {
        throw new IOException("Could not create temporary directory");
    }

    return temp;
}

From source file:Main.java

public static byte[] readFile(File file) throws IOException {
    if (!file.exists()) {
        throw new IOException("not crete file=" + file.getAbsolutePath());
    }//from  w w w.  j av a  2s .co  m
    FileInputStream fileInputStream = null;
    ByteArrayOutputStream byteArrayOutputStream = null;
    try {
        fileInputStream = new FileInputStream(file);
        byteArrayOutputStream = new ByteArrayOutputStream(64);
        int length = 0;
        byte[] buffer = new byte[1024];
        while ((length = fileInputStream.read(buffer)) != -1) {
            byteArrayOutputStream.write(buffer, 0, length);
        }
        return byteArrayOutputStream.toByteArray();
    } finally {
        if (fileInputStream != null) {
            fileInputStream.close();
        }
        if (byteArrayOutputStream != null) {
            byteArrayOutputStream.close();
        }
    }
}

From source file:Main.java

public static final Element getElementByTagName(Element parent, String name) throws IOException {
    final NodeList list = parent.getElementsByTagName(name);
    if (list.getLength() == 1) {
        return (Element) list.item(0);
    } else {//from   w  w  w.  ja v a2s .c o m
        throw new IOException(String.format("Expected one child element named \"%s\"", name));
    }
}

From source file:Utils.java

private static void deleteContentsRecursive(File file) throws IOException {
    File[] files = file.listFiles();
    for (File child : files) {
        if (child.isDirectory())
            deleteContentsRecursive(child);
        if (!child.delete())
            throw new IOException("Unable to delete " + child.getPath());
    }/*from w w  w.ja v  a2 s .c o  m*/
}

From source file:Main.java

public static void touch(File file) throws IOException {
    if (!file.exists()) {
        File parent = file.getParentFile();
        if (parent != null)
            if (!parent.exists())
                if (!parent.mkdirs())
                    throw new IOException("Cannot create parent directories for file: " + file);
        file.createNewFile();//  w  ww  . j av  a  2  s.com
    }
}

From source file:Main.java

public static Bitmap decodeStream(InputStream is) throws IOException {
    Bitmap b = BitmapFactory.decodeStream(is);
    if (b == null) {
        throw new IOException("Failed to create bitmap, decodeStream() returned null");
    }//from   w w w .j a v  a2  s  .co m

    return b;
}

From source file:Main.java

public static final Element getChildElement(Element parent) throws IOException {
    final List<Element> childElements = getChildElements(parent);
    if (childElements.size() == 1) {
        return childElements.get(0);
    } else {/*from ww w .j  av  a2  s  . c o  m*/
        throw new IOException("Expected one child element");
    }
}