KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > http > FavIconHandler


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.manager.http;
21
22 import com.sun.image.codec.jpeg.JPEGCodec;
23 import com.sun.image.codec.jpeg.JPEGEncodeParam;
24 import com.sun.image.codec.jpeg.JPEGImageEncoder;
25
26 import java.awt.Graphics JavaDoc;
27 import java.awt.image.BufferedImage JavaDoc;
28 import java.io.BufferedInputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.io.UnsupportedEncodingException JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.apache.excalibur.instrument.manager.http.server.AbstractHTTPURLHandler;
35 import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect;
36 import org.apache.excalibur.instrument.manager.http.server.URLCoder;
37 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
38 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor;
39 import org.apache.excalibur.instrument.manager.InstrumentSampleSnapshot;
40 import org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException;
41
42 /**
43  * Serves up a favicon.ico file.
44  *
45  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
46  * @version CVS $Revision: 1.9 $ $Date: 2004/03/06 14:01:28 $
47  * @since 4.1
48  */

49 public class FavIconHandler
50     extends AbstractHTTPURLHandler
51 {
52     /*---------------------------------------------------------------
53      * Constructors
54      *-------------------------------------------------------------*/

55     /**
56      * Creates a new FavIconHandler.
57      */

58     public FavIconHandler()
59     {
60         super( "/favicon.ico", CONTENT_TYPE_IMAGE_X_ICON,
61             InstrumentManagerHTTPConnector.ENCODING );
62     }
63     
64     /*---------------------------------------------------------------
65      * AbstractHandler Methods
66      *-------------------------------------------------------------*/

67     /**
68      * Handles the specified request.
69      *
70      * @param The full path being handled.
71      * @param parameters A Map of the parameters in the request.
72      * @param os The OutputStream to write the result to.
73      */

74     public void doGet( String JavaDoc path, Map JavaDoc parameters, OutputStream JavaDoc os )
75         throws IOException JavaDoc
76     {
77         String JavaDoc imageResource = "favicon.ico";
78         BufferedInputStream JavaDoc is =
79             new BufferedInputStream JavaDoc( getClass().getResourceAsStream( imageResource ) );
80         byte[] favIcon;
81         try {
82             favIcon = new byte[is.available()];
83             is.read( favIcon, 0, favIcon.length );
84         } finally {
85             is.close();
86         }
87         // Now write the image out to the client.
88
os.write( favIcon );
89     }
90 }
91
92
Popular Tags