예제 #1
0
 /**
  * Register an implementation.
  *
  * @param s The source to be registered, may not be <code>null</code>
  */
 public void addSource(DOMImplementationSource s)
 {
     if (s == null)
     {
         throw new java.lang.NullPointerException();
     }
     if (!sources.contains(s))
     {
         sources.addElement(s);
     }
 }
예제 #2
0
        /*
         * Writes entry information to the underlying stream. Data associated with
         * the entry can then be written using {@code write()}. After data is
         * written {@code closeEntry()} must be called to complete the writing of
         * the entry to the underlying stream.
         *
         * @param ze
         *            the {@code ZipEntry} to store.
         * @throws IOException
         *             If an error occurs storing the entry.
         * @see #write
         */
        public void putNextEntry(ZipEntry ze)  //throws java.io.IOException {
        {
            if (currentEntry != null)
            {
                closeEntry();
            }
            if (ze.getMethod() == STORED ||
                (compressMethod == STORED && ze.getMethod() == -1))
            {
                if (ze.crc == -1)
                {
                    /* [MSG "archive.20", "Crc mismatch"] */
                    throw new ZipException("Crc mismatch"); //$NON-NLS-1$
                }
                if (ze.size == -1 && ze.compressedSize == -1)
                {
                    /* [MSG "archive.21", "Size mismatch"] */
                    throw new ZipException("Size mismatch"); //$NON-NLS-1$
                }
                if (ze.size != ze.compressedSize && ze.compressedSize != -1 &&
                    ze.size != -1)
                {
                    /* [MSG "archive.21", "Size mismatch"] */
                    throw new ZipException("Size mismatch"); //$NON-NLS-1$
                }
            }
            /* [MSG "archive.1E", "Stream is closed"] */
            if (cDir == null)
            {
                throw new java.io.IOException("Stream is closed"); //$NON-NLS-1$
            }
            if (entries.contains(ze.name))
            {
                /* [MSG "archive.29", "Entry already exists: {0}"] */
                throw new ZipException("Entry already exists: " + ze.name); //$NON-NLS-1$
            }
            nameLength = utf8Count(ze.name);
            if (nameLength > 0xffff)
            {
                /* [MSG "archive.2A", "Name too long: {0}"] */
                throw new java.lang.IllegalArgumentException("Name too long: " + ze.name); //$NON-NLS-1$
            }

            def.setLevel(compressLevel);
            currentEntry = ze;
            entries.add(currentEntry.name);
            if (currentEntry.getMethod() == -1)
            {
                currentEntry.setMethod(compressMethod);
            }
            writeLong(outJ, ZipFile.LOCSIG);               // Entry header
            writeShort(outJ, ZIPLocalHeaderVersionNeeded); // Extraction version
            writeShort(outJ, currentEntry.getMethod() == STORED ? 0
                    : ZIPDataDescriptorFlag);
            writeShort(outJ, currentEntry.getMethod());
            if (currentEntry.getTime() == -1)
            {
                currentEntry.setTime(java.lang.SystemJ.currentTimeMillis());
            }
            writeShort(outJ, currentEntry.time);
            writeShort(outJ, currentEntry.modDate);

            if (currentEntry.getMethod() == STORED)
            {
                if (currentEntry.size == -1)
                {
                    currentEntry.size = currentEntry.compressedSize;
                }
                else if (currentEntry.compressedSize == -1)
                {
                    currentEntry.compressedSize = currentEntry.size;
                }
                writeLong(outJ, currentEntry.crc);
                writeLong(outJ, currentEntry.size);
                writeLong(outJ, currentEntry.size);
            }
            else
            {
                writeLong(outJ, 0);
                writeLong(outJ, 0);
                writeLong(outJ, 0);
            }
            writeShort(outJ, nameLength);
            if (currentEntry.extra != null)
            {
                writeShort(outJ, currentEntry.extra.Length);
            }
            else
            {
                writeShort(outJ, 0);
            }
            nameBytes = toUTF8Bytes(currentEntry.name, nameLength);
            outJ.write(nameBytes);
            if (currentEntry.extra != null)
            {
                outJ.write(currentEntry.extra);
            }
        }