Source Code Cross Referenced for ZipLoader.java in  » Scripting » Nice » gnu » bytecode » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » Nice » gnu.bytecode 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 1997  Per M.A. Bothner.
002:        // This is free software;  for terms and warranty disclaimer see ./COPYING.
003:
004:        package gnu.bytecode;
005:
006:        /** Load classes from a Zip archive.
007:         * @author	Per Bothner
008:         */
009:
010:        public class ZipLoader extends ClassLoader {
011:            /** The zip archive from which we will load the classes.
012:             * The format of the archive is the same as classes.zip. */
013:            java.util.zip.ZipFile zar;
014:
015:            /** Number of classes managed by this loader. */
016:            int size;
017:
018:            /** name of ZipFile */
019:            private String zipname;
020:
021:            /* A list of pairs of (name, class) of already loaded classes. */
022:            private java.util.Vector loadedClasses;
023:
024:            public ZipLoader(String name) throws java.io.IOException {
025:                this .zipname = name;
026:                this .zar = new java.util.zip.ZipFile(name);
027:                size = 0;
028:                java.util.Enumeration e = this .zar.entries();
029:                while (e.hasMoreElements()) {
030:                    java.util.zip.ZipEntry ent = (java.util.zip.ZipEntry) e
031:                            .nextElement();
032:                    if (!ent.isDirectory())
033:                        size++;
034:                }
035:                loadedClasses = new java.util.Vector(size);
036:            }
037:
038:            public Class loadClass(String name, boolean resolve)
039:                    throws ClassNotFoundException {
040:                Class clas;
041:                int index = loadedClasses.indexOf(name);
042:                if (index >= 0)
043:                    clas = (Class) loadedClasses.elementAt(index + 1);
044:                else if (zar == null && loadedClasses.size() == 2 * size)
045:                    clas = Class.forName(name);
046:                else {
047:                    boolean reopened = false;
048:                    String member_name = name.replace('.', '/') + ".class";
049:                    if (this .zar == null) {
050:                        try {
051:                            this .zar = new java.util.zip.ZipFile(zipname);
052:                            reopened = true;
053:                        } catch (java.io.IOException ex) {
054:                            throw new ClassNotFoundException(
055:                                    "IOException while loading " + member_name
056:                                            + " from ziparchive \"" + name
057:                                            + "\": " + ex.toString());
058:                        }
059:                    }
060:                    java.util.zip.ZipEntry member = zar.getEntry(member_name);
061:                    if (member == null) {
062:                        if (reopened) {
063:                            try {
064:                                close();
065:                            } catch (java.io.IOException e) {
066:                                throw new RuntimeException("failed to close \""
067:                                        + zipname + "\"");
068:                            }
069:                        }
070:                        clas = Class.forName(name);
071:                    } else {
072:                        try {
073:                            int member_size = (int) member.getSize();
074:                            java.io.InputStream strm = zar
075:                                    .getInputStream(member);
076:                            byte[] bytes = new byte[member_size];
077:                            new java.io.DataInputStream(strm).readFully(bytes);
078:                            clas = defineClass(name, bytes, 0, member_size);
079:                            loadedClasses.addElement(name);
080:                            loadedClasses.addElement(clas);
081:                            if (2 * size == loadedClasses.size())
082:                                close();
083:                        } catch (java.io.IOException ex) {
084:                            throw new ClassNotFoundException(
085:                                    "IOException while loading " + member_name
086:                                            + " from ziparchive \"" + name
087:                                            + "\": " + ex.toString());
088:                        }
089:                    }
090:                }
091:
092:                if (resolve)
093:                    resolveClass(clas);
094:                return clas;
095:            }
096:
097:            /** Load all classes immediately from zip archive, close archive. */
098:            public void loadAllClasses() throws java.io.IOException {
099:                java.util.Enumeration e = this .zar.entries();
100:                while (e.hasMoreElements()) {
101:                    java.util.zip.ZipEntry member = (java.util.zip.ZipEntry) e
102:                            .nextElement();
103:                    String name = member.getName().replace('/', '.');
104:                    name = name.substring(0, name.length() - "/class".length());
105:                    int member_size = (int) member.getSize();
106:                    java.io.InputStream strm = zar.getInputStream(member);
107:                    byte[] bytes = new byte[member_size];
108:                    new java.io.DataInputStream(strm).readFully(bytes);
109:                    Class clas = defineClass(name, bytes, 0, member_size);
110:                    loadedClasses.addElement(name);
111:                    loadedClasses.addElement(clas);
112:                }
113:                close();
114:            }
115:
116:            /** Close the zip archive. loadClass will reopen if necessary. */
117:            public void close() throws java.io.IOException {
118:                if (zar != null)
119:                    zar.close();
120:                zar = null;
121:            }
122:
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.