Search in sources :

Example 1 with FileWriterException

use of eu.siacs.conversations.utils.FileWriterException in project Conversations by siacs.

the class FileBackend method copyFileToPrivateStorage.

public void copyFileToPrivateStorage(File file, Uri uri) throws FileCopyException {
    Log.d(Config.LOGTAG, "copy file (" + uri.toString() + ") to private storage " + file.getAbsolutePath());
    file.getParentFile().mkdirs();
    OutputStream os = null;
    InputStream is = null;
    try {
        file.createNewFile();
        os = new FileOutputStream(file);
        is = mXmppConnectionService.getContentResolver().openInputStream(uri);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0) {
            try {
                os.write(buffer, 0, length);
            } catch (IOException e) {
                throw new FileWriterException();
            }
        }
        try {
            os.flush();
        } catch (IOException e) {
            throw new FileWriterException();
        }
    } catch (FileNotFoundException e) {
        throw new FileCopyException(R.string.error_file_not_found);
    } catch (FileWriterException e) {
        throw new FileCopyException(R.string.error_unable_to_create_temporary_file);
    } catch (IOException e) {
        e.printStackTrace();
        throw new FileCopyException(R.string.error_io_exception);
    } finally {
        close(os);
        close(is);
    }
}
Also used : FileWriterException(eu.siacs.conversations.utils.FileWriterException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DigestOutputStream(java.security.DigestOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(android.util.Base64OutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)1 Base64OutputStream (android.util.Base64OutputStream)1 FileWriterException (eu.siacs.conversations.utils.FileWriterException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 DigestOutputStream (java.security.DigestOutputStream)1