harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r410558 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar: JarFile.java JarInputStream.java JarOutputStream.java
Date Wed, 31 May 2006 15:10:46 GMT
Author: tellison
Date: Wed May 31 08:10:45 2006
New Revision: 410558

URL: http://svn.apache.org/viewvc?rev=410558&view=rev
Log:
Source tidy-up and reformatting.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarOutputStream.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java?rev=410558&r1=410557&r2=410558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarFile.java
Wed May 31 08:10:45 2006
@@ -15,7 +15,6 @@
 
 package java.util.jar;
 
-
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FilterInputStream;
@@ -24,6 +23,7 @@
 import java.security.MessageDigest;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 
 /**
  * JarFile is used to read jar entries and their associated data from jar files.
@@ -31,334 +31,350 @@
  * @see JarInputStream
  * @see JarEntry
  */
-public class JarFile extends java.util.zip.ZipFile {
-	public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
+public class JarFile extends ZipFile {
 
-	static final String META_DIR = "META-INF/";
+    public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
 
-	private Manifest manifest;
+    static final String META_DIR = "META-INF/";
 
-	private ZipEntry manifestEntry;
+    private Manifest manifest;
 
-	JarVerifier verifier;
-
-	static final class JarFileInputStream extends FilterInputStream {
-		private long count;
-
-		private ZipEntry zipEntry;
-
-		private JarVerifier verifier;
-
-		private JarVerifier.VerifierEntry entry;
-
-		private MessageDigest digest;
-
-		JarFileInputStream(InputStream is, ZipEntry ze, JarVerifier ver) {
-			super(is);
-			if (ver != null) {
-				zipEntry = ze;
-				verifier = ver;
-				count = zipEntry.getSize();
-				entry = verifier.initEntry(ze.getName());
-				if (entry != null)
-					digest = entry.digest;
-			}
-		}
-
-		public int read() throws IOException {
-			int r = super.read();
-			if (entry != null) {
-				if (r != -1) {
-					digest.update((byte) r);
-					count--;
-				}
-				if (r == -1 || count <= 0) {
-					JarVerifier.VerifierEntry temp = entry;
-					entry = null;
-					verifier.verifySignatures(temp, zipEntry);
-				}
-			}
-			return r;
-		}
-
-		public int read(byte[] buf, int off, int nbytes) throws IOException {
-			int r = super.read(buf, off, nbytes);
-			if (entry != null) {
-				if (r != -1) {
-					int size = r;
-					if (count < size)
-						size = (int) count;
-					digest.update(buf, off, size);
-					count -= r;
-				}
-				if (r == -1 || count <= 0) {
-					JarVerifier.VerifierEntry temp = entry;
-					entry = null;
-					verifier.verifySignatures(temp, zipEntry);
-				}
-			}
-			return r;
-		}
-
-		public long skip(long nbytes) throws IOException {
-			long cnt = 0, rem = 0;
-			byte[] buf = new byte[4096];
-			while (cnt < nbytes) {
-				int x = read(buf, 0,
-						(rem = nbytes - cnt) > buf.length ? buf.length
-								: (int) rem);
-				if (x == -1)
-					return cnt;
-				cnt += x;
-			}
-			return cnt;
-		}
-	}
-
-	/**
-	 * Create a new JarFile using the contents of file.
-	 * 
-	 * @param file
-	 *            java.io.File
-	 * @exception java.io.IOException
-	 *                If the file cannot be read.
-	 */
-	public JarFile(File file) throws IOException {
-		this(file, true);
-	}
-
-	/**
-	 * Create a new JarFile using the contents of file.
-	 * 
-	 * @param file
-	 *            java.io.File
-	 * @param verify
-	 *            verify a signed jar file
-	 * @exception java.io.IOException
-	 *                If the file cannot be read.
-	 */
-	public JarFile(File file, boolean verify) throws IOException {
-		super(file);
-		if (verify)
-			verifier = new JarVerifier(file.getPath());
-		readMetaEntries();
-	}
-
-	/**
-	 * Create a new JarFile using the contents of file.
-	 * 
-	 * @param file
-	 *            java.io.File
-	 * @param verify
-	 *            verify a signed jar file
-	 * @param mode
-	 *            the mode to use, either OPEN_READ or OPEN_READ | OPEN_DELETE
-	 * @exception java.io.IOException
-	 *                If the file cannot be read.
-	 */
-	public JarFile(File file, boolean verify, int mode) throws IOException {
-		super(file, mode);
-		if (verify)
-			verifier = new JarVerifier(file.getPath());
-		readMetaEntries();
-	}
-
-	/**
-	 * Create a new JarFile from the contents of the file specified by filename.
-	 * 
-	 * @param filename
-	 *            java.lang.String
-	 * @exception java.io.IOException
-	 *                If fileName cannot be opened for reading.
-	 */
-	public JarFile(String filename) throws IOException {
-		this(filename, true);
-
-	}
-
-	/**
-	 * Create a new JarFile from the contents of the file specified by filename.
-	 * 
-	 * @param filename
-	 *            java.lang.String
-	 * @param verify
-	 *            verify a signed jar file
-	 * @exception java.io.IOException
-	 *                If fileName cannot be opened for reading.
-	 */
-	public JarFile(String filename, boolean verify) throws IOException {
-		super(filename);
-		if (verify)
-			verifier = new JarVerifier(filename);
-		readMetaEntries();
-	}
-
-	/**
-	 * Return an enumeration containing the JarEntrys contained in this JarFile.
-	 * 
-	 * @return java.util.Enumeration
-	 * @exception java.lang.IllegalStateException
-	 *                If this JarFile has been closed.
-	 */
-	public Enumeration<JarEntry> entries() {
-		class JarFileEnumerator implements Enumeration<JarEntry> {
-			Enumeration ze;
-
-			JarFile jf;
-
-			JarFileEnumerator(Enumeration zenum, JarFile jf) {
-				ze = zenum;
-				this.jf = jf;
-			}
-
-			public boolean hasMoreElements() {
-				return ze.hasMoreElements();
-			}
-
-			public JarEntry nextElement() {
-				JarEntry je = new JarEntry((ZipEntry) ze.nextElement());
-				je.parentJar = jf;
-				if (verifier != null)
-					je.certificates = verifier.getCertificates(je.getName());
-				return je;
-			}
-		}
-		return new JarFileEnumerator(super.entries(), this);
-	}
-
-	/**
-	 * Return the JarEntry specified by name or null if no such entry exists.
-	 * 
-	 * @param name
-	 *            the name of the entry in the jar file
-	 * @return java.util.jar.JarEntry
-	 */
-	public JarEntry getJarEntry(String name) {
-		return (JarEntry) getEntry(name);
-	}
-
-	/**
-	 * Returns the Manifest object associated with this JarFile or null if no
-	 * manifest entry exists.
-	 * 
-	 * @return java.util.jar.Manifest
-	 */
-	public Manifest getManifest() throws IOException {
-		if (manifest != null)
-			return manifest;
-		if (manifestEntry != null) {
-			ByteArrayInputStream is = (ByteArrayInputStream) super
-					.getInputStream(manifestEntry);
-			if (verifier != null) {
-				byte[] buf = new byte[is.available()];
-				is.mark(buf.length);
-				is.read(buf, 0, buf.length);
-				is.reset();
-				verifier.addMetaEntry(manifestEntry.getName(), buf);
-			}
-			try {
-				manifest = new Manifest(is, verifier != null);
-			} finally {
-				is.close();
-			}
-			manifestEntry = null;
-		}
-		return manifest;
-	}
-
-	private void readMetaEntries() throws IOException {
-		ZipEntry[] metaEntries = this.getMetaEntriesImpl(null);
-		int dirLength = META_DIR.length();
-
-		boolean signed = false;
-		if (null != metaEntries) {
-			for (int i = 0; i < metaEntries.length; i++) {
-				ZipEntry entry = metaEntries[i];
-				String entryName = entry.getName();
-				if (manifestEntry == null
-						&& manifest == null
-						&& entryName.regionMatches(true, dirLength,
-								MANIFEST_NAME, dirLength, MANIFEST_NAME
-										.length()
-										- dirLength)) {
-					manifestEntry = entry;
-					if (verifier == null)
-						break;
-				} else if (verifier != null
-						&& entryName.length() > dirLength
-						&& (entryName.regionMatches(true,
-								entryName.length() - 3, ".SF", 0, 3)
-								|| entryName.regionMatches(true, entryName
-										.length() - 4, ".DSA", 0, 4) || entryName
-								.regionMatches(true, entryName.length() - 4,
-										".RSA", 0, 4))) {
-					signed = true;
-					InputStream is = super.getInputStream(entry);
-					byte[] buf = new byte[is.available()];
-					try {
-						is.read(buf, 0, buf.length);
-					} finally {
-						is.close();
-					}
-					verifier.addMetaEntry(entryName, buf);
-				}
-			}
-		}
-		if (!signed)
-			verifier = null;
-	}
-
-	/**
-	 * Return an InputStream for reading the decompressed contents of ze.
-	 * 
-	 * @param ze
-	 *            the ZipEntry to read from
-	 * @return java.io.InputStream
-	 * @exception java.io.IOException
-	 *                If an error occured while creating the InputStream.
-	 */
-	public InputStream getInputStream(ZipEntry ze) throws IOException {
-		if (manifestEntry != null)
-			getManifest();
-		if (verifier != null) {
-			verifier.setManifest(getManifest());
-			if (manifest != null) {
-				verifier.mainAttributesChunk = manifest
-						.getMainAttributesChunk();
-			}
-			if (verifier.readCertificates()) {
-				verifier.removeMetaEntries();
-				if (manifest != null)
-					manifest.removeChunks();
-				if (!verifier.isSignedJar())
-					verifier = null;
-			}
-		}
-		InputStream in = super.getInputStream(ze);
-		if (in == null)
-			return null;
-		return new JarFileInputStream(in, ze, ze.getSize() >= 0 ? verifier
-				: null);
-	}
-
-	/**
-	 * Return the JarEntry specified by name or null if no such entry exists
-	 * 
-	 * @param name
-	 *            the name of the entry in the jar file
-	 * @return java.util.jar.JarEntry
-	 */
-	public ZipEntry getEntry(String name) {
-		ZipEntry ze = super.getEntry(name);
-		if (ze == null)
-			return ze;
-		JarEntry je = new JarEntry(ze);
-		je.parentJar = this;
-		if (verifier != null)
-			je.certificates = verifier.getCertificates(je.getName());
-		return je;
-	}
+    private ZipEntry manifestEntry;
+
+    JarVerifier verifier;
+
+    static final class JarFileInputStream extends FilterInputStream {
+        private long count;
+
+        private ZipEntry zipEntry;
+
+        private JarVerifier verifier;
+
+        private JarVerifier.VerifierEntry entry;
+
+        private MessageDigest digest;
+
+        JarFileInputStream(InputStream is, ZipEntry ze, JarVerifier ver) {
+            super(is);
+            if (ver != null) {
+                zipEntry = ze;
+                verifier = ver;
+                count = zipEntry.getSize();
+                entry = verifier.initEntry(ze.getName());
+                if (entry != null) {
+                    digest = entry.digest;
+                }
+            }
+        }
+
+        public int read() throws IOException {
+            int r = super.read();
+            if (entry != null) {
+                if (r != -1) {
+                    digest.update((byte) r);
+                    count--;
+                }
+                if (r == -1 || count <= 0) {
+                    JarVerifier.VerifierEntry temp = entry;
+                    entry = null;
+                    verifier.verifySignatures(temp, zipEntry);
+                }
+            }
+            return r;
+        }
+
+        public int read(byte[] buf, int off, int nbytes) throws IOException {
+            int r = super.read(buf, off, nbytes);
+            if (entry != null) {
+                if (r != -1) {
+                    int size = r;
+                    if (count < size) {
+                        size = (int) count;
+                    }
+                    digest.update(buf, off, size);
+                    count -= r;
+                }
+                if (r == -1 || count <= 0) {
+                    JarVerifier.VerifierEntry temp = entry;
+                    entry = null;
+                    verifier.verifySignatures(temp, zipEntry);
+                }
+            }
+            return r;
+        }
+
+        public long skip(long nbytes) throws IOException {
+            long cnt = 0, rem = 0;
+            byte[] buf = new byte[4096];
+            while (cnt < nbytes) {
+                int x = read(buf, 0,
+                        (rem = nbytes - cnt) > buf.length ? buf.length
+                                : (int) rem);
+                if (x == -1) {
+                    return cnt;
+                }
+                cnt += x;
+            }
+            return cnt;
+        }
+    }
+
+    /**
+     * Create a new JarFile using the contents of file.
+     * 
+     * @param file
+     *            java.io.File
+     * @exception java.io.IOException
+     *                If the file cannot be read.
+     */
+    public JarFile(File file) throws IOException {
+        this(file, true);
+    }
+
+    /**
+     * Create a new JarFile using the contents of file.
+     * 
+     * @param file
+     *            java.io.File
+     * @param verify
+     *            verify a signed jar file
+     * @exception java.io.IOException
+     *                If the file cannot be read.
+     */
+    public JarFile(File file, boolean verify) throws IOException {
+        super(file);
+        if (verify) {
+            verifier = new JarVerifier(file.getPath());
+        }
+        readMetaEntries();
+    }
+
+    /**
+     * Create a new JarFile using the contents of file.
+     * 
+     * @param file
+     *            java.io.File
+     * @param verify
+     *            verify a signed jar file
+     * @param mode
+     *            the mode to use, either OPEN_READ or OPEN_READ | OPEN_DELETE
+     * @exception java.io.IOException
+     *                If the file cannot be read.
+     */
+    public JarFile(File file, boolean verify, int mode) throws IOException {
+        super(file, mode);
+        if (verify) {
+            verifier = new JarVerifier(file.getPath());
+        }
+        readMetaEntries();
+    }
+
+    /**
+     * Create a new JarFile from the contents of the file specified by filename.
+     * 
+     * @param filename
+     *            java.lang.String
+     * @exception java.io.IOException
+     *                If fileName cannot be opened for reading.
+     */
+    public JarFile(String filename) throws IOException {
+        this(filename, true);
+
+    }
+
+    /**
+     * Create a new JarFile from the contents of the file specified by filename.
+     * 
+     * @param filename
+     *            java.lang.String
+     * @param verify
+     *            verify a signed jar file
+     * @exception java.io.IOException
+     *                If fileName cannot be opened for reading.
+     */
+    public JarFile(String filename, boolean verify) throws IOException {
+        super(filename);
+        if (verify) {
+            verifier = new JarVerifier(filename);
+        }
+        readMetaEntries();
+    }
+
+    /**
+     * Return an enumeration containing the JarEntrys contained in this JarFile.
+     * 
+     * @return java.util.Enumeration
+     * @exception java.lang.IllegalStateException
+     *                If this JarFile has been closed.
+     */
+    public Enumeration<JarEntry> entries() {
+        class JarFileEnumerator implements Enumeration<JarEntry> {
+            Enumeration ze;
+
+            JarFile jf;
+
+            JarFileEnumerator(Enumeration zenum, JarFile jf) {
+                ze = zenum;
+                this.jf = jf;
+            }
+
+            public boolean hasMoreElements() {
+                return ze.hasMoreElements();
+            }
+
+            public JarEntry nextElement() {
+                JarEntry je = new JarEntry((ZipEntry) ze.nextElement());
+                je.parentJar = jf;
+                if (verifier != null) {
+                    je.certificates = verifier.getCertificates(je.getName());
+                }
+                return je;
+            }
+        }
+        return new JarFileEnumerator(super.entries(), this);
+    }
+
+    /**
+     * Return the JarEntry specified by name or null if no such entry exists.
+     * 
+     * @param name
+     *            the name of the entry in the jar file
+     * @return java.util.jar.JarEntry
+     */
+    public JarEntry getJarEntry(String name) {
+        return (JarEntry) getEntry(name);
+    }
+
+    /**
+     * Returns the Manifest object associated with this JarFile or null if no
+     * manifest entry exists.
+     * 
+     * @return java.util.jar.Manifest
+     */
+    public Manifest getManifest() throws IOException {
+        if (manifest != null) {
+            return manifest;
+        }
+        if (manifestEntry != null) {
+            ByteArrayInputStream is = (ByteArrayInputStream) super
+                    .getInputStream(manifestEntry);
+            if (verifier != null) {
+                byte[] buf = new byte[is.available()];
+                is.mark(buf.length);
+                is.read(buf, 0, buf.length);
+                is.reset();
+                verifier.addMetaEntry(manifestEntry.getName(), buf);
+            }
+            try {
+                manifest = new Manifest(is, verifier != null);
+            } finally {
+                is.close();
+            }
+            manifestEntry = null;
+        }
+        return manifest;
+    }
+
+    private void readMetaEntries() throws IOException {
+        ZipEntry[] metaEntries = this.getMetaEntriesImpl(null);
+        int dirLength = META_DIR.length();
+
+        boolean signed = false;
+        if (null != metaEntries) {
+            for (ZipEntry entry : metaEntries) {
+                String entryName = entry.getName();
+                if (manifestEntry == null
+                        && manifest == null
+                        && entryName.regionMatches(true, dirLength,
+                                MANIFEST_NAME, dirLength, MANIFEST_NAME
+                                        .length()
+                                        - dirLength)) {
+                    manifestEntry = entry;
+                    if (verifier == null) {
+                        break;
+                    }
+                } else if (verifier != null
+                        && entryName.length() > dirLength
+                        && (entryName.regionMatches(true,
+                                entryName.length() - 3, ".SF", 0, 3)
+                                || entryName.regionMatches(true, entryName
+                                        .length() - 4, ".DSA", 0, 4) || entryName
+                                .regionMatches(true, entryName.length() - 4,
+                                        ".RSA", 0, 4))) {
+                    signed = true;
+                    InputStream is = super.getInputStream(entry);
+                    byte[] buf = new byte[is.available()];
+                    try {
+                        is.read(buf, 0, buf.length);
+                    } finally {
+                        is.close();
+                    }
+                    verifier.addMetaEntry(entryName, buf);
+                }
+            }
+        }
+        if (!signed) {
+            verifier = null;
+        }
+    }
+
+    /**
+     * Return an InputStream for reading the decompressed contents of ze.
+     * 
+     * @param ze
+     *            the ZipEntry to read from
+     * @return java.io.InputStream
+     * @exception java.io.IOException
+     *                If an error occured while creating the InputStream.
+     */
+    public InputStream getInputStream(ZipEntry ze) throws IOException {
+        if (manifestEntry != null) {
+            getManifest();
+        }
+        if (verifier != null) {
+            verifier.setManifest(getManifest());
+            if (manifest != null) {
+                verifier.mainAttributesChunk = manifest
+                        .getMainAttributesChunk();
+            }
+            if (verifier.readCertificates()) {
+                verifier.removeMetaEntries();
+                if (manifest != null) {
+                    manifest.removeChunks();
+                }
+                if (!verifier.isSignedJar()) {
+                    verifier = null;
+                }
+            }
+        }
+        InputStream in = super.getInputStream(ze);
+        if (in == null) {
+            return null;
+        }
+        return new JarFileInputStream(in, ze, ze.getSize() >= 0 ? verifier
+                : null);
+    }
+
+    /**
+     * Return the JarEntry specified by name or null if no such entry exists
+     * 
+     * @param name
+     *            the name of the entry in the jar file
+     * @return java.util.jar.JarEntry
+     */
+    public ZipEntry getEntry(String name) {
+        ZipEntry ze = super.getEntry(name);
+        if (ze == null) {
+            return ze;
+        }
+        JarEntry je = new JarEntry(ze);
+        je.parentJar = this;
+        if (verifier != null) {
+            je.certificates = verifier.getCertificates(je.getName());
+        }
+        return je;
+    }
 
-	private native ZipEntry[] getMetaEntriesImpl(byte[] buf);
+    private native ZipEntry[] getMetaEntriesImpl(byte[] buf);
 
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java?rev=410558&r1=410557&r2=410558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarInputStream.java
Wed May 31 08:10:45 2006
@@ -15,7 +15,6 @@
 
 package java.util.jar;
 
-
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -25,135 +24,139 @@
 
 public class JarInputStream extends ZipInputStream {
 
-	private Manifest manifest;
+    private Manifest manifest;
+
+    private boolean eos = false;
+
+    private JarEntry mEntry;
+
+    private JarEntry jarEntry;
+
+    private boolean isMeta;
 
-	private boolean eos = false;
+    private JarVerifier verifier;
 
-	private JarEntry mEntry;
+    private OutputStream verStream;
+
+    /**
+     * Constructs a new JarInputStream from stream
+     */
+    public JarInputStream(InputStream stream, boolean verify)
+            throws IOException {
+        super(stream);
+        if (verify) {
+            verifier = new JarVerifier("JarInputStream");
+        }
+        if ((mEntry = getNextJarEntry()) == null) {
+            return;
+        }
+        String name = mEntry.getName().toUpperCase();
+        if (name.equals(JarFile.META_DIR)) {
+            mEntry = null; // modifies behavior of getNextJarEntry()
+            closeEntry();
+            mEntry = getNextJarEntry();
+            name = mEntry.getName().toUpperCase();
+        }
+        if (name.equals(JarFile.MANIFEST_NAME)) {
+            mEntry = null;
+            manifest = new Manifest(this, verify);
+            closeEntry();
+            if (verify) {
+                verifier.setManifest(manifest);
+                if (manifest != null) {
+                    verifier.mainAttributesChunk = manifest
+                            .getMainAttributesChunk();
+                }
+            }
 
-	private JarEntry jarEntry;
+        } else {
+            Attributes temp = new Attributes(3);
+            temp.map.put("hidden", null);
+            mEntry.setAttributes(temp);
+            /*
+             * if not from the first entry, we will not get enough
+             * information,so no verify will be taken out.
+             */
+            verifier = null;
+        }
+    }
 
-	private boolean isMeta;
-
-	private JarVerifier verifier;
-
-	private OutputStream verStream;
-
-	/**
-	 * Constructs a new JarInputStream from stream
-	 */
-	public JarInputStream(InputStream stream, boolean verify)
-			throws IOException {
-		super(stream);
-		if (verify) {
-			verifier = new JarVerifier("JarInputStream");			
-		}
-		if ((mEntry = getNextJarEntry()) == null)
-			return;
-		String name = mEntry.getName().toUpperCase();
-		if (name.equals(JarFile.META_DIR)) {
-			mEntry = null; // modifies behavior of getNextJarEntry()
-			closeEntry();
-			mEntry = getNextJarEntry();
-			name = mEntry.getName().toUpperCase();
-		}
-		if (name.equals(JarFile.MANIFEST_NAME)) {
-			mEntry = null;
-			manifest = new Manifest(this, verify);
-			closeEntry();
-			if (verify) {
-				verifier.setManifest(manifest);
-				if (manifest != null)
-					verifier.mainAttributesChunk = manifest
-							.getMainAttributesChunk();
-			}
-
-		} else {
-			Attributes temp = new Attributes(3);
-			temp.map.put("hidden", null);
-			mEntry.setAttributes(temp);
-			/* if not from the first entry, we will not get
-			 enough information,so no verify will be taken out.*/
-			verifier = null;
-		}
-	}
-
-	public JarInputStream(InputStream stream) throws IOException {
-		this(stream, true);
-	}
-
-	/**
-	 * Returns the Manifest object associated with this JarInputStream or null
-	 * if no manifest entry exists.
-	 * 
-	 * @return java.util.jar.Manifest
-	 */
-	public Manifest getManifest() {
-		return manifest;
-	}
-
-	/**
-	 * Returns the next JarEntry contained in this stream or null if no more
-	 * entries are present.
-	 * 
-	 * @return java.util.jar.JarEntry
-	 * @exception java.io.IOException
-	 *                If an error occurs while reading the entry
-	 */
-	public JarEntry getNextJarEntry() throws IOException {
-		return (JarEntry) getNextEntry();
-	}
-
-	public int read(byte[] buffer, int offset, int length) throws IOException {
-		if (mEntry != null)
-			return -1;
-		int r = super.read(buffer, offset, length);
-		if (verStream != null && !eos) {
-			if (r == -1) {
-				eos = true;				
-				if (verifier != null) {
-					if (isMeta) {
-						verifier.addMetaEntry(jarEntry.getName(),
-								((ByteArrayOutputStream) verStream)
-					    					.toByteArray());
-						try {
-							verifier.readCertificates();
-						} catch (SecurityException e) {
-							verifier = null;
-							throw e;
-						}
-					}
-					else {
+    public JarInputStream(InputStream stream) throws IOException {
+        this(stream, true);
+    }
+
+    /**
+     * Returns the Manifest object associated with this JarInputStream or null
+     * if no manifest entry exists.
+     * 
+     * @return java.util.jar.Manifest
+     */
+    public Manifest getManifest() {
+        return manifest;
+    }
+
+    /**
+     * Returns the next JarEntry contained in this stream or null if no more
+     * entries are present.
+     * 
+     * @return java.util.jar.JarEntry
+     * @exception java.io.IOException
+     *                If an error occurs while reading the entry
+     */
+    public JarEntry getNextJarEntry() throws IOException {
+        return (JarEntry) getNextEntry();
+    }
+
+    public int read(byte[] buffer, int offset, int length) throws IOException {
+        if (mEntry != null) {
+            return -1;
+        }
+        int r = super.read(buffer, offset, length);
+        if (verStream != null && !eos) {
+            if (r == -1) {
+                eos = true;
+                if (verifier != null) {
+                    if (isMeta) {
+                        verifier.addMetaEntry(jarEntry.getName(),
+                                ((ByteArrayOutputStream) verStream)
+                                        .toByteArray());
+                        try {
+                            verifier.readCertificates();
+                        } catch (SecurityException e) {
+                            verifier = null;
+                            throw e;
+                        }
+                    } else {
                         verifier.verifySignatures(
                                 (JarVerifier.VerifierEntry) this.verStream,
                                 jarEntry);
                     }
-				}
-			} else {
-				verStream.write(buffer, offset, r);
+                }
+            } else {
+                verStream.write(buffer, offset, r);
             }
-		}
-		return r;
-	}
-
-	/**
-	 * Returns the next ZipEntry contained in this stream or null if no more
-	 * entries are present.
-	 * 
-	 * @return java.util.zip.ZipEntry
-	 * @exception java.io.IOException
-	 *                If an error occurs while reading the entry
-	 */
-	public ZipEntry getNextEntry() throws IOException {
-		if (mEntry != null) {
-			jarEntry = mEntry;
-			mEntry = null;
-			jarEntry.setAttributes(null);			
-		}
-		else {
+        }
+        return r;
+    }
+
+    /**
+     * Returns the next ZipEntry contained in this stream or null if no more
+     * entries are present.
+     * 
+     * @return java.util.zip.ZipEntry
+     * @exception java.io.IOException
+     *                If an error occurs while reading the entry
+     */
+    public ZipEntry getNextEntry() throws IOException {
+        if (mEntry != null) {
+            jarEntry = mEntry;
+            mEntry = null;
+            jarEntry.setAttributes(null);
+        } else {
             jarEntry = (JarEntry) super.getNextEntry();
-            if (jarEntry == null)
+            if (jarEntry == null) {
                 return null;
+            }
             if (verifier != null) {
                 isMeta = jarEntry.getName().toUpperCase().startsWith(
                         JarFile.META_DIR);
@@ -164,14 +167,15 @@
                 }
             }
         }
-		eos = false;			
-		return jarEntry;
-	}
-
-	protected ZipEntry createZipEntry(String name) {
-		JarEntry entry = new JarEntry(name);
-		if (manifest != null)
-			entry.setAttributes(manifest.getAttributes(name));
-		return entry;
-	}
+        eos = false;
+        return jarEntry;
+    }
+
+    protected ZipEntry createZipEntry(String name) {
+        JarEntry entry = new JarEntry(name);
+        if (manifest != null) {
+            entry.setAttributes(manifest.getAttributes(name));
+        }
+        return entry;
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarOutputStream.java?rev=410558&r1=410557&r2=410558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/JarOutputStream.java
Wed May 31 08:10:45 2006
@@ -15,7 +15,6 @@
 
 package java.util.jar;
 
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.zip.ZipEntry;
@@ -26,54 +25,55 @@
  */
 public class JarOutputStream extends ZipOutputStream {
 
-	private Manifest manifest;
-
-	/**
-	 * Contructs a new JarOuputStream using os as the underlying stream.
-	 * Manifest information for the JarFile to be written is obtained from the
-	 * parameter Manifest, mf.
-	 * 
-	 * @param os
-	 *            The OutputStream to write to
-	 * @param mf
-	 *            The Manifest to output for this Jar.
-	 * @exception IOException
-	 *                If an error occurs creating the JarOutputStream
-	 */
-	public JarOutputStream(OutputStream os, Manifest mf) throws IOException {
-		super(os);
-		if (mf == null)
-			throw new NullPointerException();
-		manifest = mf;
-		ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME);
-		putNextEntry(ze);
-		manifest.write(this);
-		closeEntry();
-	}
-
-	/**
-	 * Contructs a new JarOuputStream using os as the underlying stream.
-	 * 
-	 * @param os
-	 *            The OutputStream to write to
-	 * @exception IOException
-	 *                If an error occurs creating the JarOutputStream
-	 */
-	public JarOutputStream(OutputStream os) throws IOException {
-		super(os);
-	}
+    private Manifest manifest;
 
-	/**
-	 * Writes the specified entry to the underlying stream. The previous entry
-	 * is closed if it is still open.
-	 * 
-	 * 
-	 * @param ze
-	 *            The ZipEntry to write
-	 * @exception IOException
-	 *                If an error occurs writing the entry
-	 */
-	public void putNextEntry(ZipEntry ze) throws IOException {
-		super.putNextEntry(ze);
-	}
+    /**
+     * Contructs a new JarOuputStream using os as the underlying stream.
+     * Manifest information for the JarFile to be written is obtained from the
+     * parameter Manifest, mf.
+     * 
+     * @param os
+     *            The OutputStream to write to
+     * @param mf
+     *            The Manifest to output for this Jar.
+     * @exception IOException
+     *                If an error occurs creating the JarOutputStream
+     */
+    public JarOutputStream(OutputStream os, Manifest mf) throws IOException {
+        super(os);
+        if (mf == null) {
+            throw new NullPointerException();
+        }
+        manifest = mf;
+        ZipEntry ze = new ZipEntry(JarFile.MANIFEST_NAME);
+        putNextEntry(ze);
+        manifest.write(this);
+        closeEntry();
+    }
+
+    /**
+     * Contructs a new JarOuputStream using os as the underlying stream.
+     * 
+     * @param os
+     *            The OutputStream to write to
+     * @exception IOException
+     *                If an error occurs creating the JarOutputStream
+     */
+    public JarOutputStream(OutputStream os) throws IOException {
+        super(os);
+    }
+
+    /**
+     * Writes the specified entry to the underlying stream. The previous entry
+     * is closed if it is still open.
+     * 
+     * 
+     * @param ze
+     *            The ZipEntry to write
+     * @exception IOException
+     *                If an error occurs writing the entry
+     */
+    public void putNextEntry(ZipEntry ze) throws IOException {
+        super.putNextEntry(ze);
+    }
 }



Mime
View raw message