Reading Javadocs from inside the original zip file
2 Comments Published November 19th, 2006 in Java Tags: .JDK 1.5 Javadocs zip file is 45MB compressed, and 235MB uncompressed. If you’d like to browse its content without uncompress it, you can use following servlet:
1public class JavadocSampleServlet extends HttpServlet { 2 private static final String JAVADOC_LOCATION = 3 "D:/Java/docs/jdk-1_5_0-doc.zip"; 4 protected void doGet(HttpServletRequest req, HttpServletResponse res) 5 throws ServletException, IOException { 6 String resource = req.getPathInfo(); 7 if (resource == null || "/".equals(resource)) 8 resource = "/index.html"; 9 URL url = new URL("jar:file:///" + JAVADOC_LOCATION + 10 "!/docs" + resource); 11 URLConnection conn = url.openConnection(); 12 InputStream input = null; 13 OutputStream output = null; 14 try { 15 input = conn.getInputStream(); 16 output = res.getOutputStream(); 17 int c; 18 while ((c = input.read()) != -1) output.write(c); 19 output.flush(); 20 } finally { 21 if (input != null) input.close(); 22 if (output != null) output.close(); 23 } 24 } 25}
Set up the constant JAVADOC_LOCATION with proper javadoc file path on your disk.
Here’s the servlet mapping:
1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 3<web-app> 4 <servlet> 5 <servlet-name>javadoc</servlet-name> 6 <servlet-class> 7 it.newinstance.sample.JavadocSampleServlet 8 </servlet-class> 9 </servlet> 10 <servlet-mapping> 11 <servlet-name>javadoc</servlet-name> 12 <url-pattern>/javadoc/*</url-pattern> 13 </servlet-mapping> 14</web-app>
Configure it in your tomcat and go for the URL:
http://localhost:8080/${yourContextName}/javadoc/
and enjoy.
You’ve saved 190MB of disk space ;-)
Notice the new feature of colored sources on my blog: I used this post to test if it works correctly. This weekend I wrote my parser to convert java sources to html. Seems good, isn’t that?
Search
Calendar
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Oct | Dec » | |||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
Archives
Categories
Tag Cloud
Android API Bash Bios CSS Development Eclipse Encription Error Handling Font Git Google GWT Hardware How-To HTML Installation iPod Java JavaScript Karmic Linux Lucks MacBook Open Source Opinion OSX Pitfalls Pkg Practices Python Resume Security Software Suspend TDD Testing Tools Top Down Tricks Ubuntu Uninstall Wakup On Lan Web Workaround
WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.
Blog License
Blogs I like
Books on the desk
Friends' Blogs
- Antonio Terreno & Valter Bernardini
- Bruno Bossola
- Daniele Galluccio
- Domenico Ventura
- Ed Schepis
- Fabrizio Gianneschi
- Luca Grulla
- Luigi Zanderighi
- Marcello Teodori
- Mida Boghetich
- Muralidharan Chandrasekaran
- Piero Ricca
- Renzo Borgatti
- Simone Bordet
- Simone Bruno
- Uberto Barbini
- Valvolog
- Webtide blogs (Greg Wilkins & Jan Bartel)
Links





















Or you could try ClassFinder.
It is open source and serves docs and source (and on-the-fly decompiles) with a very small code base.
It has been developed a couple of years ago, but I still haven’t found anything to beat it.
Perché non facciamo un sito per il browse di codice sorgente?????