Exemplo n.º 1
0
        protected void initOverFile(java.io.File file, String fileName)
        {
            this.file = file;

            this.linkName = "";

            if (file.isDirectory())
            {
                this.mode     = DEFAULT_DIR_MODE;
                this.linkFlag = TarConstants.LF_DIR;

                int nameLength = fileName.length();
                if (nameLength == 0 || fileName.charAt(nameLength - 1) != '/')
                {
                    this.name = fileName + "/";
                }
                else
                {
                    this.name = fileName;
                }
                this.size = 0;
            }
            else
            {
                this.mode     = DEFAULT_FILE_MODE;
                this.linkFlag = TarConstants.LF_NORMAL;
                this.size     = file.length();
                this.name     = fileName;
            }

            this.modTime  = file.lastModified() / MILLIS_PER_SECOND;
            this.devMajor = 0;
            this.devMinor = 0;
        }
Exemplo n.º 2
0
 /**
  * Create a new instance using the attributes of the given file
  */
 public ArArchiveEntry(java.io.File inputFile, String entryName)
 {
     // TODO sort out mode
     this.name         = entryName;
     this.length       = inputFile.isFile() ? inputFile.length() : 0;
     this.userId       = 0;
     this.groupId      = 0;
     this.mode         = DEFAULT_MODE;
     this.lastModified = inputFile.lastModified() / 1000;
 }
Exemplo n.º 3
0
 /**
  * Creates a new zip entry taking some information from the given
  * file and using the provided name.
  *
  * <p />The name will be adjusted to end with a forward slash "/" if
  * the file is a directory.  If the file is not a directory a
  * potential trailing forward slash will be stripped from the
  * entry name.
  */
 public ZipArchiveEntry(java.io.File inputFile, String entryName)
     : base(inputFile.isDirectory() && !entryName.EndsWith("/") ?  entryName + "/" : entryName)
 {
     setName(inputFile.isDirectory() && !entryName.EndsWith("/") ?  entryName + "/" : entryName);
     if (inputFile.isFile())
     {
         setSize(inputFile.length());
     }
     setTime(inputFile.lastModified());
     // TODO are there any other fields we can set here?
 }
Exemplo n.º 4
0
        /**
         * Creates a CPIOArchiveEntry with a specified name for a
         * specified file.
         *
         * @param format
         *            The cpio format for this entry.
         * @param inputFile
         *            The file to gather information from.
         * @param entryName
         *            The name of this entry.
         * <br/>
         * Possible format values are:
         * <p>
         * CpioConstants.FORMAT_NEW<br/>
         * CpioConstants.FORMAT_NEW_CRC<br/>
         * CpioConstants.FORMAT_OLD_BINARY<br/>
         * CpioConstants.FORMAT_OLD_ASCII<br/>
         *
         * @since Apache Commons Compress 1.1
         */
        public CpioArchiveEntry(short format, java.io.File inputFile, String entryName)
        {
            this.setFileFormat(format);
            this.name = entryName;
            this.setSize(inputFile.isFile() ? inputFile.length() : 0);
            long mode = 0;

            if (inputFile.isDirectory())
            {
                mode |= CpioConstants.C_ISDIR;
            }
            else if (inputFile.isFile())
            {
                mode |= CpioConstants.C_ISREG;
            }
            else
            {
                throw new java.lang.IllegalArgumentException("Cannot determine type of file "
                                                             + inputFile.getName());
            }
            // TODO set other fields as needed
            setMode(mode);
            setTime(inputFile.lastModified() / 1000);
        }