提交 60f5d839 编写于 作者: S smarks
上级 ffad86a1
...@@ -71,7 +71,7 @@ public class Attributes implements Map<Object,Object>, Cloneable { ...@@ -71,7 +71,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
* @param size the initial number of attributes * @param size the initial number of attributes
*/ */
public Attributes(int size) { public Attributes(int size) {
map = new HashMap(size); map = new HashMap<>(size);
} }
/** /**
...@@ -81,7 +81,7 @@ public class Attributes implements Map<Object,Object>, Cloneable { ...@@ -81,7 +81,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
* @param attr the specified Attributes * @param attr the specified Attributes
*/ */
public Attributes(Attributes attr) { public Attributes(Attributes attr) {
map = new HashMap(attr); map = new HashMap<>(attr);
} }
...@@ -296,9 +296,9 @@ public class Attributes implements Map<Object,Object>, Cloneable { ...@@ -296,9 +296,9 @@ public class Attributes implements Map<Object,Object>, Cloneable {
* XXX Need to handle UTF8 values and break up lines longer than 72 bytes * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
*/ */
void write(DataOutputStream os) throws IOException { void write(DataOutputStream os) throws IOException {
Iterator it = entrySet().iterator(); Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next(); Map.Entry<Object, Object> e = it.next();
StringBuffer buffer = new StringBuffer( StringBuffer buffer = new StringBuffer(
((Name)e.getKey()).toString()); ((Name)e.getKey()).toString());
buffer.append(": "); buffer.append(": ");
...@@ -340,9 +340,9 @@ public class Attributes implements Map<Object,Object>, Cloneable { ...@@ -340,9 +340,9 @@ public class Attributes implements Map<Object,Object>, Cloneable {
// write out all attributes except for the version // write out all attributes except for the version
// we wrote out earlier // we wrote out earlier
Iterator it = entrySet().iterator(); Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next(); Map.Entry<Object, Object> e = it.next();
String name = ((Name)e.getKey()).toString(); String name = ((Name)e.getKey()).toString();
if ((version != null) && ! (name.equalsIgnoreCase(vername))) { if ((version != null) && ! (name.equalsIgnoreCase(vername))) {
...@@ -499,7 +499,7 @@ public class Attributes implements Map<Object,Object>, Cloneable { ...@@ -499,7 +499,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
*/ */
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof Name) { if (o instanceof Name) {
Comparator c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER; Comparator<String> c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER;
return c.compare(name, ((Name)o).name) == 0; return c.compare(name, ((Name)o).name) == 0;
} else { } else {
return false; return false;
......
...@@ -48,21 +48,21 @@ class JarVerifier { ...@@ -48,21 +48,21 @@ class JarVerifier {
/* a table mapping names to code signers, for jar entries that have /* a table mapping names to code signers, for jar entries that have
had their actual hashes verified */ had their actual hashes verified */
private Hashtable verifiedSigners; private Hashtable<String, CodeSigner[]> verifiedSigners;
/* a table mapping names to code signers, for jar entries that have /* a table mapping names to code signers, for jar entries that have
passed the .SF/.DSA/.EC -> MANIFEST check */ passed the .SF/.DSA/.EC -> MANIFEST check */
private Hashtable sigFileSigners; private Hashtable<String, CodeSigner[]> sigFileSigners;
/* a hash table to hold .SF bytes */ /* a hash table to hold .SF bytes */
private Hashtable sigFileData; private Hashtable<String, byte[]> sigFileData;
/** "queue" of pending PKCS7 blocks that we couldn't parse /** "queue" of pending PKCS7 blocks that we couldn't parse
* until we parsed the .SF file */ * until we parsed the .SF file */
private ArrayList pendingBlocks; private ArrayList<SignatureFileVerifier> pendingBlocks;
/* cache of CodeSigner objects */ /* cache of CodeSigner objects */
private ArrayList signerCache; private ArrayList<CodeSigner[]> signerCache;
/* Are we parsing a block? */ /* Are we parsing a block? */
private boolean parsingBlockOrSF = false; private boolean parsingBlockOrSF = false;
...@@ -94,10 +94,10 @@ class JarVerifier { ...@@ -94,10 +94,10 @@ class JarVerifier {
public JarVerifier(byte rawBytes[]) { public JarVerifier(byte rawBytes[]) {
manifestRawBytes = rawBytes; manifestRawBytes = rawBytes;
sigFileSigners = new Hashtable(); sigFileSigners = new Hashtable<>();
verifiedSigners = new Hashtable(); verifiedSigners = new Hashtable<>();
sigFileData = new Hashtable(11); sigFileData = new Hashtable<>(11);
pendingBlocks = new ArrayList(); pendingBlocks = new ArrayList<>();
baos = new ByteArrayOutputStream(); baos = new ByteArrayOutputStream();
manifestDigests = new ArrayList<>(); manifestDigests = new ArrayList<>();
} }
...@@ -248,10 +248,9 @@ class JarVerifier { ...@@ -248,10 +248,9 @@ class JarVerifier {
sigFileData.put(key, bytes); sigFileData.put(key, bytes);
// check pending blocks, we can now process // check pending blocks, we can now process
// anyone waiting for this .SF file // anyone waiting for this .SF file
Iterator it = pendingBlocks.iterator(); Iterator<SignatureFileVerifier> it = pendingBlocks.iterator();
while (it.hasNext()) { while (it.hasNext()) {
SignatureFileVerifier sfv = SignatureFileVerifier sfv = it.next();
(SignatureFileVerifier) it.next();
if (sfv.needSignatureFile(key)) { if (sfv.needSignatureFile(key)) {
if (debug != null) { if (debug != null) {
debug.println( debug.println(
...@@ -270,7 +269,7 @@ class JarVerifier { ...@@ -270,7 +269,7 @@ class JarVerifier {
String key = uname.substring(0, uname.lastIndexOf(".")); String key = uname.substring(0, uname.lastIndexOf("."));
if (signerCache == null) if (signerCache == null)
signerCache = new ArrayList(); signerCache = new ArrayList<>();
if (manDig == null) { if (manDig == null) {
synchronized(manifestRawBytes) { synchronized(manifestRawBytes) {
...@@ -287,7 +286,7 @@ class JarVerifier { ...@@ -287,7 +286,7 @@ class JarVerifier {
if (sfv.needSignatureFileBytes()) { if (sfv.needSignatureFileBytes()) {
// see if we have already parsed an external .SF file // see if we have already parsed an external .SF file
byte[] bytes = (byte[]) sigFileData.get(key); byte[] bytes = sigFileData.get(key);
if (bytes == null) { if (bytes == null) {
// put this block on queue for later processing // put this block on queue for later processing
...@@ -343,7 +342,7 @@ class JarVerifier { ...@@ -343,7 +342,7 @@ class JarVerifier {
*/ */
public CodeSigner[] getCodeSigners(String name) public CodeSigner[] getCodeSigners(String name)
{ {
return (CodeSigner[])verifiedSigners.get(name); return verifiedSigners.get(name);
} }
public CodeSigner[] getCodeSigners(JarFile jar, JarEntry entry) public CodeSigner[] getCodeSigners(JarFile jar, JarEntry entry)
...@@ -376,15 +375,14 @@ class JarVerifier { ...@@ -376,15 +375,14 @@ class JarVerifier {
CodeSigner[] signers) { CodeSigner[] signers) {
if (signers != null) { if (signers != null) {
ArrayList certChains = new ArrayList(); ArrayList<java.security.cert.Certificate> certChains = new ArrayList<>();
for (int i = 0; i < signers.length; i++) { for (int i = 0; i < signers.length; i++) {
certChains.addAll( certChains.addAll(
signers[i].getSignerCertPath().getCertificates()); signers[i].getSignerCertPath().getCertificates());
} }
// Convert into a Certificate[] // Convert into a Certificate[]
return (java.security.cert.Certificate[]) return certChains.toArray(
certChains.toArray(
new java.security.cert.Certificate[certChains.size()]); new java.security.cert.Certificate[certChains.size()]);
} }
return null; return null;
...@@ -418,8 +416,8 @@ class JarVerifier { ...@@ -418,8 +416,8 @@ class JarVerifier {
// MANIFEST.MF is always treated as signed and verified, // MANIFEST.MF is always treated as signed and verified,
// move its signers from sigFileSigners to verifiedSigners. // move its signers from sigFileSigners to verifiedSigners.
if (sigFileSigners.containsKey(JarFile.MANIFEST_NAME)) { if (sigFileSigners.containsKey(JarFile.MANIFEST_NAME)) {
verifiedSigners.put(JarFile.MANIFEST_NAME, CodeSigner[] codeSigners = sigFileSigners.remove(JarFile.MANIFEST_NAME);
sigFileSigners.remove(JarFile.MANIFEST_NAME)); verifiedSigners.put(JarFile.MANIFEST_NAME, codeSigners);
} }
} }
...@@ -493,10 +491,10 @@ class JarVerifier { ...@@ -493,10 +491,10 @@ class JarVerifier {
// Extended JavaUtilJarAccess CodeSource API Support // Extended JavaUtilJarAccess CodeSource API Support
private Map urlToCodeSourceMap = new HashMap(); private Map<URL, Map<CodeSigner[], CodeSource>> urlToCodeSourceMap = new HashMap<>();
private Map signerToCodeSource = new HashMap(); private Map<CodeSigner[], CodeSource> signerToCodeSource = new HashMap<>();
private URL lastURL; private URL lastURL;
private Map lastURLMap; private Map<CodeSigner[], CodeSource> lastURLMap;
/* /*
* Create a unique mapping from codeSigner cache entries to CodeSource. * Create a unique mapping from codeSigner cache entries to CodeSource.
...@@ -504,19 +502,19 @@ class JarVerifier { ...@@ -504,19 +502,19 @@ class JarVerifier {
* and shared JAR file although in practice there will be a single URL in use. * and shared JAR file although in practice there will be a single URL in use.
*/ */
private synchronized CodeSource mapSignersToCodeSource(URL url, CodeSigner[] signers) { private synchronized CodeSource mapSignersToCodeSource(URL url, CodeSigner[] signers) {
Map map; Map<CodeSigner[], CodeSource> map;
if (url == lastURL) { if (url == lastURL) {
map = lastURLMap; map = lastURLMap;
} else { } else {
map = (Map) urlToCodeSourceMap.get(url); map = urlToCodeSourceMap.get(url);
if (map == null) { if (map == null) {
map = new HashMap(); map = new HashMap<>();
urlToCodeSourceMap.put(url, map); urlToCodeSourceMap.put(url, map);
} }
lastURLMap = map; lastURLMap = map;
lastURL = url; lastURL = url;
} }
CodeSource cs = (CodeSource) map.get(signers); CodeSource cs = map.get(signers);
if (cs == null) { if (cs == null) {
cs = new VerifierCodeSource(csdomain, url, signers); cs = new VerifierCodeSource(csdomain, url, signers);
signerToCodeSource.put(signers, cs); signerToCodeSource.put(signers, cs);
...@@ -524,16 +522,16 @@ class JarVerifier { ...@@ -524,16 +522,16 @@ class JarVerifier {
return cs; return cs;
} }
private CodeSource[] mapSignersToCodeSources(URL url, List signers, boolean unsigned) { private CodeSource[] mapSignersToCodeSources(URL url, List<CodeSigner[]> signers, boolean unsigned) {
List sources = new ArrayList(); List<CodeSource> sources = new ArrayList<>();
for (int i = 0; i < signers.size(); i++) { for (int i = 0; i < signers.size(); i++) {
sources.add(mapSignersToCodeSource(url, (CodeSigner[]) signers.get(i))); sources.add(mapSignersToCodeSource(url, signers.get(i)));
} }
if (unsigned) { if (unsigned) {
sources.add(mapSignersToCodeSource(url, null)); sources.add(mapSignersToCodeSource(url, null));
} }
return (CodeSource[]) sources.toArray(new CodeSource[sources.size()]); return sources.toArray(new CodeSource[sources.size()]);
} }
private CodeSigner[] emptySigner = new CodeSigner[0]; private CodeSigner[] emptySigner = new CodeSigner[0];
...@@ -553,7 +551,7 @@ class JarVerifier { ...@@ -553,7 +551,7 @@ class JarVerifier {
* but this handles a CodeSource of any type, just in case. * but this handles a CodeSource of any type, just in case.
*/ */
CodeSource[] sources = mapSignersToCodeSources(cs.getLocation(), getJarCodeSigners(), true); CodeSource[] sources = mapSignersToCodeSources(cs.getLocation(), getJarCodeSigners(), true);
List sourceList = new ArrayList(); List<CodeSource> sourceList = new ArrayList<>();
for (int i = 0; i < sources.length; i++) { for (int i = 0; i < sources.length; i++) {
sourceList.add(sources[i]); sourceList.add(sources[i]);
} }
...@@ -574,6 +572,7 @@ class JarVerifier { ...@@ -574,6 +572,7 @@ class JarVerifier {
* signing data that can be compared by object reference identity. * signing data that can be compared by object reference identity.
*/ */
private static class VerifierCodeSource extends CodeSource { private static class VerifierCodeSource extends CodeSource {
private static final long serialVersionUID = -9047366145967768825L;
URL vlocation; URL vlocation;
CodeSigner[] vsigners; CodeSigner[] vsigners;
...@@ -641,16 +640,16 @@ class JarVerifier { ...@@ -641,16 +640,16 @@ class JarVerifier {
return vcerts; return vcerts;
} }
} }
private Map signerMap; private Map<String, CodeSigner[]> signerMap;
private synchronized Map signerMap() { private synchronized Map<String, CodeSigner[]> signerMap() {
if (signerMap == null) { if (signerMap == null) {
/* /*
* Snapshot signer state so it doesn't change on us. We care * Snapshot signer state so it doesn't change on us. We care
* only about the asserted signatures. Verification of * only about the asserted signatures. Verification of
* signature validity happens via the JarEntry apis. * signature validity happens via the JarEntry apis.
*/ */
signerMap = new HashMap(verifiedSigners.size() + sigFileSigners.size()); signerMap = new HashMap<>(verifiedSigners.size() + sigFileSigners.size());
signerMap.putAll(verifiedSigners); signerMap.putAll(verifiedSigners);
signerMap.putAll(sigFileSigners); signerMap.putAll(sigFileSigners);
} }
...@@ -658,15 +657,15 @@ class JarVerifier { ...@@ -658,15 +657,15 @@ class JarVerifier {
} }
public synchronized Enumeration<String> entryNames(JarFile jar, final CodeSource[] cs) { public synchronized Enumeration<String> entryNames(JarFile jar, final CodeSource[] cs) {
final Map map = signerMap(); final Map<String, CodeSigner[]> map = signerMap();
final Iterator itor = map.entrySet().iterator(); final Iterator<Map.Entry<String, CodeSigner[]>> itor = map.entrySet().iterator();
boolean matchUnsigned = false; boolean matchUnsigned = false;
/* /*
* Grab a single copy of the CodeSigner arrays. Check * Grab a single copy of the CodeSigner arrays. Check
* to see if we can optimize CodeSigner equality test. * to see if we can optimize CodeSigner equality test.
*/ */
List req = new ArrayList(cs.length); List<CodeSigner[]> req = new ArrayList<>(cs.length);
for (int i = 0; i < cs.length; i++) { for (int i = 0; i < cs.length; i++) {
CodeSigner[] match = findMatchingSigners(cs[i]); CodeSigner[] match = findMatchingSigners(cs[i]);
if (match != null) { if (match != null) {
...@@ -678,8 +677,8 @@ class JarVerifier { ...@@ -678,8 +677,8 @@ class JarVerifier {
} }
} }
final List signersReq = req; final List<CodeSigner[]> signersReq = req;
final Enumeration enum2 = (matchUnsigned) ? unsignedEntryNames(jar) : emptyEnumeration; final Enumeration<String> enum2 = (matchUnsigned) ? unsignedEntryNames(jar) : emptyEnumeration;
return new Enumeration<String>() { return new Enumeration<String>() {
...@@ -691,14 +690,14 @@ class JarVerifier { ...@@ -691,14 +690,14 @@ class JarVerifier {
} }
while (itor.hasNext()) { while (itor.hasNext()) {
Map.Entry e = (Map.Entry) itor.next(); Map.Entry<String, CodeSigner[]> e = itor.next();
if (signersReq.contains((CodeSigner[]) e.getValue())) { if (signersReq.contains(e.getValue())) {
name = (String) e.getKey(); name = e.getKey();
return true; return true;
} }
} }
while (enum2.hasMoreElements()) { while (enum2.hasMoreElements()) {
name = (String) enum2.nextElement(); name = enum2.nextElement();
return true; return true;
} }
return false; return false;
...@@ -719,13 +718,13 @@ class JarVerifier { ...@@ -719,13 +718,13 @@ class JarVerifier {
* Like entries() but screens out internal JAR mechanism entries * Like entries() but screens out internal JAR mechanism entries
* and includes signed entries with no ZIP data. * and includes signed entries with no ZIP data.
*/ */
public Enumeration<JarEntry> entries2(final JarFile jar, Enumeration e) { public Enumeration<JarEntry> entries2(final JarFile jar, Enumeration<? extends ZipEntry> e) {
final Map map = new HashMap(); final Map<String, CodeSigner[]> map = new HashMap<>();
map.putAll(signerMap()); map.putAll(signerMap());
final Enumeration enum_ = e; final Enumeration<? extends ZipEntry> enum_ = e;
return new Enumeration<JarEntry>() { return new Enumeration<JarEntry>() {
Enumeration signers = null; Enumeration<String> signers = null;
JarEntry entry; JarEntry entry;
public boolean hasMoreElements() { public boolean hasMoreElements() {
...@@ -733,7 +732,7 @@ class JarVerifier { ...@@ -733,7 +732,7 @@ class JarVerifier {
return true; return true;
} }
while (enum_.hasMoreElements()) { while (enum_.hasMoreElements()) {
ZipEntry ze = (ZipEntry) enum_.nextElement(); ZipEntry ze = enum_.nextElement();
if (JarVerifier.isSigningRelated(ze.getName())) { if (JarVerifier.isSigningRelated(ze.getName())) {
continue; continue;
} }
...@@ -744,7 +743,7 @@ class JarVerifier { ...@@ -744,7 +743,7 @@ class JarVerifier {
signers = Collections.enumeration(map.keySet()); signers = Collections.enumeration(map.keySet());
} }
while (signers.hasMoreElements()) { while (signers.hasMoreElements()) {
String name = (String) signers.nextElement(); String name = signers.nextElement();
entry = jar.newEntry(new ZipEntry(name)); entry = jar.newEntry(new ZipEntry(name));
return true; return true;
} }
...@@ -764,7 +763,7 @@ class JarVerifier { ...@@ -764,7 +763,7 @@ class JarVerifier {
} }
}; };
} }
private Enumeration emptyEnumeration = new Enumeration<String>() { private Enumeration<String> emptyEnumeration = new Enumeration<String>() {
public boolean hasMoreElements() { public boolean hasMoreElements() {
return false; return false;
...@@ -797,8 +796,8 @@ class JarVerifier { ...@@ -797,8 +796,8 @@ class JarVerifier {
} }
private Enumeration<String> unsignedEntryNames(JarFile jar) { private Enumeration<String> unsignedEntryNames(JarFile jar) {
final Map map = signerMap(); final Map<String, CodeSigner[]> map = signerMap();
final Enumeration entries = jar.entries(); final Enumeration<JarEntry> entries = jar.entries();
return new Enumeration<String>() { return new Enumeration<String>() {
String name; String name;
...@@ -813,7 +812,7 @@ class JarVerifier { ...@@ -813,7 +812,7 @@ class JarVerifier {
} }
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
String value; String value;
ZipEntry e = (ZipEntry) entries.nextElement(); ZipEntry e = entries.nextElement();
value = e.getName(); value = e.getName();
if (e.isDirectory() || isSigningRelated(value)) { if (e.isDirectory() || isSigningRelated(value)) {
continue; continue;
...@@ -836,14 +835,14 @@ class JarVerifier { ...@@ -836,14 +835,14 @@ class JarVerifier {
} }
}; };
} }
private List jarCodeSigners; private List<CodeSigner[]> jarCodeSigners;
private synchronized List getJarCodeSigners() { private synchronized List<CodeSigner[]> getJarCodeSigners() {
CodeSigner[] signers; CodeSigner[] signers;
if (jarCodeSigners == null) { if (jarCodeSigners == null) {
HashSet set = new HashSet(); HashSet<CodeSigner[]> set = new HashSet<>();
set.addAll(signerMap().values()); set.addAll(signerMap().values());
jarCodeSigners = new ArrayList(); jarCodeSigners = new ArrayList<>();
jarCodeSigners.addAll(set); jarCodeSigners.addAll(set);
} }
return jarCodeSigners; return jarCodeSigners;
...@@ -858,7 +857,7 @@ class JarVerifier { ...@@ -858,7 +857,7 @@ class JarVerifier {
public CodeSource getCodeSource(URL url, String name) { public CodeSource getCodeSource(URL url, String name) {
CodeSigner[] signers; CodeSigner[] signers;
signers = (CodeSigner[]) signerMap().get(name); signers = signerMap().get(name);
return mapSignersToCodeSource(url, signers); return mapSignersToCodeSource(url, signers);
} }
......
...@@ -55,7 +55,7 @@ public class CommandLine { ...@@ -55,7 +55,7 @@ public class CommandLine {
public static String[] parse(String[] args) public static String[] parse(String[] args)
throws IOException throws IOException
{ {
ArrayList newArgs = new ArrayList(args.length); List<String> newArgs = new ArrayList<>(args.length);
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String arg = args[i]; String arg = args[i];
if (arg.length() > 1 && arg.charAt(0) == '@') { if (arg.length() > 1 && arg.charAt(0) == '@') {
...@@ -69,10 +69,10 @@ public class CommandLine { ...@@ -69,10 +69,10 @@ public class CommandLine {
newArgs.add(arg); newArgs.add(arg);
} }
} }
return (String[])newArgs.toArray(new String[newArgs.size()]); return newArgs.toArray(new String[newArgs.size()]);
} }
private static void loadCmdFile(String name, List args) private static void loadCmdFile(String name, List<String> args)
throws IOException throws IOException
{ {
Reader r = new BufferedReader(new FileReader(name)); Reader r = new BufferedReader(new FileReader(name));
...@@ -83,7 +83,7 @@ public class CommandLine { ...@@ -83,7 +83,7 @@ public class CommandLine {
st.commentChar('#'); st.commentChar('#');
st.quoteChar('"'); st.quoteChar('"');
st.quoteChar('\''); st.quoteChar('\'');
while (st.nextToken() != st.TT_EOF) { while (st.nextToken() != StreamTokenizer.TT_EOF) {
args.add(st.sval); args.add(st.sval);
} }
r.close(); r.close();
......
...@@ -47,10 +47,10 @@ public class Manifest { ...@@ -47,10 +47,10 @@ public class Manifest {
/* list of headers that all pertain to a particular /* list of headers that all pertain to a particular
* file in the archive * file in the archive
*/ */
private Vector entries = new Vector(); private Vector<MessageHeader> entries = new Vector<>();
private byte[] tmpbuf = new byte[512]; private byte[] tmpbuf = new byte[512];
/* a hashtable of entries, for fast lookup */ /* a hashtable of entries, for fast lookup */
private Hashtable tableEntries = new Hashtable(); private Hashtable<String, MessageHeader> tableEntries = new Hashtable<>();
static final String[] hashes = {"SHA"}; static final String[] hashes = {"SHA"};
static final byte[] EOL = {(byte)'\r', (byte)'\n'}; static final byte[] EOL = {(byte)'\r', (byte)'\n'};
...@@ -115,14 +115,14 @@ public class Manifest { ...@@ -115,14 +115,14 @@ public class Manifest {
} }
public MessageHeader getEntry(String name) { public MessageHeader getEntry(String name) {
return (MessageHeader) tableEntries.get(name); return tableEntries.get(name);
} }
public MessageHeader entryAt(int i) { public MessageHeader entryAt(int i) {
return (MessageHeader) entries.elementAt(i); return entries.elementAt(i);
} }
public Enumeration entries() { public Enumeration<MessageHeader> entries() {
return entries.elements(); return entries.elements();
} }
...@@ -214,7 +214,7 @@ public class Manifest { ...@@ -214,7 +214,7 @@ public class Manifest {
/* the first header in the file should be the global one. /* the first header in the file should be the global one.
* It should say "Manifest-Version: x.x"; if not add it * It should say "Manifest-Version: x.x"; if not add it
*/ */
MessageHeader globals = (MessageHeader) entries.elementAt(0); MessageHeader globals = entries.elementAt(0);
if (globals.findValue("Manifest-Version") == null) { if (globals.findValue("Manifest-Version") == null) {
/* Assume this is a user-defined manifest. If it has a Name: <..> /* Assume this is a user-defined manifest. If it has a Name: <..>
...@@ -238,7 +238,7 @@ public class Manifest { ...@@ -238,7 +238,7 @@ public class Manifest {
globals.print(ps); globals.print(ps);
for (int i = 1; i < entries.size(); ++i) { for (int i = 1; i < entries.size(); ++i) {
MessageHeader mh = (MessageHeader) entries.elementAt(i); MessageHeader mh = entries.elementAt(i);
mh.print(ps); mh.print(ps);
} }
} }
......
...@@ -47,7 +47,7 @@ import sun.security.x509.AlgorithmId; ...@@ -47,7 +47,7 @@ import sun.security.x509.AlgorithmId;
* *
* <p>Each entry section contains the name of an entry (which must * <p>Each entry section contains the name of an entry (which must
* have a counterpart in the manifest). Like the manifest it contains * have a counterpart in the manifest). Like the manifest it contains
* a hash, the hash of the manifest section correspondind to the * a hash, the hash of the manifest section corresponding to the
* name. Since the manifest entry contains the hash of the data, this * name. Since the manifest entry contains the hash of the data, this
* is equivalent to a signature of the data, plus the attributes of * is equivalent to a signature of the data, plus the attributes of
* the manifest entry. * the manifest entry.
...@@ -66,7 +66,7 @@ public class SignatureFile { ...@@ -66,7 +66,7 @@ public class SignatureFile {
/* list of headers that all pertain to a particular file in the /* list of headers that all pertain to a particular file in the
* archive */ * archive */
private Vector entries = new Vector(); private Vector<MessageHeader> entries = new Vector<>();
/* Right now we only support SHA hashes */ /* Right now we only support SHA hashes */
static final String[] hashes = {"SHA"}; static final String[] hashes = {"SHA"};
...@@ -98,7 +98,7 @@ public class SignatureFile { ...@@ -98,7 +98,7 @@ public class SignatureFile {
* character in length. */ * character in length. */
private SignatureFile(String name) throws JarException { private SignatureFile(String name) throws JarException {
entries = new Vector(); entries = new Vector<>();
if (name != null) { if (name != null) {
if (name.length() > 8 || name.indexOf('.') != -1) { if (name.length() > 8 || name.indexOf('.') != -1) {
...@@ -142,9 +142,9 @@ public class SignatureFile { ...@@ -142,9 +142,9 @@ public class SignatureFile {
this(name, true); this(name, true);
this.manifest = manifest; this.manifest = manifest;
Enumeration enum_ = manifest.entries(); Enumeration<MessageHeader> enum_ = manifest.entries();
while (enum_.hasMoreElements()) { while (enum_.hasMoreElements()) {
MessageHeader mh = (MessageHeader)enum_.nextElement(); MessageHeader mh = enum_.nextElement();
String entryName = mh.findValue("Name"); String entryName = mh.findValue("Name");
if (entryName != null) { if (entryName != null) {
add(entryName); add(entryName);
...@@ -269,9 +269,9 @@ public class SignatureFile { ...@@ -269,9 +269,9 @@ public class SignatureFile {
*the entry does not exist. *the entry does not exist.
*/ */
public MessageHeader getEntry(String name) { public MessageHeader getEntry(String name) {
Enumeration enum_ = entries(); Enumeration<MessageHeader> enum_ = entries();
while(enum_.hasMoreElements()) { while(enum_.hasMoreElements()) {
MessageHeader mh = (MessageHeader)enum_.nextElement(); MessageHeader mh = enum_.nextElement();
if (name.equals(mh.findValue("Name"))) { if (name.equals(mh.findValue("Name"))) {
return mh; return mh;
} }
...@@ -282,13 +282,13 @@ public class SignatureFile { ...@@ -282,13 +282,13 @@ public class SignatureFile {
/** /**
* Returns the n-th entry. The global header is a entry 0. */ * Returns the n-th entry. The global header is a entry 0. */
public MessageHeader entryAt(int n) { public MessageHeader entryAt(int n) {
return (MessageHeader) entries.elementAt(n); return entries.elementAt(n);
} }
/** /**
* Returns an enumeration of the entries. * Returns an enumeration of the entries.
*/ */
public Enumeration entries() { public Enumeration<MessageHeader> entries() {
return entries.elements(); return entries.elements();
} }
...@@ -322,11 +322,11 @@ public class SignatureFile { ...@@ -322,11 +322,11 @@ public class SignatureFile {
} }
} }
private Hashtable digests = new Hashtable(); private Hashtable<String, MessageDigest> digests = new Hashtable<>();
private MessageDigest getDigest(String algorithm) private MessageDigest getDigest(String algorithm)
throws NoSuchAlgorithmException { throws NoSuchAlgorithmException {
MessageDigest dig = (MessageDigest)digests.get(algorithm); MessageDigest dig = digests.get(algorithm);
if (dig == null) { if (dig == null) {
dig = MessageDigest.getInstance(algorithm); dig = MessageDigest.getInstance(algorithm);
digests.put(algorithm, dig); digests.put(algorithm, dig);
...@@ -344,7 +344,7 @@ public class SignatureFile { ...@@ -344,7 +344,7 @@ public class SignatureFile {
/* the first header in the file should be the global one. /* the first header in the file should be the global one.
* It should say "SignatureFile-Version: x.x"; barf if not * It should say "SignatureFile-Version: x.x"; barf if not
*/ */
MessageHeader globals = (MessageHeader) entries.elementAt(0); MessageHeader globals = entries.elementAt(0);
if (globals.findValue("Signature-Version") == null) { if (globals.findValue("Signature-Version") == null) {
throw new JarException("Signature file requires " + throw new JarException("Signature file requires " +
"Signature-Version: 1.0 in 1st header"); "Signature-Version: 1.0 in 1st header");
...@@ -354,7 +354,7 @@ public class SignatureFile { ...@@ -354,7 +354,7 @@ public class SignatureFile {
globals.print(ps); globals.print(ps);
for (int i = 1; i < entries.size(); ++i) { for (int i = 1; i < entries.size(); ++i) {
MessageHeader mh = (MessageHeader) entries.elementAt(i); MessageHeader mh = entries.elementAt(i);
mh.print(ps); mh.print(ps);
} }
} }
......
...@@ -213,10 +213,10 @@ public class MemoryMonitor extends JPanel { ...@@ -213,10 +213,10 @@ public class MemoryMonitor extends JPanel {
// Calculate remaining size // Calculate remaining size
float ssH = ascent + descent; float ssH = ascent + descent;
float remainingHeight = (float) (y2 - (ssH*2) - 0.5f); float remainingHeight = y2 - (ssH*2) - 0.5f;
float blockHeight = remainingHeight/10; float blockHeight = remainingHeight/10;
float blockWidth = 20.0f; float blockWidth = 20.0f;
float remainingWidth = (float) (x2 - blockWidth - 10); float remainingWidth = x2 - blockWidth - 10;
// .. Memory Free .. // .. Memory Free ..
big.setColor(mfColor); big.setColor(mfColor);
...@@ -224,7 +224,7 @@ public class MemoryMonitor extends JPanel { ...@@ -224,7 +224,7 @@ public class MemoryMonitor extends JPanel {
int i = 0; int i = 0;
for ( ; i < MemUsage ; i++) { for ( ; i < MemUsage ; i++) {
mfRect.setRect(x1+5,(float) y1+ssH+i*blockHeight, mfRect.setRect(x1+5,(float) y1+ssH+i*blockHeight,
blockWidth,(float) blockHeight-1); blockWidth, blockHeight-1);
big.fill(mfRect); big.fill(mfRect);
} }
...@@ -232,13 +232,13 @@ public class MemoryMonitor extends JPanel { ...@@ -232,13 +232,13 @@ public class MemoryMonitor extends JPanel {
big.setColor(Color.green); big.setColor(Color.green);
for ( ; i < 10; i++) { for ( ; i < 10; i++) {
muRect.setRect(x1+5,(float) y1 + ssH+i*blockHeight, muRect.setRect(x1+5,(float) y1 + ssH+i*blockHeight,
blockWidth,(float) blockHeight-1); blockWidth, blockHeight-1);
big.fill(muRect); big.fill(muRect);
} }
// .. Draw History Graph .. // .. Draw History Graph ..
if (remainingWidth <= 30) remainingWidth = (float)30; if (remainingWidth <= 30) remainingWidth = (float)30;
if (remainingHeight <= ssH) remainingHeight = (float)ssH; if (remainingHeight <= ssH) remainingHeight = ssH;
big.setColor(graphColor); big.setColor(graphColor);
int graphX = x1+30; int graphX = x1+30;
int graphY = y1 + (int) ssH; int graphY = y1 + (int) ssH;
...@@ -347,8 +347,8 @@ public class MemoryMonitor extends JPanel { ...@@ -347,8 +347,8 @@ public class MemoryMonitor extends JPanel {
big = bimg.createGraphics(); big = bimg.createGraphics();
big.setFont(font); big.setFont(font);
FontMetrics fm = big.getFontMetrics(font); FontMetrics fm = big.getFontMetrics(font);
ascent = (int) fm.getAscent(); ascent = fm.getAscent();
descent = (int) fm.getDescent(); descent = fm.getDescent();
} }
repaint(); repaint();
try { try {
......
...@@ -61,7 +61,7 @@ public class ZipFileStore extends FileStore { ...@@ -61,7 +61,7 @@ public class ZipFileStore extends FileStore {
private final ZipFileSystem zfs; private final ZipFileSystem zfs;
ZipFileStore(ZipPath zpath) { ZipFileStore(ZipPath zpath) {
this.zfs = (ZipFileSystem)zpath.getFileSystem(); this.zfs = zpath.getFileSystem();
} }
@Override @Override
......
...@@ -1609,7 +1609,7 @@ public class ZipFileSystem extends FileSystem { ...@@ -1609,7 +1609,7 @@ public class ZipFileSystem extends FileSystem {
synchronized (inflaters) { synchronized (inflaters) {
int size = inflaters.size(); int size = inflaters.size();
if (size > 0) { if (size > 0) {
Inflater inf = (Inflater)inflaters.remove(size - 1); Inflater inf = inflaters.remove(size - 1);
return inf; return inf;
} else { } else {
return new Inflater(true); return new Inflater(true);
...@@ -1638,7 +1638,7 @@ public class ZipFileSystem extends FileSystem { ...@@ -1638,7 +1638,7 @@ public class ZipFileSystem extends FileSystem {
synchronized (deflaters) { synchronized (deflaters) {
int size = deflaters.size(); int size = deflaters.size();
if (size > 0) { if (size > 0) {
Deflater def = (Deflater)deflaters.remove(size - 1); Deflater def = deflaters.remove(size - 1);
return def; return def;
} else { } else {
return new Deflater(Deflater.DEFAULT_COMPRESSION, true); return new Deflater(Deflater.DEFAULT_COMPRESSION, true);
......
...@@ -211,7 +211,7 @@ public class ZipFileSystemProvider extends FileSystemProvider { ...@@ -211,7 +211,7 @@ public class ZipFileSystemProvider extends FileSystemProvider {
public <V extends FileAttributeView> V public <V extends FileAttributeView> V
getFileAttributeView(Path path, Class<V> type, LinkOption... options) getFileAttributeView(Path path, Class<V> type, LinkOption... options)
{ {
return (V)ZipFileAttributeView.get(toZipPath(path), type); return ZipFileAttributeView.get(toZipPath(path), type);
} }
@Override @Override
......
...@@ -78,12 +78,12 @@ public class ZipInfo { ...@@ -78,12 +78,12 @@ public class ZipInfo {
// twice // twice
long len = LOCHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENHDR; long len = LOCHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENHDR;
if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len) if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
zfs.zerror("read loc header failed"); ZipFileSystem.zerror("read loc header failed");
if (LOCEXT(buf) > CENEXT(cen, pos) + CENHDR) { if (LOCEXT(buf) > CENEXT(cen, pos) + CENHDR) {
// have to read the second time; // have to read the second time;
len = LOCHDR + LOCNAM(buf) + LOCEXT(buf); len = LOCHDR + LOCNAM(buf) + LOCEXT(buf);
if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len) if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
zfs.zerror("read loc header failed"); ZipFileSystem.zerror("read loc header failed");
} }
printLOC(buf); printLOC(buf);
pos += CENHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENCOM(cen, pos); pos += CENHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENCOM(cen, pos);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册