Search in sources :

Example 11 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureMediaStore method copyToExternal.

public static void copyToExternal(String sourcePath, java.io.File targetPath) throws IOException {
    // copy
    FileInputStream fis = new FileInputStream(new File(sourcePath));
    java.io.FileOutputStream fos = new java.io.FileOutputStream(targetPath, false);
    IOUtils.copyLarge(fis, fos);
    fos.close();
    fis.close();
}
Also used : FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File) FileInputStream(info.guardianproject.iocipher.FileInputStream)

Example 12 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureMediaStore method createUniqueFilename.

private static String createUniqueFilename(String filename) {
    if (!exists(filename)) {
        return filename;
    }
    int count = 1;
    String uniqueName;
    File file;
    do {
        uniqueName = formatUnique(filename, count++);
        file = new File(uniqueName);
    } while (file.exists());
    return uniqueName;
}
Also used : File(info.guardianproject.iocipher.File)

Example 13 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureMediaStore method delete.

private static void delete(String parentName) throws IOException {
    File parent = new File(parentName);
    // if a file or an empty directory - delete it
    if (!parent.isDirectory() || parent.list().length == 0) {
        // Log.e(TAG, "delete:" + parent );
        if (!parent.delete()) {
            throw new IOException("Error deleting " + parent);
        }
        return;
    }
    // directory - recurse
    String[] list = parent.list();
    for (int i = 0; i < list.length; i++) {
        String childName = parentName + "/" + list[i];
        delete(childName);
    }
    delete(parentName);
}
Also used : IOException(java.io.IOException) File(info.guardianproject.iocipher.File)

Example 14 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class SecureMediaStore method deleteSession.

public static void deleteSession(String sessionId) throws IOException {
    String dirName = "/" + sessionId;
    File file = new File(dirName);
    // if the session doesnt have any ul/dl files - bail
    if (!file.exists()) {
        return;
    }
    // delete recursive
    delete(dirName);
}
Also used : File(info.guardianproject.iocipher.File)

Example 15 with File

use of info.guardianproject.iocipher.File in project Zom-Android by zom.

the class AudioWife method initPlayer.

/**
 **
 * Initialize and prepare the audio player
 ***
 */
private void initPlayer(Context ctx, final Uri mediaUri, String mimeType) throws IOException {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    if (mediaUri.getScheme() != null) {
        if (mediaUri.getScheme().equals("vfs")) {
            final info.guardianproject.iocipher.File fileMediaEncrypted = new info.guardianproject.iocipher.File(mediaUri.getPath());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mMediaPlayer.setDataSource(new MediaDataSource() {

                    final info.guardianproject.iocipher.RandomAccessFile fis = new info.guardianproject.iocipher.RandomAccessFile(fileMediaEncrypted, "r");

                    @Override
                    public int readAt(long position, byte[] buffer, int offset, int size) throws IOException {
                        if (position > getSize())
                            return -1;
                        fis.seek(position);
                        byte[] outBuffer = new byte[size];
                        int readSize = fis.read(outBuffer, 0, size);
                        System.arraycopy(outBuffer, 0, buffer, offset, size);
                        return readSize;
                    }

                    @Override
                    public long getSize() throws IOException {
                        return fis.length();
                    }

                    @Override
                    public void close() throws IOException {
                        if (fis != null)
                            fis.close();
                    }
                });
            } else {
                HttpMediaStreamer streamer = new HttpMediaStreamer(fileMediaEncrypted, mimeType);
                Uri uri = streamer.getUri();
                mMediaPlayer.setDataSource(ctx, uri);
            }
        } else if (mediaUri.getScheme().equals("content")) {
            mMediaPlayer.setDataSource(ctx, mediaUri);
        } else if (mediaUri.getScheme().equals("file")) {
            mMediaPlayer.setDataSource(ctx, mediaUri);
        }
    } else {
        mMediaPlayer.setDataSource(mediaUri.getPath());
    }
    try {
        mMediaPlayer.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    mMediaPlayer.setOnCompletionListener(mOnCompletion);
}
Also used : File(info.guardianproject.iocipher.File) HttpMediaStreamer(org.awesomeapp.messenger.util.HttpMediaStreamer) IOException(java.io.IOException) Uri(android.net.Uri) IOException(java.io.IOException) MediaDataSource(android.media.MediaDataSource) File(info.guardianproject.iocipher.File) MediaPlayer(android.media.MediaPlayer)

Aggregations

File (info.guardianproject.iocipher.File)32 IOException (java.io.IOException)14 FileOutputStream (info.guardianproject.iocipher.FileOutputStream)6 FileInputStream (info.guardianproject.iocipher.FileInputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 Bitmap (android.graphics.Bitmap)4 Uri (android.net.Uri)4 HashMap (java.util.HashMap)4 RemoteException (android.os.RemoteException)3 RandomAccessFile (info.guardianproject.iocipher.RandomAccessFile)3 BitmapFactory (android.graphics.BitmapFactory)2 MediaDataSource (android.media.MediaDataSource)2 MediaPlayer (android.media.MediaPlayer)2 HttpRequest (cz.msebera.android.httpclient.HttpRequest)2 BasicHttpRequest (cz.msebera.android.httpclient.message.BasicHttpRequest)2 InputStream (java.io.InputStream)2 HttpMediaStreamer (org.awesomeapp.messenger.util.HttpMediaStreamer)2 OmemoFingerprint (org.jivesoftware.smackx.omemo.OmemoFingerprint)2 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)2 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)2