Search in sources :

Example 31 with File

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

the class IOCipherOmemoStore method storeCachedDeviceList.

@Override
public void storeCachedDeviceList(OmemoManager omemoManager, BareJid contact, CachedDeviceList deviceList) {
    if (contact == null) {
        return;
    }
    File activeDevices = hierarchy.getContactsActiveDevicesPath(omemoManager, contact);
    try {
        writeIntegers(activeDevices, deviceList.getActiveDevices());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write active devices of deviceList of " + contact + ": " + e.getMessage());
    }
    File inactiveDevices = hierarchy.getContactsInactiveDevicesPath(omemoManager, contact);
    try {
        writeIntegers(inactiveDevices, deviceList.getInactiveDevices());
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Could not write inactive devices of deviceList of " + contact + ": " + e.getMessage());
    }
}
Also used : IOException(java.io.IOException) File(info.guardianproject.iocipher.File)

Example 32 with File

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

the class OtrDataHandler method offerData.

/**
 *    private File writeDataToStorage (String url, byte[] data)
 *    {
 *        debug( "writeDataToStorage:" + url + " " + data.length);
 *
 *        String[] path = url.split("/");
 *        String sanitizedPath = SystemServices.sanitize(path[path.length - 1]);
 *
 *        File fileDownloadsDir = new File(Environment.DIRECTORY_DOWNLOADS);
 *        fileDownloadsDir.mkdirs();
 *
 *        info.guardianproject.iocipher.File file = new info.guardianproject.iocipher.File(fileDownloadsDir, sanitizedPath);
 *        debug( "writeDataToStorage:" + file.getAbsolutePath() );
 *
 *        try {
 *            OutputStream output = (new info.guardianproject.iocipher.FileOutputStream(file));
 *            output.write(data);
 *            output.flush();
 *            output.close();
 *            return file;
 *        } catch (IOException e) {
 *            OtrDebugLogger.log("error writing file", e);
 *            return null;
 *        }
 *    }
 */
@Override
public void offerData(String id, Address us, Address them, String localUri, Map<String, String> headers) throws IOException {
    // TODO stash localUri and intended recipient
    long length = -1;
    String hash = null;
    File fileLocal = new File(localUri);
    if (fileLocal.exists()) {
        length = fileLocal.length();
        if (length > MAX_TRANSFER_LENGTH) {
            throw new IOException("Length too large: " + length);
        }
        FileInputStream is = new FileInputStream(fileLocal);
        hash = sha1sum(is);
        is.close();
    } else {
        // it is not in the encrypted store
        java.io.File fileExtern = new java.io.File(localUri);
        length = fileExtern.length();
        if (length > MAX_TRANSFER_LENGTH) {
            throw new IOException("Length too large: " + length);
        }
        java.io.FileInputStream is = new java.io.FileInputStream(fileExtern);
        hash = sha1sum(is);
        is.close();
    }
    if (headers == null)
        headers = new HashMap<>();
    headers.put("File-Name", fileLocal.getName());
    headers.put("File-Length", String.valueOf(length));
    headers.put("File-Hash-SHA1", hash);
    if (!headers.containsKey("Mime-Type")) {
        String mimeType = SystemServices.getMimeType(localUri);
        headers.put("Mime-Type", mimeType);
    }
    /**
     * 0 = {BufferedHeader@7083} "File-Name: B3C1B9F7-81EB-454A-AB5B-2B3B645453C6.m4a"
     *         1 = {BufferedHeader@7084} "Mime-Type: audio/x-m4a"
     *         2 = {BufferedHeader@7085} "File-Length: 0"
     *         3 = {BufferedHeader@7086} "Request-Id: 92C2FF9A-7C1E-42BA-A5DA-F2D445BCF1A5"
     */
    String[] paths = localUri.split("/");
    String url = URI_PREFIX_OTR_IN_BAND + SystemServices.sanitize(paths[paths.length - 1]);
    Request request = new Request("OFFER", us, them, url, headers);
    offerCache.put(url, new Offer(id, localUri, request));
    sendRequest(request);
}
Also used : HashMap(java.util.HashMap) HttpRequest(cz.msebera.android.httpclient.HttpRequest) BasicHttpRequest(cz.msebera.android.httpclient.message.BasicHttpRequest) IOException(java.io.IOException) FileInputStream(info.guardianproject.iocipher.FileInputStream) RandomAccessFile(info.guardianproject.iocipher.RandomAccessFile) File(info.guardianproject.iocipher.File)

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