Пример #1
0
  /**
   * Creates a new header for a file/directory entry.
   *
   * @param name File name
   * @param size File size in bytes
   * @param modTime Last modification time in numeric Unix time format
   * @param dir Is directory
   * @return
   */
  public static TarHeader createHeader(String entryName, long size, long modTime, boolean dir) {
    String name = entryName;
    name = TarUtils.trim(name.replace(File.separatorChar, '/'), '/');

    TarHeader header = new TarHeader();
    header.linkName = new StringBuffer("");

    if (name.length() > 100) {
      header.namePrefix = new StringBuffer(name.substring(0, name.lastIndexOf('/')));
      header.name = new StringBuffer(name.substring(name.lastIndexOf('/') + 1));
    } else {
      header.name = new StringBuffer(name);
    }

    if (dir) {
      header.mode = 040755;
      header.linkFlag = TarHeader.LF_DIR;
      if (header.name.charAt(header.name.length() - 1) != '/') {
        header.name.append("/");
      }
      header.size = 0;
    } else {
      header.mode = 0100644;
      header.linkFlag = TarHeader.LF_NORMAL;
      header.size = size;
    }

    header.modTime = modTime;
    header.checkSum = 0;
    header.devMajor = 0;
    header.devMinor = 0;

    return header;
  }