Exemple #1
0
 public static void RemoveFromFavFile(String name, String url) {
   File f = Channels.workFavFile();
   try {
     String str = FileUtils.readFileToString(f);
     Channels.debug("removing from fav file " + name);
     int pos = str.indexOf(url);
     if (pos > -1) {
       FileOutputStream out = new FileOutputStream(f, false);
       pos = str.lastIndexOf(FAV_BAR, pos); // head
       out.write(str.substring(0, pos).getBytes());
       pos = str.indexOf(FAV_BAR, pos + 30); // tail
       if (pos > -1) out.write(str.substring(pos).getBytes());
       out.flush();
       out.close();
     }
   } catch (Exception e) {
   }
 }
Exemple #2
0
 public static void addToFavFile(String data, String name) {
   File f = Channels.workFavFile();
   try {
     boolean newFile = !f.exists();
     Channels.debug("adding to fav file " + name);
     FileOutputStream out = new FileOutputStream(f, true);
     if (newFile) {
       String msg = "## Auto generated favorite file,Edit with care\n\n\n";
       out.write(FAV_BAR.getBytes(), 0, FAV_BAR.length());
       out.write(msg.getBytes(), 0, msg.length());
     }
     String n = "## Name: " + name + "\r\n\n";
     out.write(FAV_BAR.getBytes(), 0, FAV_BAR.length());
     out.write(n.getBytes(), 0, n.length());
     out.write(data.getBytes(), 0, data.length());
     out.flush();
     out.close();
   } catch (Exception e) {
   }
 }