Beispiel #1
0
  public String uri2string(Uri intent_uri)
      throws FileNotFoundException, MalformedURLException, IOException {

    if (intent_uri.toString().startsWith("/"))
      return FileHelper.file2String(new File(intent_uri.toString()));

    InputStream in;

    if (intent_uri.toString().startsWith("content://"))
      in = getContentResolver().openInputStream(intent_uri);
    else in = new BufferedInputStream(new URL("" + intent_uri).openStream(), 4096);

    FileOutputStream file_writer = null;

    // if it comes from network
    if (intent_uri.toString().startsWith("http")) { // https catched also
      new File(GoPrefs.getSGFPath() + "/downloads").mkdirs();
      File f = new File(GoPrefs.getSGFPath() + "/downloads/" + intent_uri.getLastPathSegment());
      f.createNewFile();
      file_writer = new FileOutputStream(f);
    }

    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = in.read(b)) != -1; ) {
      out.append(new String(b, 0, n));
      if (file_writer != null) file_writer.write(b, 0, n);
    }
    if (file_writer != null) file_writer.close();

    return out.toString();
  }
Beispiel #2
0
  public String contentToString(String url) throws IOException {
    String res = "";

    if (url.startsWith("/")) return FileHelper.file2String(new File(url));

    return res;
  }
Beispiel #3
0
  public GoLink(File file) {

    try {
      String go_lnk = FileHelper.file2String(file);
      go_lnk = go_lnk.replace("\n", "").replace("\r", "");
      fname = go_lnk; // backup
      String[] arr_content = go_lnk.split(":#");
      fname = arr_content[0];
      fname = fname.replace("file://", "");
      move_pos = Integer.parseInt(arr_content[1]);
    } catch (Exception e) {
    }
  }
Beispiel #4
-9
 /**
  * TODO care for remote content
  *
  * @return
  */
 public String getSGFString() {
   try {
     return FileHelper.file2String(new File(fname));
   } catch (IOException e) {
     return "";
   }
 }