/**
         * Put an entry on the output stream. This writes the entry's
         * header record and positions the output stream for writing
         * the contents of the entry. Once this method is called, the
         * stream is ready for calls to write() to write the entry's
         * contents. Once the contents are written, closeArchiveEntry()
         * <B>MUST</B> be called to ensure that all buffered data
         * is completely written to the output stream.
         *
         * @param archiveEntry The TarEntry to be written to the archive.
         * @throws IOException on error
         * @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry
         */
        public override void putArchiveEntry(ArchiveEntry archiveEntry) //throws IOException
        {
            if (finished)
            {
                throw new java.io.IOException("Stream has already been finished");
            }
            TarArchiveEntry entry = (TarArchiveEntry)archiveEntry;

            if (entry.getName().length() >= TarConstants.NAMELEN)
            {
                if (longFileMode == LONGFILE_GNU)
                {
                    // create a TarEntry for the LongLink, the contents
                    // of which are the entry's name
                    TarArchiveEntry longLinkEntry = new TarArchiveEntry(TarConstants.GNU_LONGLINK,
                                                                        TarConstants.LF_GNUTYPE_LONGNAME);

                    byte[] nameBytes = ArchiveUtils.toAsciiBytes(entry.getName());
                    longLinkEntry.setSize(nameBytes.Length + 1); // +1 for NUL
                    putArchiveEntry(longLinkEntry);
                    write(nameBytes);
                    write(0); // NUL terminator
                    closeArchiveEntry();
                }
                else if (longFileMode != LONGFILE_TRUNCATE)
                {
                    throw new java.lang.RuntimeException("file name '" + entry.getName()
                                                         + "' is too long ( > "
                                                         + TarConstants.NAMELEN + " bytes)");
                }
            }

            entry.writeEntryHeader(recordBuf);
            buffer.writeRecord(recordBuf);

            currBytes = 0;

            if (entry.isDirectory())
            {
                currSize = 0;
            }
            else
            {
                currSize = entry.getSize();
            }
            currName          = entry.getName();
            haveUnclosedEntry = true;
        }
示例#2
0
 /**
  * Determine if the given entry is a descendant of this entry.
  * Descendancy is determined by the name of the descendant
  * starting with this entry's name.
  *
  * @param desc Entry to be checked as a descendent of this.
  * @return True if entry is a descendant of this.
  */
 public bool isDescendent(TarArchiveEntry desc)
 {
     return(desc.getName().StartsWith(getName()));
 }
示例#3
0
 /**
  * Determine if the two entries are equal. Equality is determined
  * by the header names being equal.
  *
  * @param it Entry to be checked for equality.
  * @return True if the entries are equal.
  */
 public bool equals(TarArchiveEntry it)
 {
     return(getName().equals(it.getName()));
 }