Esempio n. 1
0
 public static String readTag(KyoroFile vFile) throws IOException {
   byte[] header = new byte[128];
   long pointer = vFile.getFilePointer();
   vFile.read(header);
   int sep = 0;
   for (int i = 0; i < header.length; i++) {
     if (':' == header[i]) {
       sep = i;
       break;
     }
   }
   String sizeAsS = new String(header, 3, sep - 3);
   // android.util.Log.v("kiyo","##NNNN#"+new String(header,0,header.length));
   long size = Long.parseLong(sizeAsS);
   vFile.seek(pointer + sep + 1);
   byte[] body = new byte[(int) size];
   vFile.read(body);
   return new String(body, "utf8");
 }
Esempio n. 2
0
 public static void saveF(KyoroFile input, KyoroFile output, long begin, long end)
     throws IOException {
   byte[] buffer = new byte[1024];
   long len = 0;
   int writed = 0;
   do {
     len = end - begin - writed;
     if (len >= 1024) {
       len = 1024;
     }
     if (len <= 0) {
       break;
     }
     len = input.read(buffer, (int) len);
     if (len <= 0) {
       break;
     }
     writed += len;
     output.addChunk(buffer, 0, (int) len);
     if (writed >= end - begin) {
       break;
     }
   } while (true);
 }
Esempio n. 3
0
  //
  // call close in this method
  public static void restore(KyoroFile index, KyoroFile input, KyoroFile output)
      throws IOException {
    //		android.util.Log.v("kiyo","#restore()--1--");

    // BufferedReader isrIndex = new BufferedReader(new InputStreamReader(input));
    long inputPosition = 0;
    try {
      //			android.util.Log.v("kiyo","#restore()--2-"+input.getFilePointer()+"<"+input.length());
      //			android.util.Log.v("kiyo","#restore()--2-"+index.getFilePointer()+"<"+index.length());
      while (index.getFilePointer() < index.length()) {
        //				android.util.Log.v("kiyo","#restore()--3-"+index.getFilePointer()+"<"+index.length());
        //				String line = VirtualFile.readLine(index, "utf8");
        String line = readTag(index);

        //
        // "DEL:b=" + beginPointer + ",e=" + endPointer + ";/n";
        //
        if (line.startsWith("DEL")) {
          //					android.util.Log.v("kiyo","#restore()--4--");
          String tmp = line.substring(6, line.length());
          String[] sp = tmp.split(",e=|;");
          long begin = Long.parseLong(sp[0]);
          long end = Long.parseLong(sp[1]);
          //					android.util.Log.v("kiyo","#be="+begin+","+end);
          //
          // write begin
          //
          //	android.util.Log.v("kiyo","#1fp"+input.getFilePointer()+","+output.getFilePointer());
          saveF(input, output, 0, begin - inputPosition);
          //
          //	android.util.Log.v("kiyo","#2fp"+input.getFilePointer()+","+output.getFilePointer());
          inputPosition += begin - inputPosition;
          //
          //	android.util.Log.v("kiyo","#3fp"+input.getFilePointer()+","+output.getFilePointer());
          // jump
          input.seek(input.getFilePointer() + (end - begin));
          //
          //	android.util.Log.v("kiyo","#4fp"+input.getFilePointer()+","+output.getFilePointer());
          inputPosition += (end - begin);
          //
          //	android.util.Log.v("kiyo","#5fp"+input.getFilePointer()+","+output.getFilePointer());

        } else if (line.startsWith("ADD")) {
          //
          // "ADD:b=" + beginPointer + ",e=" + endPointer +",l="+",t="+ text + ";\n";
          //
          //					android.util.Log.v("kiyo","#restore()--5--");
          String tmp = line.substring(6, line.length());
          String[] sp = tmp.split(",e=|,t=|;|,l=");
          long begin = Long.parseLong(sp[0]);
          long end = Long.parseLong(sp[1]);
          long length = Long.parseLong(sp[2]);
          String text = tmp.substring((int) (tmp.length() - length - 2), tmp.length() - 2);
          //
          // write begin
          //
          //	android.util.Log.v("kiyo","#a1fp"+input.getFilePointer()+","+output.getFilePointer());
          saveF(input, output, 0, begin - inputPosition);
          //
          //	android.util.Log.v("kiyo","#a2fp"+input.getFilePointer()+","+output.getFilePointer());
          inputPosition += begin - inputPosition;
          //
          //	android.util.Log.v("kiyo","#a3fp"+input.getFilePointer()+","+output.getFilePointer());
          // write text
          byte[] buf = text.getBytes();
          output.addChunk(buf, 0, buf.length);
        } else {
          //					android.util.Log.v("kiyo","#restore()--6--"+line);
        }
      }
      long av = input.length() - input.getFilePointer();
      if (av >= 0) {
        saveF(input, output, 0, av);
        inputPosition += av;
      }
    } finally {

    }
  }