01: //$Id: SerializableBlob.java 5986 2005-03-02 11:43:36Z oneovthafew $
02: package org.hibernate.lob;
03:
04: import java.io.InputStream;
05: import java.io.OutputStream;
06: import java.io.Serializable;
07: import java.sql.Blob;
08: import java.sql.SQLException;
09:
10: /**
11: * @author Gavin King
12: */
13: public class SerializableBlob implements Serializable, Blob {
14:
15: private transient final Blob blob;
16:
17: public SerializableBlob(Blob blob) {
18: this .blob = blob;
19: }
20:
21: public Blob getWrappedBlob() {
22: if (blob == null) {
23: throw new IllegalStateException(
24: "Blobs may not be accessed after serialization");
25: } else {
26: return blob;
27: }
28: }
29:
30: public long length() throws SQLException {
31: return getWrappedBlob().length();
32: }
33:
34: public byte[] getBytes(long pos, int length) throws SQLException {
35: return getWrappedBlob().getBytes(pos, length);
36: }
37:
38: public InputStream getBinaryStream() throws SQLException {
39: return getWrappedBlob().getBinaryStream();
40: }
41:
42: public long position(byte[] pattern, long start)
43: throws SQLException {
44: return getWrappedBlob().position(pattern, start);
45: }
46:
47: public long position(Blob pattern, long start) throws SQLException {
48: return getWrappedBlob().position(pattern, start);
49: }
50:
51: public int setBytes(long pos, byte[] bytes) throws SQLException {
52: return getWrappedBlob().setBytes(pos, bytes);
53: }
54:
55: public int setBytes(long pos, byte[] bytes, int offset, int len)
56: throws SQLException {
57: return getWrappedBlob().setBytes(pos, bytes, offset, len);
58: }
59:
60: public OutputStream setBinaryStream(long pos) throws SQLException {
61: return getWrappedBlob().setBinaryStream(pos);
62: }
63:
64: public void truncate(long len) throws SQLException {
65: getWrappedBlob().truncate(len);
66: }
67:
68: }
|