|
What this is
Other links
The source code/*
* AttributeMap.java
*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 2000-2001 Sun
* Microsystems, Inc. All Rights Reserved.
*
* Contributor(s): Thomas Ball
*
* Version: $Revision: 1.1 $
*/
package org.netbeans.modules.classfile;
import java.io.*;
import java.util.*;
/**
* Class representing a map of classfile attributes. The
* keys for this map are the names of the attributes (as Strings,
* not constant pool indexes). The values are byte arrays that
* hold the contents of the attribute.
*
* Note: if a ClassFile is created with includeCode parameter set to
* false, then no AttributeMaps for the classfile's methods will
* have Code attributes.
*
* @author Thomas Ball
*/
public final class AttributeMap {
Map map;
/**
* Load zero or more attributes from a class, field or method.
*/
static AttributeMap load(DataInputStream in, ConstantPool pool)
throws IOException {
return load(in, pool, false);
}
static AttributeMap load(DataInputStream in, ConstantPool pool,
boolean includeCode) throws IOException {
int count = in.readUnsignedShort();
Map map = new HashMap(count + 1, (float)1.0);
for (int i = 0; i < count; i++) {
CPUTF8Info entry = (CPUTF8Info)pool.get(in.readUnsignedShort());
String name = entry.getName();
int len = in.readInt();
if (!includeCode && name.equals("Code")) {
int n;
while ((n = (int)in.skip(len)) > 0 && n < len)
len -= n;
} else {
byte[] attr = new byte[len];
in.readFully(attr);
map.put(name, attr);
}
}
return new AttributeMap(map);
}
/*
* version of InputStream.skip() which will skip the actual
* number of requested bytes.
*/
private static void skip(InputStream in, int len) throws IOException {
}
AttributeMap(Map attributes) {
this.map = attributes;
}
DataInputStream getStream(String name) {
byte[] attr = (byte[])map.get(name);
return attr != null ?
new DataInputStream(new ByteArrayInputStream(attr)) : null;
}
/**
* Returns an array containing the bytes in a specified attribute.
* If the attribute exists but doesn't have any length (such as
* the
|
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.