Top Description Inners Fields Constructors Methods
javassist

public Class ByteArrayClassPath

extends Object
implements ClassPath
Class Inheritance
All Implemented Interfaces
javassist.ClassPath
Imports
java.io.ByteArrayInputStream, .IOException, .InputStream, java.net.MalformedURLException, .URL, .URLConnection, .URLStreamHandler

A ByteArrayClassPath contains bytes that is served as a class file to a ClassPool. It is useful to convert a byte array to a CtClass object.

For example, if you want to convert a byte array b into a CtClass object representing the class with a name classname, then do as following:

ClassPool cp = ClassPool.getDefault();
cp.insertClassPath(new ByteArrayClassPath(classname, b));
CtClass cc = cp.get(classname);

The ClassPool object cp uses the created ByteArrayClassPath object as the source of the class file.

A ByteArrayClassPath must be instantiated for every class. It contains only a single class file.

See Also
javassist.ClassPath, ClassPool#insertClassPath(ClassPath), ClassPool#appendClassPath(ClassPath), ClassPool#makeClass(InputStream)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
protected byte[]
protected String

Constructor Summary

AccessConstructor and Description
public
ByteArrayClassPath(String name, byte[] classfile)

Method Summary

Modifier and TypeMethod and Description
public URL
find(String
a fully-qualified class name.
classname
)

Implements javassist.ClassPath.find.

Obtains the URL.

public InputStream
openClassfile(String
a fully-qualified class name
classname
)

Implements javassist.ClassPath.openClassfile.

Opens the class file.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

classfileback to summary
protected byte[] classfile
classnameback to summary
protected String classname

Constructor Detail

ByteArrayClassPathback to summary
public ByteArrayClassPath(String name, byte[] classfile)

Method Detail

findback to summary
public URL find(String classname)

Implements javassist.ClassPath.find.

Obtains the URL.

Parameters
classname:String

Doc from javassist.ClassPath.find.

a fully-qualified class name.

Returns:URL

Doc from javassist.ClassPath.find.

null if the specified class file could not be found.

Annotations
@Override
openClassfileback to summary
public InputStream openClassfile(String classname)

Implements javassist.ClassPath.openClassfile.

Opens the class file.

Parameters
classname:String

Doc from javassist.ClassPath.openClassfile.

a fully-qualified class name

Returns:InputStream

Doc from javassist.ClassPath.openClassfile.

the input stream for reading a class file

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
javassist back to summary

private Class ByteArrayClassPath.BytecodeURLConnection

extends URLConnection
Class Inheritance

Field Summary

Inherited from java.net.URLConnection:
allowUserInteractionconnecteddoInputdoOutputifModifiedSinceurluseCaches

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
connect()

Implements abstract java.net.URLConnection.connect.

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

public int
getContentLength()

Overrides java.net.URLConnection.getContentLength.

Returns the value of the content-length header field.

public InputStream
getInputStream()

Overrides java.net.URLConnection.getInputStream.

Returns an input stream that reads from this open connection.

Inherited from java.net.URLConnection:
addRequestPropertygetAllowUserInteractiongetConnectTimeoutgetContentgetContentgetContentEncodinggetContentLengthLonggetContentTypegetDategetDefaultAllowUserInteractiongetDefaultRequestPropertygetDefaultUseCachesgetDefaultUseCachesgetDoInputgetDoOutputgetExpirationgetFileNameMapgetHeaderFieldgetHeaderFieldgetHeaderFieldDategetHeaderFieldIntgetHeaderFieldKeygetHeaderFieldLonggetHeaderFieldsgetIfModifiedSincegetLastModifiedgetOutputStreamgetPermissiongetReadTimeoutgetRequestPropertiesgetRequestPropertygetURLgetUseCachesguessContentTypeFromNameguessContentTypeFromStreamsetAllowUserInteractionsetConnectTimeoutsetContentHandlerFactorysetDefaultAllowUserInteractionsetDefaultRequestPropertysetDefaultUseCachessetDefaultUseCachessetDoInputsetDoOutputsetFileNameMapsetIfModifiedSincesetReadTimeoutsetRequestPropertysetUseCachestoString

Constructor Detail

BytecodeURLConnectionback to summary
protected BytecodeURLConnection(URL url)

Method Detail

connectback to summary
public void connect() throws IOException

Implements abstract java.net.URLConnection.connect.

Doc from java.net.URLConnection.connect.

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

If the connect method is called when the connection has already been opened (indicated by the connected field having the value true), the call is ignored.

URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.

Exceptions
IOException:
if an I/O error occurs while opening the connection.
getContentLengthback to summary
public int getContentLength()

Overrides java.net.URLConnection.getContentLength.

Doc from java.net.URLConnection.getContentLength.

Returns the value of the content-length header field.

Note

getContentLengthLong() should be preferred over this method, since it returns a long instead and is therefore more portable.

Returns:int

the content length of the resource that this connection's URL references, -1 if the content length is not known, or if the content length is greater than Integer.MAX_VALUE.

getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides java.net.URLConnection.getInputStream.

Doc from java.net.URLConnection.getInputStream.

Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.

Returns:InputStream

an input stream that reads from this open connection.

Exceptions
IOException:
if an I/O error occurs while creating the input stream.
javassist back to summary

private Class ByteArrayClassPath.BytecodeURLStreamHandler

extends URLStreamHandler
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected URLConnection
openConnection(final URL
the URL that this connects to.
u
)

Implements abstract java.net.URLStreamHandler.openConnection.

Opens a connection to the object referenced by the URL argument.

Inherited from java.net.URLStreamHandler:
equalsgetDefaultPortgetHostAddresshashCodehostsEqualopenConnectionparseURLsameFilesetURLsetURLtoExternalForm

Constructor Detail

BytecodeURLStreamHandlerback to summary
private BytecodeURLStreamHandler()

Method Detail

openConnectionback to summary
protected URLConnection openConnection(final URL u)

Implements abstract java.net.URLStreamHandler.openConnection.

Doc from java.net.URLStreamHandler.openConnection.

Opens a connection to the object referenced by the URL argument. This method should be overridden by a subclass.

If for the handler's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned.

Parameters
u:URL

the URL that this connects to.

Returns:URLConnection

a URLConnection object for the URL.