Java Reference
In-Depth Information
/* StreamKey stuff - new in JDK1.4 */
Map < String , InputStream > streamMap = new
new HashMap <>();
/** Associate the stream with the key. */
public
public void
void setStream ( String key , InputStream stream ) throws
throws IOException {
streamMap . put ( key , stream );
}
public
public InputStream getStream ( String key ) {
return
return ( InputStream ) streamMap . get ( key );
}
public
public Iterator < String > getStreamKeys () {
return
return streamMap . keySet (). iterator ();
}
}
It is left as an exercise for the reader to implement getImage() and other methods in terms
of other recipes used in this topic.
See Also
We have not investigated all the ins and outs of reflection or the ClassLoader mechanism,
but by now you should have a basic idea of how it works.
Perhaps the most important omissions are SecurityManager and ProtectionDomain . Only
one SecurityManager can be installed in a given instance of the JVM (e.g., to prevent a ma-
licious applet from providing its own!). A browser, for example, provides a SecurityMan-
ager that is far more restrictive than the standard one. Writing such a SecurityManager is
left as an exercise for the reader—an important exercise for anyone planning to load classes
over the Internet! (For more information about security managers and the Java Security
APIs, see Java Security by Scott Oaks (O'Reilly). A ProtectionDomain can be provided
with a ClassLoader to specify all the permissions needed for the class to run.
I've also left unexplored many topics in the JVM; see the (somewhat dated) O'Reilly books
Java Virtual Machine and Java Language , or Sun/Oracle's Java Language Specification and
JVM Specification documents (both updated with new releases, and available online ) for a
lifetime of reading enjoyment and edification!
The Apache Software Foundation maintains a vast array of useful software packages that are
free to get and use. Source code is always available without charge from its website. Two
packages you might want to investigate include the Commons BeanUtils and the Byte Code
Search WWH ::




Custom Search