Source Code Cross Referenced for ByteArrayBlob.java in  » Database-Client » iSQL-Viewer » org » isqlviewer » sql » 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 » Database Client » iSQL Viewer » org.isqlviewer.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the Mozilla Public License
003:         * Version 1.1 (the "License"); you may not use this file except in
004:         * compliance with the License. You may obtain a copy of the License at
005:         * http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009:         * License for the specific language governing rights and limitations
010:         * under the License.
011:         * 
012:         * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013:         *
014:         * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015:         * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016:         *
017:         * Contributor(s): 
018:         *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019:         *  
020:         * If you didn't download this code from the following link, you should check
021:         * if you aren't using an obsolete version: http://www.isqlviewer.com
022:         */
023:        package org.isqlviewer.sql;
024:
025:        import java.io.ByteArrayInputStream;
026:        import java.io.ByteArrayOutputStream;
027:        import java.io.IOException;
028:        import java.io.InputStream;
029:        import java.io.OutputStream;
030:        import java.sql.Blob;
031:        import java.sql.SQLException;
032:
033:        import org.isqlviewer.util.BasicUtilities;
034:
035:        /**
036:         * Utility Implementation for dealing with BLOB objects in memory.
037:         * <p>
038:         * This is very easy implementation of a BLOB using the ByteArrayInputStream. This class is designed for easily creating
039:         * BLOB objects at runtime using a byte array.
040:         * 
041:         * @see java.io.ByteArrayInputStream
042:         * @author Markus A. Kobold &lt;mkobold at sprintpcs dot com&gt;
043:         */
044:        public class ByteArrayBlob implements  Blob {
045:
046:            protected ByteArrayOutputStream blob = new ByteArrayOutputStream();
047:
048:            public ByteArrayBlob() {
049:
050:            }
051:
052:            public ByteArrayBlob(byte[] data) throws IOException {
053:
054:                blob.write(data);
055:            }
056:
057:            /**
058:             * @param binaryStream
059:             */
060:            public ByteArrayBlob(InputStream binaryStream) throws IOException {
061:
062:                BasicUtilities.copyStream(binaryStream, blob);
063:            }
064:
065:            public long length() {
066:
067:                return blob.size();
068:            }
069:
070:            public byte[] getBytes(long pos, int length) throws SQLException {
071:
072:                try {
073:                    byte[] copy = new byte[length];
074:                    System.arraycopy(blob.toByteArray(), (int) pos, copy, 0,
075:                            length);
076:                    return copy;
077:                } catch (Throwable t) {
078:                    throw new SQLException(t.getMessage());
079:                }
080:            }
081:
082:            public InputStream getBinaryStream() throws SQLException {
083:
084:                try {
085:                    return new ByteArrayInputStream(blob.toByteArray());
086:                } catch (Throwable t) {
087:                    throw new SQLException(t.getMessage());
088:                }
089:            }
090:
091:            public long position(byte[] pattern, long start)
092:                    throws SQLException {
093:
094:                try {
095:                    String s = new String(pattern);
096:                    String b = blob.toString();
097:                    return b.indexOf(s);
098:                } catch (Throwable t) {
099:                    throw new SQLException(t.getMessage());
100:                }
101:            }
102:
103:            public long position(Blob pattern, long start) throws SQLException {
104:
105:                return position(pattern.getBytes(0, (int) pattern.length()),
106:                        start);
107:            }
108:
109:            public void truncate(long length) throws SQLException {
110:
111:                try {
112:                    int len = (int) length;
113:                    byte[] copy = new byte[len];
114:                    System.arraycopy(blob.toByteArray(), 0, copy, 0, len);
115:                    blob.reset();
116:                    blob.write(copy);
117:                } catch (Throwable t) {
118:                    throw new SQLException(t.getMessage());
119:                }
120:            }
121:
122:            public OutputStream setBinaryStream(long pos) throws SQLException {
123:
124:                return blob;
125:            }
126:
127:            public int setBytes(long pos, byte[] bytes, int offset, int len)
128:                    throws SQLException {
129:
130:                try {
131:                    byte[] copy = blob.toByteArray();
132:                    System.arraycopy(blob.toByteArray(), 0, copy, 0, len);
133:                    blob.reset();
134:                    blob.write(copy);
135:                    return len;
136:                } catch (Throwable t) {
137:                    throw new SQLException(t.getMessage());
138:                }
139:            }
140:
141:            public int setBytes(long pos, byte[] bytes) throws SQLException {
142:
143:                return setBytes(pos, bytes, 0, bytes.length);
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.