@Override public void offerData(String id,Address us,Address them,String localUri,Map<String,String> headers) throws IOException {
  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 {
    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);
  }
  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);
}

@ Override public void offerData ( String id , Address us , Address them , String localUri , Map < String , String > headers ) throws IOException { 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 { 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 ) ; } 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 ) ; }
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 ; } }
