KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > lob > BlobImpl


1 //$Id: BlobImpl.java,v 1.2 2004/12/18 18:46:02 oneovthafew Exp $
2
package org.hibernate.lob;
3
4 import java.io.ByteArrayInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7 import java.io.OutputStream JavaDoc;
8 import java.sql.Blob JavaDoc;
9 import java.sql.SQLException JavaDoc;
10
11 /**
12  * A dummy implementation of <tt>java.sql.Blob</tt> that
13  * may be used to insert new data into a BLOB.
14  * @author Gavin King
15  */

16 public class BlobImpl implements Blob JavaDoc {
17
18     private InputStream JavaDoc stream;
19     private int length;
20     private boolean needsReset = false;
21
22     public BlobImpl(byte[] bytes) {
23         this.stream = new ByteArrayInputStream JavaDoc(bytes);
24         this.length = bytes.length;
25     }
26
27     public BlobImpl(InputStream JavaDoc stream, int length) {
28         this.stream = stream;
29         this.length = length;
30     }
31
32     /**
33      * @see java.sql.Blob#length()
34      */

35     public long length() throws SQLException JavaDoc {
36         return length;
37     }
38
39     /**
40      * @see java.sql.Blob#truncate(long)
41      */

42     public void truncate(long pos) throws SQLException JavaDoc {
43         excep();
44     }
45
46     /**
47      * @see java.sql.Blob#getBytes(long, int)
48      */

49     public byte[] getBytes(long pos, int len) throws SQLException JavaDoc {
50         excep(); return null;
51     }
52
53     /**
54      * @see java.sql.Blob#setBytes(long, byte[])
55      */

56     public int setBytes(long pos, byte[] bytes) throws SQLException JavaDoc {
57         excep(); return 0;
58     }
59
60     /**
61      * @see java.sql.Blob#setBytes(long, byte[], int, int)
62      */

63     public int setBytes(long pos, byte[] bytes, int i, int j)
64     throws SQLException JavaDoc {
65         excep(); return 0;
66     }
67
68     /**
69      * @see java.sql.Blob#position(byte[], long)
70      */

71     public long position(byte[] bytes, long pos) throws SQLException JavaDoc {
72         excep(); return 0;
73     }
74
75     /**
76      * @see java.sql.Blob#getBinaryStream()
77      */

78     public InputStream JavaDoc getBinaryStream() throws SQLException JavaDoc {
79         try {
80             if (needsReset) stream.reset();
81         }
82         catch (IOException JavaDoc ioe) {
83             throw new SQLException JavaDoc("could not reset reader");
84         }
85         needsReset = true;
86         return stream;
87     }
88
89     /**
90      * @see java.sql.Blob#setBinaryStream(long)
91      */

92     public OutputStream JavaDoc setBinaryStream(long pos) throws SQLException JavaDoc {
93         excep(); return null;
94     }
95
96     /**
97      * @see java.sql.Blob#position(Blob, long)
98      */

99     public long position(Blob JavaDoc blob, long pos) throws SQLException JavaDoc {
100         excep(); return 0;
101     }
102
103     private static void excep() {
104         throw new UnsupportedOperationException JavaDoc("Blob may not be manipulated from creating session");
105     }
106
107 }
108
109
110
111
112
113
114
Popular Tags