Java Code Examples for java.net.ContentHandler

Following code examples demonstrate how to use java.net.ContentHandlerfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.net.ContentHandlerand various code implementation of this class.

    public static void loadService() {
        ServiceLoader<ContentHandler> loader = ServiceLoader.load(ContentHandler.class);
loader.forEach(System.err::println);
        StringBuilder packages = new StringBuilder(System.getProperty("java.content.handler.pkgs", ""));
System.err.println("java.content.handler.pkgs: before: " + packages);
        for (ContentHandler handler : loader) {
            String packageName = handler.getClass().getPackage().getName();
            String superPackageName = packageName.substring(0, packageName.lastIndexOf('.'));
            if (packages.indexOf(superPackageName) < 0) {
                if (packages.length() != 0) {
                    packages.append('|');
                }
                packages.append(superPackageName);
            }
        }
System.err.println("java.content.handler.pkgs: after: " + packages);
        System.setProperty("java.content.handler.pkgs", packages.toString());
    } 


    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to ContentHandler.class!",
                   ContentHandler.class.isAssignableFrom(sut));
    } 

Advertisement
Javadoc
The abstract class ContentHandler is the superclass of all classes that read an Object from a URLCon

nection.

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". @author James Gosling @see java.net.ContentHandler#getContent(java.net.URLConnection) @see java.net.ContentHandlerFactory @see java.net.URL#getContent() @see java.net.URLConnection @see java.net.URLConnection#getContent() @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory) @since JDK1.0

Read More
Advertisement