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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations