Search in sources :

Example 6 with FileOutputStream

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

the class SecureMediaStore method copyToVfs.

public static void copyToVfs(InputStream sourceIS, String targetPath) throws IOException {
    // create the target directories tree
    mkdirs(targetPath);
    // copy
    FileOutputStream fos = new FileOutputStream(new File(targetPath), false);
    IOUtils.copyLarge(sourceIS, fos);
    fos.close();
    sourceIS.close();
}
Also used : FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File)

Example 7 with FileOutputStream

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

the class SecureMediaStore method resizeAndImportImage.

/**
 * Resize an image to an efficient size for sending via OTRDATA, then copy
 * that resized version into vfs. All imported content is stored under
 * /SESSION_NAME/ The original full path is retained to facilitate browsing
 * The session content can be deleted when the session is over
 *
 * @param sessionId
 * @return vfs uri
 * @throws IOException
 */
public static Uri resizeAndImportImage(Context context, String sessionId, Uri uri, String mimeType) throws IOException {
    String originalImagePath = uri.getPath();
    String targetPath = "/" + sessionId + "/upload/" + UUID.randomUUID().toString() + "/image";
    boolean savePNG = false;
    if (originalImagePath.endsWith(".png") || (mimeType != null && mimeType.contains("png")) || originalImagePath.endsWith(".gif") || (mimeType != null && mimeType.contains("gif"))) {
        savePNG = true;
        targetPath += ".png";
    } else {
        targetPath += ".jpg";
    }
    // load lower-res bitmap
    Bitmap bmp = getThumbnailFile(context, uri, DEFAULT_IMAGE_WIDTH);
    File file = new File(targetPath);
    file.getParentFile().mkdirs();
    FileOutputStream out = new info.guardianproject.iocipher.FileOutputStream(file);
    if (savePNG)
        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
    else
        bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
    out.flush();
    out.close();
    bmp.recycle();
    return vfsUri(targetPath);
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(info.guardianproject.iocipher.FileOutputStream) File(info.guardianproject.iocipher.File)

Example 8 with FileOutputStream

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

the class IOCipherOmemoStore method writeIntegers.

private void writeIntegers(File target, Set<Integer> integers) throws IOException {
    if (target == null) {
        throw new IOException("Could not write integers to null-path.");
    }
    IOException io = null;
    DataOutputStream out = null;
    try {
        out = new DataOutputStream(new FileOutputStream(target));
        for (int i : integers) {
            out.writeInt(i);
        }
    } catch (IOException e) {
        io = e;
    } finally {
        if (out != null) {
            out.close();
        }
    }
    if (io != null) {
        throw io;
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(info.guardianproject.iocipher.FileOutputStream) IOException(java.io.IOException) OmemoFingerprint(org.jivesoftware.smackx.omemo.OmemoFingerprint)

Example 9 with FileOutputStream

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

the class IOCipherOmemoStore method writeBytes.

private void writeBytes(File target, byte[] bytes) throws IOException {
    if (target == null) {
        throw new IOException("Could not write bytes to null-path.");
    }
    // Create file
    FileHierarchy.createFile(target);
    IOException io = null;
    DataOutputStream out = null;
    try {
        out = new DataOutputStream(new FileOutputStream(target));
        out.write(bytes);
    } catch (IOException e) {
        io = e;
    } finally {
        if (out != null) {
            out.close();
        }
    }
    if (io != null) {
        throw io;
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) FileOutputStream(info.guardianproject.iocipher.FileOutputStream) IOException(java.io.IOException)

Aggregations

FileOutputStream (info.guardianproject.iocipher.FileOutputStream)9 File (info.guardianproject.iocipher.File)5 IOException (java.io.IOException)5 DataOutputStream (java.io.DataOutputStream)4 Bitmap (android.graphics.Bitmap)2 Intent (android.content.Intent)1 BufferedOutputStream (java.io.BufferedOutputStream)1 InputStream (java.io.InputStream)1 OmemoFingerprint (org.jivesoftware.smackx.omemo.OmemoFingerprint)1