01: package ru.emdev.EmForge.util;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.InputStream;
05: import java.io.OutputStream;
06: import java.sql.Blob;
07: import java.sql.SQLException;
08:
09: /** Own implementation of Blob, since Hibernate's provided Blob does not supported even simple getBytes
10: *
11: *
12: */
13: public class BlobImpl implements Blob {
14: private byte[] bytes;
15:
16: public BlobImpl(byte[] bytes) {
17: this .bytes = bytes;
18: }
19:
20: public void free() throws SQLException {
21: bytes = null;
22:
23: }
24:
25: public InputStream getBinaryStream() throws SQLException {
26: return new ByteArrayInputStream(bytes);
27: }
28:
29: public InputStream getBinaryStream(long i_pos, long i_length)
30: throws SQLException {
31: return new ByteArrayInputStream(getBytes(i_pos, Long.valueOf(
32: i_length).intValue()));
33: }
34:
35: public byte[] getBytes(long i_pos, int i_length)
36: throws SQLException {
37: byte[] subArray = new byte[i_length];
38: System.arraycopy(bytes, Long.valueOf(i_pos - 1).intValue(),
39: subArray, 0, i_length);
40: return subArray;
41: }
42:
43: public long length() throws SQLException {
44: return bytes.length;
45: }
46:
47: public long position(byte[] i_pattern, long i_start)
48: throws SQLException {
49: throw new SQLException("position operation is no supported yet");
50: }
51:
52: public long position(Blob i_pattern, long i_start)
53: throws SQLException {
54: throw new SQLException("position operation is no supported yet");
55: }
56:
57: public OutputStream setBinaryStream(long i_pos) throws SQLException {
58: throw new SQLException("position operation is no supported yet");
59: }
60:
61: public int setBytes(long i_pos, byte[] i_bytes) throws SQLException {
62: throw new SQLException("position operation is no supported yet");
63: }
64:
65: public int setBytes(long i_pos, byte[] i_bytes, int i_offset,
66: int i_len) throws SQLException {
67: throw new SQLException("position operation is no supported yet");
68: }
69:
70: public void truncate(long i_len) throws SQLException {
71: throw new SQLException("position operation is no supported yet");
72: }
73: }
|