01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.persistence.lobs;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.ByteArrayOutputStream;
22: import java.sql.Blob;
23: import java.sql.SQLException;
24:
25: public class BlobImpl implements Blob {
26:
27: public BlobImpl(byte[] bytes) {
28: this .bytes = bytes;
29: }
30:
31: public java.io.InputStream getBinaryStream() throws SQLException {
32:
33: return new ByteArrayInputStream(bytes);
34: }
35:
36: public byte[] getBytes(long position, int length)
37: throws SQLException {
38: byte[] answer = new byte[length];
39:
40: System
41: .arraycopy(bytes, (int) position, answer, 0,
42: bytes.length);
43: return answer;
44: }
45:
46: public long length() throws java.sql.SQLException {
47:
48: return bytes.length;
49: }
50:
51: public long position(Blob clob, long start)
52: throws java.sql.SQLException {
53:
54: // we only use this to set clob values, so just return -1
55: return -1L;
56: }
57:
58: public long position(byte[] pattern, long start)
59: throws java.sql.SQLException {
60:
61: // we only use this to set clob values, so just return -1
62: return -1L;
63: }
64:
65: // do nothing sensible, just to support JDBC 3.0 interface included in J2SE
66: // 1.4
67: public int setBytes(long pos, byte[] bytes) {
68: return -1;
69: }
70:
71: // do nothing sensible, just to support JDBC 3.0 interface included in J2SE
72: // 1.4
73: public int setBytes(long pos, byte[] bytes, int offset, int len) {
74: return -1;
75: }
76:
77: // do nothing sensible, just to support JDBC 3.0 interface included in J2SE
78: // 1.4
79: public java.io.OutputStream setBinaryStream(long pos) {
80: return new ByteArrayOutputStream();
81: }
82:
83: // do nothing sensible, just to support JDBC 3.0 interface included in J2SE
84: // 1.4
85: public void truncate(long len) {
86: }
87:
88: private byte[] bytes;
89: }
|