Example usage for java.io FileNotFoundException initCause

List of usage examples for java.io FileNotFoundException initCause

Introduction

In this page you can find the example usage for java.io FileNotFoundException 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

public static InputStream createWallpaperInputStream(Context context, String preferenceValue)
        throws FileNotFoundException {
    File file = new File(preferenceValue);
    if (file.exists()) {
        return new FileInputStream(file);
    }/*from   w  ww.j  a v  a  2 s.c om*/

    Uri uri = Uri.parse(preferenceValue);
    ContentResolver contentResolver = context.getContentResolver();
    try {
        return contentResolver.openInputStream(uri);
    } catch (SecurityException e) {
        Log.i("ThemingUtils", "unable to open background image", e);
        FileNotFoundException fileNotFoundException = new FileNotFoundException(e.getMessage());
        fileNotFoundException.initCause(e);
        throw fileNotFoundException;
    }
}

From source file:cn.edu.wyu.documentviewer.model.DocumentInfo.java

public static FileNotFoundException asFileNotFoundException(Throwable t) throws FileNotFoundException {
    if (t instanceof FileNotFoundException) {
        throw (FileNotFoundException) t;
    }//  w  ww.j a  v a 2s.  co m
    final FileNotFoundException fnfe = new FileNotFoundException(t.getMessage());
    fnfe.initCause(t);
    throw fnfe;
}

From source file:nl.nn.adapterframework.util.StreamUtil.java

public static OutputStream getOutputStream(Object target) throws IOException {
    if (target instanceof OutputStream) {
        return (OutputStream) target;
    }//from  w ww  . ja v  a2 s . c o m
    if (target instanceof String) {
        String filename = (String) target;
        if (StringUtils.isEmpty(filename)) {
            throw new IOException("target string cannot be empty but must contain a filename");
        }
        try {
            return new FileOutputStream(filename);
        } catch (FileNotFoundException e) {
            FileNotFoundException fnfe = new FileNotFoundException("cannot create file [" + filename + "]");
            fnfe.initCause(e);
            throw fnfe;
        }
    }
    return null;
}