/**
  * Return PDF instance wrapping file referenced by Intent. Currently reads all bytes to memory, in
  * future local files should be passed to native code and remote ones should be downloaded to
  * local tmp dir.
  *
  * @return PDF instance
  */
 private PDF getPDF() {
   final Intent intent = getIntent();
   Uri uri = intent.getData();
   filePath = uri.getPath();
   if (uri.getScheme().equals("file")) {
     if (history) {
       Recent recent = new Recent(this);
       recent.add(0, filePath);
       recent.commit();
     }
     return new PDF(new File(filePath), this.box);
   } else if (uri.getScheme().equals("content")) {
     ContentResolver cr = this.getContentResolver();
     FileDescriptor fileDescriptor;
     try {
       fileDescriptor = cr.openFileDescriptor(uri, "r").getFileDescriptor();
     } catch (FileNotFoundException e) {
       throw new RuntimeException(e); // TODO: handle errors
     }
     return new PDF(fileDescriptor, this.box);
   } else {
     throw new RuntimeException("don't know how to get filename from " + uri);
   }
 }
Пример #2
0
 private final Term getTerm() {
   final String id = recent.top();
   if (null == id) throw new EvalException("no such identifier");
   return new Term("id", id);
 }