ContentHandler
Stay organized with collections
Save and categorize content based on your preferences.
The abstract class ContentHandler
is the superclass
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 setContentHandler
) is
called with a String
giving the MIME 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.
If no content handler could be found, URLConnection will
look for a content handler in a user-defineable set of places.
By default it looks in sun.net.www.content, but users can define a
vertical-bar delimited set of class prefixes to search through in
addition by defining the java.content.handler.pkgs property.
The class name must be of the form:
{package-prefix}.{major}.{minor}
e.g.
YoyoDyne.experimental.text.plain
If the loading of the content handler class would be performed by
a classloader that is outside of the delegation chain of the caller,
the JVM will need the RuntimePermission "getClassLoader".
Public Constructor Summary
Public Method Summary
abstract
Object
|
getContent( URLConnection urlc)
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.
|
Object
|
getContent( URLConnection urlc, Class[] classes)
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.
|
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Public Methods
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.
Returns
- the object read by the
ContentHandler
.
Throws
IOException |
if an I/O error occurs while reading the object.
|
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()
and screen the return type for a match of the suggested types.
Parameters
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.
null if none of the requested are supported.
Throws
IOException |
if an I/O error occurs while reading the object. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eContentHandler\u003c/code\u003e is an abstract class used to read an \u003ccode\u003eObject\u003c/code\u003e from a \u003ccode\u003eURLConnection\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt's primarily invoked indirectly via \u003ccode\u003eURL.getContent()\u003c/code\u003e or \u003ccode\u003eURLConnection.getContent()\u003c/code\u003e, not directly.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eContentHandlerFactory\u003c/code\u003e helps locate the appropriate \u003ccode\u003eContentHandler\u003c/code\u003e subclass based on the MIME type.\u003c/p\u003e\n"],["\u003cp\u003eUsers can customize content handler search locations using the \u003ccode\u003ejava.content.handler.pkgs\u003c/code\u003e property.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetContent\u003c/code\u003e method reads a URL connection stream and creates an object from it.\u003c/p\u003e\n"]]],["`ContentHandler` is an abstract class handling object retrieval from a `URLConnection`. Applications use `URL` or `URLConnection`'s `getContent`, which triggers a `ContentHandlerFactory` to provide a `ContentHandler` based on the MIME type. If none is found, it searches user-defined locations. The `getContent` method in the handler reads the stream and creates an object or checks for the type requested. Users can define search by setting `java.content.handler.pkgs`.\n"],null,["# ContentHandler\n\npublic abstract class **ContentHandler** extends [Object](../../../reference/java/lang/Object.html) \nThe abstract class `ContentHandler` is the superclass\nof all classes that read an `Object` from a\n`URLConnection`.\n\n\nAn application does not generally call the\n`getContent` method in this class directly. Instead, an\napplication calls the `getContent` method in class\n`URL` or in `URLConnection`.\nThe application's content handler factory (an instance of a class that\nimplements the interface `ContentHandlerFactory` set\nup by a call to `setContentHandler`) is\ncalled with a `String` giving the MIME type of the\nobject being received on the socket. The factory returns an\ninstance of a subclass of `ContentHandler`, and its\n`getContent` method is called to create the object.\n\n\nIf no content handler could be found, URLConnection will\nlook for a content handler in a user-defineable set of places.\nBy default it looks in sun.net.www.content, but users can define a\nvertical-bar delimited set of class prefixes to search through in\naddition by defining the java.content.handler.pkgs property.\nThe class name must be of the form: \n\n```\n {package-prefix}.{major}.{minor}\n e.g.\n YoyoDyne.experimental.text.plain\n \n```\nIf the loading of the content handler class would be performed by a classloader that is outside of the delegation chain of the caller, the JVM will need the RuntimePermission \"getClassLoader\".\n\n\u003cbr /\u003e\n\n##### See Also\n\n- [getContent(java.net.URLConnection)](../../../reference/java/net/ContentHandler.html#getContent(java.net.URLConnection))\n- [ContentHandlerFactory](../../../reference/java/net/ContentHandlerFactory.html)\n- [URL.getContent()](../../../reference/java/net/URL.html#getContent())\n- [URLConnection](../../../reference/java/net/URLConnection.html)\n- [URLConnection.getContent()](../../../reference/java/net/URLConnection.html#getContent())\n- [URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)](../../../reference/java/net/URLConnection.html#setContentHandlerFactory(java.net.ContentHandlerFactory)) \n\n### Public Constructor Summary\n\n|---|--------------------------------------------------------------------------------------|\n| | [ContentHandler](../../../reference/java/net/ContentHandler.html#ContentHandler())() |\n\n### Public Method Summary\n\n|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Object](../../../reference/java/lang/Object.html) | [getContent](../../../reference/java/net/ContentHandler.html#getContent(java.net.URLConnection))([URLConnection](../../../reference/java/net/URLConnection.html) urlc) 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. |\n| [Object](../../../reference/java/lang/Object.html) | [getContent](../../../reference/java/net/ContentHandler.html#getContent(java.net.URLConnection,%20java.lang.Class[]))([URLConnection](../../../reference/java/net/URLConnection.html) urlc, [Class\\[\\]](../../../reference/java/lang/Class.html) classes) 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. |\n\n### Inherited Method Summary\n\nFrom class [java.lang.Object](../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../reference/java/lang/Object.html) | [clone](../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../reference/java/lang/String.html) | [toString](../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nPublic Constructors\n-------------------\n\n#### public\n**ContentHandler**\n()\n\n\u003cbr /\u003e\n\nPublic Methods\n--------------\n\n#### public abstract [Object](../../../reference/java/lang/Object.html)\n**getContent**\n([URLConnection](../../../reference/java/net/URLConnection.html) urlc)\n\nGiven a URL connect stream positioned at the beginning of the\nrepresentation of an object, this method reads that stream and\ncreates an object from it. \n\n##### Parameters\n\n| urlc | a URL connection. |\n|------|-------------------|\n\n##### Returns\n\n- the object read by the `ContentHandler`. \n\n##### Throws\n\n| [IOException](../../../reference/java/io/IOException.html) | if an I/O error occurs while reading the object. |\n|------------------------------------------------------------|--------------------------------------------------|\n\n#### public [Object](../../../reference/java/lang/Object.html)\n**getContent**\n([URLConnection](../../../reference/java/net/URLConnection.html) urlc, [Class\\[\\]](../../../reference/java/lang/Class.html) classes)\n\nGiven a URL connect stream positioned at the beginning of the\nrepresentation of an object, this method reads that stream and\ncreates an object that matches one of the types specified.\n\nThe default implementation of this method should call getContent()\nand screen the return type for a match of the suggested types. \n\n##### Parameters\n\n| urlc | a URL connection. |\n| classes | an array of types requested |\n|---------|-----------------------------|\n\n##### Returns\n\n- the object read by the `ContentHandler` that is the first match of the suggested types. null if none of the requested are supported. \n\n##### Throws\n\n| [IOException](../../../reference/java/io/IOException.html) | if an I/O error occurs while reading the object. |\n|------------------------------------------------------------|--------------------------------------------------|"]]