Source Code Cross Referenced for ByteArrayDataSource.java in  » Groupware » hipergate » com » knowgate » dfs » 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 » Groupware » hipergate » com.knowgate.dfs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.knowgate.dfs;
002:
003:        /*
004:         * @(#)ByteArrayDataSource.java	1.4 01/05/23
005:         *
006:         * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * - Redistributions of source code must retain the above copyright
013:         *   notice, this list of conditions and the following disclaimer.
014:         *
015:         * - Redistribution in binary form must reproduce the above copyright
016:         *   notice, this list of conditions and the following disclaimer in the
017:         *   documentation and/or other materials provided with the distribution.
018:         *
019:         * Neither the name of Sun Microsystems, Inc. or the names of contributors
020:         * may be used to endorse or promote products derived from this software
021:         * without specific prior written permission.
022:         *
023:         * This software is provided "AS IS," without a warranty of any kind. ALL
024:         * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
025:         * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
026:         * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
027:         * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES OR LIABILITIES
028:         * SUFFERED BY LICENSEE AS A RESULT OF  OR RELATING TO USE, MODIFICATION
029:         * OR DISTRIBUTION OF THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
030:         * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
031:         * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
032:         * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
033:         * ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS
034:         * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
035:         *
036:         * You acknowledge that Software is not designed, licensed or intended
037:         * for use in the design, construction, operation or maintenance of any
038:         * nuclear facility.
039:         */
040:
041:        import java.io.*;
042:        import javax.activation.*;
043:
044:        /**
045:         * A simple DataSource for demonstration purposes.
046:         * This class implements a DataSource from:
047:         * 	an InputStream
048:         *	a byte array
049:         * 	a String
050:         *
051:         * @author John Mani
052:         * @author Bill Shannon
053:         * @author Max Spivak
054:         */
055:        public class ByteArrayDataSource implements  DataSource {
056:            private byte[] data; // data
057:            private String type; // content-type
058:
059:            /* Create a DataSource from an input stream */
060:            public ByteArrayDataSource(InputStream is, String type) {
061:                this .type = type;
062:                try {
063:                    ByteArrayOutputStream os = new ByteArrayOutputStream();
064:                    int ch;
065:
066:                    while ((ch = is.read()) != -1)
067:                        // XXX - must be made more efficient by
068:                        // doing buffered reads, rather than one byte reads
069:                        os.write(ch);
070:                    data = os.toByteArray();
071:
072:                } catch (IOException ioex) {
073:                }
074:            }
075:
076:            /* Create a DataSource from a byte array */
077:            public ByteArrayDataSource(byte[] data, String type) {
078:                this .data = data;
079:                this .type = type;
080:            }
081:
082:            /* Create a DataSource from a String */
083:            public ByteArrayDataSource(String data, String type) {
084:                try {
085:                    // Assumption that the string contains only ASCII
086:                    // characters!  Otherwise just pass a charset into this
087:                    // constructor and use it in getBytes()
088:                    this .data = data.getBytes("iso-8859-1");
089:                } catch (UnsupportedEncodingException uex) {
090:                }
091:                this .type = type;
092:            }
093:
094:            /**
095:             * Return an InputStream for the data.
096:             * Note - a new stream must be returned each time.
097:             */
098:            public InputStream getInputStream() throws IOException {
099:                if (data == null)
100:                    throw new IOException("no data");
101:                return new ByteArrayInputStream(data);
102:            }
103:
104:            public OutputStream getOutputStream() throws IOException {
105:                throw new IOException("cannot do this");
106:            }
107:
108:            public String getContentType() {
109:                return type;
110:            }
111:
112:            public String getName() {
113:                return "dummy";
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.