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