Search in sources :

Example 6 with FileInputStream

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

the class IOCipherOmemoStore method readInt.

private int readInt(File target) throws IOException {
    if (target == null) {
        throw new IOException("Could not read integer from null-path.");
    }
    IOException io = null;
    int i = -1;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(target));
        i = in.readInt();
    } catch (IOException e) {
        io = e;
    } finally {
        if (in != null) {
            in.close();
        }
    }
    if (io != null) {
        throw io;
    }
    return i;
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) OmemoFingerprint(org.jivesoftware.smackx.omemo.OmemoFingerprint) FileInputStream(info.guardianproject.iocipher.FileInputStream)

Example 7 with FileInputStream

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

the class IOCipherOmemoStore method readBytes.

private byte[] readBytes(File target) throws IOException {
    if (target == null) {
        throw new IOException("Could not read bytes from null-path.");
    }
    byte[] b = null;
    IOException io = null;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(target));
        b = new byte[in.available()];
        in.read(b);
    } catch (IOException e) {
        io = e;
    } finally {
        if (in != null) {
            in.close();
        }
    }
    if (io != null) {
        throw io;
    }
    return b;
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(info.guardianproject.iocipher.FileInputStream)

Example 8 with FileInputStream

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

the class IOCipherOmemoStore method readLong.

private long readLong(File target) throws IOException {
    if (target == null) {
        throw new IOException("Could not read long from null-path.");
    }
    IOException io = null;
    long l = -1;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(target));
        l = in.readLong();
    } catch (IOException e) {
        io = e;
    } finally {
        if (in != null) {
            in.close();
        }
    }
    if (io != null) {
        throw io;
    }
    return l;
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(info.guardianproject.iocipher.FileInputStream)

Example 9 with FileInputStream

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

the class IOCipherOmemoStore method readIntegers.

private Set<Integer> readIntegers(File target) throws IOException {
    if (target == null) {
        throw new IOException("Could not write integers to null-path.");
    }
    HashSet<Integer> integers = new HashSet<>();
    IOException io = null;
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(target));
        try {
            while (true) {
                integers.add(in.readInt());
            }
        } catch (EOFException e) {
        // Reached end of the list.
        }
    } catch (IOException e) {
        io = e;
    } finally {
        if (in != null) {
            in.close();
        }
    }
    if (io != null) {
        throw io;
    }
    return integers;
}
Also used : EOFException(java.io.EOFException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(info.guardianproject.iocipher.FileInputStream) HashSet(java.util.HashSet)

Example 10 with FileInputStream

use of info.guardianproject.iocipher.FileInputStream 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

FileInputStream (info.guardianproject.iocipher.FileInputStream)10 IOException (java.io.IOException)9 File (info.guardianproject.iocipher.File)5 DataInputStream (java.io.DataInputStream)4 Bitmap (android.graphics.Bitmap)2 BitmapFactory (android.graphics.BitmapFactory)2 HttpRequest (cz.msebera.android.httpclient.HttpRequest)2 BasicHttpRequest (cz.msebera.android.httpclient.message.BasicHttpRequest)2 RandomAccessFile (info.guardianproject.iocipher.RandomAccessFile)2 FileNotFoundException (java.io.FileNotFoundException)2 Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1 Header (cz.msebera.android.httpclient.Header)1 HttpException (cz.msebera.android.httpclient.HttpException)1 MethodNotSupportedException (cz.msebera.android.httpclient.MethodNotSupportedException)1 AbstractSessionInputBuffer (cz.msebera.android.httpclient.impl.io.AbstractSessionInputBuffer)1 HttpRequestParser (cz.msebera.android.httpclient.impl.io.HttpRequestParser)1 SessionInputBuffer (cz.msebera.android.httpclient.io.SessionInputBuffer)1 FileOutputStream (info.guardianproject.iocipher.FileOutputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1