Package com.everbox4j.bean

Examples of com.everbox4j.bean.EverBoxObject


        JSONObject obj = new JSONObject();
        obj.put("path", ebo.getPath());
        StringBuilder sb = new StringBuilder();
        int rc = FS.get(obj, sb);
        assertEquals(200, rc);
        EverBoxObject me = Json.fromJson(EverBoxObject.class, sb.toString());
        me = list(me);
        ebo.setEntries(me.getEntries());
      }
    }
    return parent;
  }
View Full Code Here


    return parent;
  }
 
  @Test
  public void test_upload() throws Throwable {
    EverBoxObject ebo = new EverBoxObject();
    ebo.setPath("/home/ta.rtf");
    EverboxAPI.upload(ebo);
//    File f = new File("everbox/ta.rtf");
//    byte[] sha = Digest.SHA1(new FileInputStream(f), (int)f.length());
////    System.out.println(new String(sha));
//    String key = Base64.encodeBase64String(sha).replace('/', '_');
View Full Code Here

      }
      log.debug("Server return : " + thumbnailInfo);
      log.debug("获取下载URL "+ thumbnailInfo.getString("dataurl"));
     
      //额外检查,以免重复下载了文件
      EverBoxObject localEbo = new EverBoxObject();
      localEbo.setPath(ebo.getPath());
      loadLocalFileInfo(localEbo);
      if(localEbo.getType() == 1 && localEbo.getFileSize() == ebo.getFileSize()) {
        log.info("虽然服务器上的文件的最后修改时间比本地文件新,但大小与一致,需要额外检查 "+ ebo.getPath());
        if(thumbnailInfo.has("fileSize")) {
          long fileSize = thumbnailInfo.getLong("fileSize");
          if(fileSize == localEbo.getFileSize()) {
            String[] keys = makeFileKeys(ebo);
            EverboxLocalFileInfo info = EverboxContext.dao.fetch(EverboxLocalFileInfo.class, ebo.getPath());
            if(info != null && info.getRemoteRev() != null && info.getSha1s() != null) {
              if(info.getRemoteRev().equals(thumbnailInfo.getString("ver")) && info.getSha1s().equals(Json.toJson(keys))) {
                log.info("本地文件与服务器文件一致,无需下载");
View Full Code Here

 
  public static void compareEverboxObject(EverBoxObject oldOne, EverBoxObject newOne,List<EverboxModify> mList){
    List<EverBoxObject> oldList = new ArrayList<EverBoxObject>(oldOne.getEntries());
    List<EverBoxObject> newList = new ArrayList<EverBoxObject>(newOne.getEntries());
    oldIT: for (Iterator<EverBoxObject> oldIt = oldList.iterator(); oldIt.hasNext();) {
      EverBoxObject oldEntry = oldIt.next();
      for (Iterator<EverBoxObject> newIt = newList.iterator(); newIt.hasNext();) {
        EverBoxObject newEntry = newIt.next();
        if(newEntry.getPath().equals(oldEntry.getPath())) {
          newIt.remove();
          if(newEntry.getType() != oldEntry.getType()) {
            log.infof("警告!! 文件类型(文件夹<-->文件)改变!! -- (%d-->%d) %s",
                oldEntry.getType() , newEntry.getType(), oldEntry.getPath());
          }
          if(newEntry.getType() == EverboxConfig.FILE && oldEntry.getType() == EverboxConfig.FILE) {
            if(oldEntry.getEditTime() > newEntry.getEditTime()) {
              mList.add(new EverboxModify(oldEntry, EverboxModify.OLDER, false));
              log.info("B的文件较旧-- " + oldEntry.getPath());
            } else if(oldEntry.getEditTime() < newEntry.getEditTime()) {
              mList.add(new EverboxModify(newEntry, EverboxModify.NEWER, false));
              log.info("B的文件较新 -- " + oldEntry.getPath());
            }
          }else if(newEntry.getType() == EverboxConfig.DIR && oldEntry.getType() == EverboxConfig.DIR) {
            compareEverboxObject(oldEntry, newEntry,mList);
          }
          continue oldIT;
        }
      }
      //能到这里? 那肯定是被删除了
      oldIt.remove();
      List<EverBoxObject> list = new ArrayList<EverBoxObject>();
      oldEntry.asList(list);
      for (EverBoxObject ebo : list) {
        log.info("B比A少了一个文件 -- " + ebo.getPath());
        mList.add(new EverboxModify(ebo, EverboxModify.MISS, false));
      }
    }
    //仍然有新的Entry? 那就是新增咯
    if(newList.size() > 0) {
      for (EverBoxObject newEntry : newList) {
        List<EverBoxObject> list = new ArrayList<EverBoxObject>();
        newEntry.asList(list);
        for (EverBoxObject ebo : list) {
          mList.add(new EverboxModify(ebo, EverboxModify.ADD, false));
          log.info("B比A多了一个文件 -- " + ebo.getPath());
        }
      }
View Full Code Here

    File[] files = parentFile.listFiles();
    if(files == null)
      files = new File[0];
    List<EverBoxObject> entries = new ArrayList<EverBoxObject>(files.length);
    for (File file : files) {
      EverBoxObject ebo = new EverBoxObject();
      ebo.setPath(parent.getPath() +"/" + file.getName());
      loadLocalFileInfo(ebo);
      entries.add(ebo);
      if(parent.getType() == EverboxConfig.DIR)
        listLocal(ebo);
    }
View Full Code Here

      //重新加载一下配置
      EverboxConfig.reloadConfig();
      //加载前一次运行后,本地文件情况
      context.preLocalHome = EverboxConfig.loadLocalHomeDataFromDisk();
      //刷新当前的本地文件情况
      EverBoxObject eboA = new EverBoxObject();
      eboA.setPath("/home");
      context.nowLocalHome = listLocal(eboA);
      //得出本地Home变化差异表A
      log.info("得出本地Home变化差异表");
      context.localModifyList.clear();
      EverboxAPI.compareEverboxObject(EverboxAPI.cloneEverboxObject(context.preLocalHome),
View Full Code Here

      mergeEverBoxObject(oldOne, newOne);
    //文件已经改变,遍历其Entries
    List<EverBoxObject> oldEntries = oldOne.getEntries();
    List<EverBoxObject> newEntries = newOne.getEntries();
    oldIT : for (Iterator<EverBoxObject> oldIt = oldEntries.iterator(); oldIt.hasNext();) {
      EverBoxObject oldEntry = oldIt.next();
      for (Iterator<EverBoxObject> newIt = newEntries.iterator(); newIt.hasNext();) {
        EverBoxObject newEntry = newIt.next();
        if(oldEntry.getPath().equals(newEntry.getPath())) {
          newIt.remove();
//          System.out.println("找到一个已存在文件 " + oldEntry.getPath());
          boolean flag = equals(oldEntry, newEntry);
          if(flag) {
//            System.out.println("没有做任何修改 "+oldEntry.getPath());
            continue oldIT;
          }
          if(oldEntry.getType() == EverboxConfig.FILE && newEntry.getType() == EverboxConfig.FILE) {
            mergeEverBoxObject(oldEntry, newEntry);
            remoteModifyList.add(new EverboxModify(newEntry, EverboxModify.NEWER, true));
            log.info("远程(服务器端)更新了一个文件 -- " + oldEntry.getPath());
            continue oldIT;//TODO add into remote modify list
          } else if(oldEntry.getType() != newEntry.getType()) {
//            remoteModifyList.add(new EverboxModify(newEntry, EverboxModify.UPDATE, true));
//            mergeEverBoxObject(oldEntry, newEntry);
            log.info("远程(服务器端) !警告!! 文件类型(文件夹<-->文件)改变!! -- " + oldEntry.getPath());
//            continue oldIT;//TODO add into remote modify list
          }
          JSONObject obj = new JSONObject();
          obj.put("path", newEntry.getPath());
          StringBuilder sb = new StringBuilder();
          FS.get(obj, sb);
          newEntry = Json.fromJson(EverBoxObject.class, sb.toString());
          reflashRemote(oldEntry, newEntry);
          continue oldIT;
        }
      }
      //No match in newOne? Object shall be deleted!!
      oldIt.remove();//TODO add into remote modify list
      remoteModifyList.add(new EverboxModify(oldEntry, EverboxModify.MISS, true));
      log.info("远程(服务器端)删除了一个文件 -- " + oldEntry.getPath());
    }
    //仍然有新的Entry? 那就是远程新增咯
    if(newEntries.size() > 0) {
      for (EverBoxObject newEntry : newEntries) {
        System.out.println(newEntry.getPath());
        oldEntries.add(listRemote(newEntry));//TODO add into remote modify list
        List<EverBoxObject> list = new ArrayList<EverBoxObject>();
        newEntry.asList(list);
        for (EverBoxObject ebo : list) {
          remoteModifyList.add(new EverboxModify(ebo, EverboxModify.ADD, true));
          log.info("远程(服务器端)新增了一个文件 -- " + ebo.getPath());
        }
      }
View Full Code Here

      return parent;
    log.info("遍历全部子节点 "+parent.getPath());
    parent = EverboxAPI.get(parent.getPath());
    for (EverBoxObject ebo : parent.getEntries()) {
      if(ebo.getType() == EverboxConfig.DIR) {
        EverBoxObject me = EverboxAPI.get(ebo.getPath());
        me = listRemote(me);
        ebo.setEntries(me.getEntries());
      }
    }
    return parent;
  }
View Full Code Here

    File[] files = parentFile.listFiles();
    if(files == null)
      files = new File[0];
    List<EverBoxObject> entries = new ArrayList<EverBoxObject>(files.length);
    for (File file : files) {
      EverBoxObject ebo = new EverBoxObject();
      ebo.setPath(parent.getPath() +"/" + file.getName());
      loadLocalFileInfo(ebo);
      entries.add(ebo);
      if(parent.getType() == EverboxConfig.DIR)
        listLocal(ebo);
    }
View Full Code Here

//    System.out.println(Json.toJson(context.localOpts));
//    System.out.println("-------------------------------------------------------");
//    System.exit(1);
    for (Iterator<EverboxOPT> it = context.remoteOpts.iterator(); it.hasNext();) {
      EverboxOPT opt = it.next();
      EverBoxObject ebo = opt.getEverBoxObject();
      if(opt.getMode() == EverboxOPT.ADD) {
        if(ebo.getType() == EverboxConfig.FILE) {
          EverboxAPI.upload(ebo);
        } else if(ebo.getType() == EverboxConfig.DIR) {
          EverboxAPI.mkidrRemote(ebo);
        }
      } else if(opt.getMode() == EverboxOPT.DELETE) {
        EverboxAPI.deleteRemote(ebo);
      }
    }
    for (Iterator<EverboxOPT> it = context.localOpts.iterator(); it.hasNext();) {
      EverboxOPT opt = it.next();
      EverBoxObject ebo = opt.getEverBoxObject();
      if(opt.getMode() == EverboxOPT.ADD) {
        if(ebo.getType() == EverboxConfig.FILE) {
          EverboxAPI.download(ebo);
        } else if(ebo.getType() == EverboxConfig.DIR) {
          Files.makeDir(new File(EverboxConfig.getRealPath(ebo)));
        }
      } else if(opt.getMode() == EverboxOPT.DELETE) {
        Files.deleteDir(new File(EverboxConfig.getRealPath(ebo)));
      }
View Full Code Here

TOP

Related Classes of com.everbox4j.bean.EverBoxObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.