import java.io.*;
import java.net.*;
import javax.swing.ImageIcon;


/**
 * A factory that constructs ImageContentHandler objects
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class ImageContentHandler extends ContentHandler
{

    /**
     * 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.
     *
     * @param connection           The URLConnection to read from
     */
    public Object getContent(URLConnection connection) throws IOException
    {
       byte[]             data; 
       ImageIcon          icon; 
       InputStream        is; 
       int                length;
       

       icon = null;
       
       is = connection.getInputStream();
       length = connection.getContentLength();
       data = new byte[length];
       is.read(data);
       icon = new ImageIcon(data);

       return icon;
    }
    

}
