01: // $Id: BytesBlob.java 7 2007-08-17 19:32:18Z jcamaia $
02:
03: package net.sf.persist.tests.framework;
04:
05: import java.io.ByteArrayInputStream;
06: import java.io.InputStream;
07: import java.io.OutputStream;
08: import java.sql.Blob;
09: import java.sql.SQLException;
10:
11: /**
12: * Blob implementation backed by a byte array, suitable for sending data to the database only
13: * (does not implement mutable methods)
14: */
15: public class BytesBlob implements Blob {
16:
17: byte[] b;
18:
19: public BytesBlob(byte[] b) {
20: super ();
21: this .b = b;
22: }
23:
24: public InputStream getBinaryStream() throws SQLException {
25: return new ByteArrayInputStream(b);
26: }
27:
28: public byte[] getBytes(long pos, int length) throws SQLException {
29: byte[] ret = new byte[length];
30: for (int i = (int) pos - 1; i < pos + length - 1; i++)
31: ret[i] = b[i + (int) pos - 1];
32: return ret;
33: }
34:
35: public long length() throws SQLException {
36: return b.length;
37: }
38:
39: public long position(byte[] pattern, long start)
40: throws SQLException {
41: throw new RuntimeException(
42: "position(byte[],long) not implemented");
43: }
44:
45: public long position(Blob pattern, long start) throws SQLException {
46: throw new RuntimeException(
47: "position(Blob,long) not implemented");
48: }
49:
50: public OutputStream setBinaryStream(long pos) throws SQLException {
51: throw new RuntimeException(
52: "setBinaryStream(long) not implemented");
53: }
54:
55: public int setBytes(long pos, byte[] bytes) throws SQLException {
56: throw new RuntimeException(
57: "setBytes(long,byte[]) not implemented");
58: }
59:
60: public int setBytes(long pos, byte[] bytes, int offset, int len)
61: throws SQLException {
62: throw new RuntimeException(
63: "setBytes(long,byte[],int,int) not implemented");
64: }
65:
66: public void truncate(long len) throws SQLException {
67: throw new RuntimeException("truncate(long) not implemented");
68: }
69:
70: }
|