ContentHandler in Java

java.net.ContentHandler

The abstract class ContentHandler is the super class of all classes that read an Object from a URLConnection.

An application does not generally call the getContent method in this class directly. Instead, an application calls the getContent method in class URL or in URLConnection.

The application's content handler factory (an instance of a class that implements the interface ContentHandlerFactory set up by a call to setContent HandlerFactory is called with a String giving theMIME type of the object being received on the socket. The factory returns an instance of a subclass of ContentHandler, and its getContent method is called to create the object.

Declaration

public abstract class ContentHandler {

    public abstract Object
getContent(URLConnection urlc) throws IOException;

    @SuppressWarnings("rawtypes")
    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
        Object obj = getContent(urlc);

        for (Class<?> c : classes) {
            if (c.isInstance(obj)) {
                return obj;
            }
        }
        return null;
    }
}

Methods

1. getContent(URLConnection urlc)

Object java.net.ContentHandler.getContent(URLConnection urlc) throws IOException

Given a URL connect stream positioned at the beginning of the representation of an object, this method reads that stream and creates an object from it.

Parameters: urlc a URL connection.Returns:the object read by the ContentHandler.

Throws:

IOException - if an I/O error occurs while reading the object.


2. getContent(URLConnection urlc, Class[] classes)

Object java.net.ContentHandler.getContent(URLConnection urlc, Class[] classes) throws IOException

Given a URL connect stream positioned at the beginning of the representation of an object, this method reads that stream and creates an object that matches one of the types specified. The default implementation of this method should call getContent(URLConnection)and screen the return type for a match  of the suggested types.

Parameters: Two parameters are required for this method.

urlc: a URL connection.

classes: an array of types requested.

Returns: the object read by the ContentHandler that is the first match of the suggested types or null if none of the requested are supported.

Throws:

IOException - if an I/O error occurs while reading the object.


Some other classes/interfaces of java.net

AuthenticatorThe class Authenticator represents an object that knows how to obtain authentication for a network connection.

BindExceptionSignals that an error occurred while attempting to bind a socket to a local address and port. 

CacheRequestRepresents channels for storing resources in the ResponseCache.

CacheResponseRepresent channels for retrieving resources from the ResponseCache.

ConnectExceptionSignals that an error occurred while attempting to connect a socket to a remote address and port.

ContentHandlerThe abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.

ContentHandlerFactoryThis interface defines a factory for content handlers. Implementing this interface should map a MIME type into an instance of ContentHandler.

CookieHandlerA CookieHandler object provides a callback mechanism to hook up an HTTP state management policy implementation into the HTTP protocol handler.

CookieManagerCookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. 

CookiePolicyCookiePolicy implementations decide which cookies should be accepted and which should be rejected.

CookieStoreA CookieStore object represents storage for cookies. Can store and retrieve cookies.

DatagramPacketThis class represents a datagram packet.

No comments:

Post a Comment