Source Code Cross Referenced for ResourceAggregator.java in  » J2EE » hgcommons » biz » hammurapi » util » 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 » J2EE » hgcommons » biz.hammurapi.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * hgcommons 7
003:         * Hammurapi Group Common Library 
004:         * Copyright (C) 2003  Hammurapi Group
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
021:         * e-Mail: support@hammurapi.biz
022:         */
023:        package biz.hammurapi.util;
024:
025:        import java.io.BufferedReader;
026:        import java.io.ByteArrayInputStream;
027:        import java.io.ByteArrayOutputStream;
028:        import java.io.IOException;
029:        import java.io.InputStream;
030:        import java.io.InputStreamReader;
031:        import java.util.ArrayList;
032:        import java.util.Iterator;
033:        import java.util.List;
034:
035:        /**
036:         * Aggregates multiple classpath resources in one resource stream.
037:         * @author Pavel Vlasov
038:         * @revision $Revision$
039:         */
040:        public class ResourceAggregator {
041:            private List resourceList = new ArrayList();
042:
043:            /**
044:             * Adds resource to the list of resources to be aggregated. 
045:             * @param resourceName
046:             */
047:            public void addResource(String resourceName) {
048:                resourceList.add(resourceName);
049:            }
050:
051:            /**
052:             * Reads each line from 'resourceListName' resource and adds
053:             * to the list of resources to be aggregated.
054:             * Directive #include allows to include another resource
055:             * list. If line has # as its first non-blank character then this 
056:             * line is treated as comment line. 
057:             * @param resourceListName
058:             * @throws IOException 
059:             */
060:            public void addResourceList(String resourceListName)
061:                    throws IOException {
062:                InputStream resourceStream = getClass().getClassLoader()
063:                        .getResourceAsStream(resourceListName);
064:                if (resourceStream == null) {
065:                    throw new IOException("Script list resource not found: "
066:                            + resourceListName);
067:                }
068:
069:                BufferedReader br = new BufferedReader(new InputStreamReader(
070:                        resourceStream));
071:                String s;
072:                while ((s = br.readLine()) != null) {
073:                    String strim = s.trim();
074:                    if (strim.startsWith("#include")) {
075:                        addResourceList(strim.substring("#include".length())
076:                                .trim());
077:                    } else if (strim.length() > 0 && !strim.startsWith("#")) {
078:                        resourceList.add(strim);
079:                    }
080:                }
081:                br.close();
082:            }
083:
084:            /**
085:             * Aggregates all resources in one resource.
086:             * @return Aggregated input stream.
087:             * @throws IOException
088:             */
089:            public InputStream aggregate() throws IOException {
090:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
091:                Iterator it = resourceList.iterator();
092:                ClassLoader classLoader = getClass().getClassLoader();
093:                while (it.hasNext()) {
094:                    String resourceName = (String) it.next();
095:                    InputStream in = classLoader
096:                            .getResourceAsStream(resourceName);
097:                    if (in == null) {
098:                        throw new IOException("Resource not found: "
099:                                + resourceName);
100:                    }
101:                    byte[] buf = new byte[4096];
102:                    int l;
103:                    while ((l = in.read(buf)) != -1) {
104:                        baos.write(buf, 0, l);
105:                    }
106:                    in.close();
107:                }
108:                baos.close();
109:
110:                return new ByteArrayInputStream(baos.toByteArray());
111:            }
112:
113:            /**
114:             * Aggregates resource lists listed in command line arguments and outputs them to console. 
115:             * @param args
116:             */
117:            public static void main(String[] args) {
118:                try {
119:                    ResourceAggregator aggregator = new ResourceAggregator();
120:                    for (int i = 0; i < args.length; i++) {
121:                        aggregator.addResourceList(args[i]);
122:                    }
123:
124:                    BufferedReader br = new BufferedReader(
125:                            new InputStreamReader(aggregator.aggregate()));
126:                    String line;
127:                    while ((line = br.readLine()) != null) {
128:                        System.out.println(line);
129:                    }
130:                } catch (IOException e) {
131:                    System.err.println("ERROR: " + e.getMessage());
132:                    System.exit(1);
133:                }
134:
135:            }
136:
137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.