コード例 #1
0
ファイル: BackupZip.java プロジェクト: 4Fwolf/mt6572_x201
  public void addFileByFileName(String srcFileName, String desFileName) throws IOException {
    MyLogger.logD(
        "BACKUP", "addFileByFileName:" + "srcFile:" + srcFileName + ",desFile:" + desFileName);

    ZipEntry zipEntry = new ZipEntry(desFileName);
    File file = new File(srcFileName);
    FileInputStream inputStream = new FileInputStream(file);
    mOutZip.putNextEntry(zipEntry);

    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = inputStream.read(buffer)) != -1) {
      mOutZip.write(buffer, 0, len);
    }

    inputStream.close();
  }
コード例 #2
0
ファイル: BackupZip.java プロジェクト: 4Fwolf/mt6572_x201
  public static List<String> GetFileList(
      String zipFileString, boolean bContainFolder, boolean bContainFile, String tmpString)
      throws IOException {

    MyLogger.logI(CLASS_TAG, "GetFileList");

    List<String> fileList = new ArrayList<String>();
    ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));
    ZipEntry zipEntry;
    String szName = "";

    while ((zipEntry = inZip.getNextEntry()) != null) {
      szName = zipEntry.getName();
      MyLogger.logD(CLASS_TAG, szName);

      if (zipEntry.isDirectory()) {

        // get the folder name of the widget
        szName = szName.substring(0, szName.length() - 1);
        if (bContainFolder) {
          if (tmpString == null) {
            fileList.add(szName);
          } else if (szName.matches(tmpString)) {
            fileList.add(szName);
          }
        }

      } else {
        if (bContainFile) {
          if (tmpString == null) {
            fileList.add(szName);
          } else if (szName.matches(tmpString)) {
            fileList.add(szName);
          }
        }
      }
    }

    inZip.close();
    if (fileList.size() > 0) {
      Collections.sort(fileList);
      Collections.reverse(fileList);
    }
    return fileList;
  }