Source Code Cross Referenced for MultipartDataSource.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » 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 » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2001 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        /**
007:         * Wrapper class to make com.oreilly.servlet.multipart.FilePart object
008:         * available as a DataSource.
009:         *
010:         * We have to buffer the data stream since the MimePart class will try to
011:         * read the stream several times (??) and we can't rewind the HttpRequest stream.
012:         * <p>
013:         * <b>Note</b>: The clients of this class must explictly call <code>dispose()</code> 
014:         * method to release temp files associated with this object.
015:         * </p>
016:         * 
017:         * @author George Lindholm, ITServices, UBC
018:         * @version $Revision: 35756 $
019:         */package org.jasig.portal;
020:
021:        import java.io.ByteArrayOutputStream;
022:        import java.io.ByteArrayInputStream;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.OutputStream;
026:        import java.io.FileOutputStream;
027:        import java.io.BufferedOutputStream;
028:        import java.io.FileInputStream;
029:        import java.io.BufferedInputStream;
030:        import javax.activation.DataSource;
031:        import com.oreilly.servlet.multipart.FilePart;
032:
033:        import org.apache.commons.logging.Log;
034:        import org.apache.commons.logging.LogFactory;
035:
036:        public class MultipartDataSource implements  DataSource {
037:
038:            private static final Log log = LogFactory
039:                    .getLog(MultipartDataSource.class);
040:
041:            java.io.File tempfile;
042:            ByteArrayOutputStream buff = null;
043:            String contentType = null;
044:            String filename = null;
045:            String errorMessage = null;
046:            boolean isAvailable = false;
047:
048:            public MultipartDataSource(FilePart filePart) throws IOException {
049:                contentType = filePart.getContentType();
050:                filename = filePart.getFileName();
051:                try {
052:                    tempfile = java.io.File.createTempFile("uPdata", null);
053:                    tempfile.deleteOnExit();
054:                    OutputStream out = new BufferedOutputStream(
055:                            new FileOutputStream(tempfile));
056:                    filePart.writeTo(out);
057:                    out.close();
058:                } catch (IOException ioe) {
059:                    log.error("MultipartDataSource unable to create temp file",
060:                            ioe);
061:                    if (tempfile != null) {
062:                        try {
063:                            tempfile.delete();
064:                        } catch (Exception e) {
065:                        }
066:                        tempfile = null;
067:                    }
068:                    buff = new ByteArrayOutputStream();
069:                    filePart.writeTo(buff);
070:                }
071:                this .isAvailable = true;
072:            }
073:
074:            public MultipartDataSource(String fileName, String errorMessage) {
075:                this .filename = fileName;
076:                this .errorMessage = errorMessage;
077:                this .isAvailable = false;
078:            }
079:
080:            public boolean isAvailable() {
081:                return this .isAvailable;
082:            }
083:
084:            /**
085:             * Releases tempfile associated with this object any memory they consume
086:             * will be returned to the OS.
087:             * @since uPortal 2.5.  Prior to uPortal 2.5, tempfile deletion was a side effect
088:             * of the finalizer.
089:             */
090:            public void dispose() {
091:                buff = null;
092:                if (tempfile != null) {
093:                    boolean success = tempfile.delete();
094:                    if (!success) {
095:                        log.error("Unable to delete temp file ["
096:                                + tempfile.getPath() + "]");
097:                    }
098:
099:                    tempfile = null;
100:                }
101:            }
102:
103:            public InputStream getInputStream() throws IOException {
104:                if (!isAvailable())
105:                    throw new IOException(this .getErrorMessage());
106:
107:                if (tempfile != null) {
108:                    return new BufferedInputStream(
109:                            new FileInputStream(tempfile));
110:                } else {
111:                    return new ByteArrayInputStream(buff.toByteArray());
112:                }
113:            }
114:
115:            public OutputStream getOutputStream() throws IOException {
116:                throw new IOException("getOutputStream() not implemented");
117:            }
118:
119:            public String getContentType() {
120:                return contentType;
121:            }
122:
123:            public String getName() {
124:                return filename;
125:            }
126:
127:            public String getErrorMessage() {
128:                return errorMessage;
129:            }
130:
131:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.