KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: SerializableBlob.java,v 1.1 2005/03/02 11:43:35 oneovthafew Exp $
2
package org.hibernate.lob;
3
4 import java.io.InputStream JavaDoc;
5 import java.io.OutputStream JavaDoc;
6 import java.io.Serializable JavaDoc;
7 import java.sql.Blob JavaDoc;
8 import java.sql.SQLException JavaDoc;
9
10 /**
11  * @author Gavin King
12  */

13 public class SerializableBlob implements Serializable JavaDoc, Blob JavaDoc {
14     
15     private transient final Blob JavaDoc blob;
16     
17     public SerializableBlob(Blob JavaDoc blob) {
18         this.blob = blob;
19     }
20
21     public Blob JavaDoc getWrappedBlob() {
22         if ( blob==null ) {
23             throw new IllegalStateException JavaDoc("Blobs may not be accessed after serialization");
24         }
25         else {
26             return blob;
27         }
28     }
29     
30     public long length() throws SQLException JavaDoc {
31         return getWrappedBlob().length();
32     }
33
34     public byte[] getBytes(long pos, int length) throws SQLException JavaDoc {
35         return getWrappedBlob().getBytes(pos, length);
36     }
37
38     public InputStream JavaDoc getBinaryStream() throws SQLException JavaDoc {
39         return getWrappedBlob().getBinaryStream();
40     }
41
42     public long position(byte[] pattern, long start) throws SQLException JavaDoc {
43         return getWrappedBlob().position(pattern, start);
44     }
45
46     public long position(Blob JavaDoc pattern, long start) throws SQLException JavaDoc {
47         return getWrappedBlob().position(pattern, start);
48     }
49
50     public int setBytes(long pos, byte[] bytes) throws SQLException JavaDoc {
51         return getWrappedBlob().setBytes(pos, bytes);
52     }
53
54     public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException JavaDoc {
55         return getWrappedBlob().setBytes(pos, bytes, offset, len);
56     }
57
58     public OutputStream JavaDoc setBinaryStream(long pos) throws SQLException JavaDoc {
59         return getWrappedBlob().setBinaryStream(pos);
60     }
61
62     public void truncate(long len) throws SQLException JavaDoc {
63         getWrappedBlob().truncate(len);
64     }
65
66 }
67
Popular Tags