01: /*-------------------------------------------------------------------------
02: *
03: * Copyright (c) 2004-2005, PostgreSQL Global Development Group
04: *
05: * IDENTIFICATION
06: * $PostgreSQL: pgjdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java,v 1.12 2007/03/29 06:13:53 jurka Exp $
07: *
08: *-------------------------------------------------------------------------
09: */
10: package org.postgresql.jdbc3;
11:
12: import java.sql.SQLException;
13:
14: public abstract class AbstractJdbc3Blob extends
15: org.postgresql.jdbc2.AbstractJdbc2Blob {
16:
17: public AbstractJdbc3Blob(org.postgresql.core.BaseConnection conn,
18: long oid) throws SQLException {
19: super (conn, oid);
20: }
21:
22: /**
23: * Writes the given array of bytes to the <code>BLOB</code> value that
24: * this <code>Blob</code> object represents, starting at position
25: * <code>pos</code>, and returns the number of bytes written.
26: *
27: * @param pos the position in the <code>BLOB</code> object at which
28: * to start writing
29: * @param bytes the array of bytes to be written to the <code>BLOB</code>
30: * value that this <code>Blob</code> object represents
31: * @return the number of bytes written
32: * @exception SQLException if there is an error accessing the
33: * <code>BLOB</code> value
34: * @see #getBytes
35: * @since 1.4
36: */
37: public synchronized int setBytes(long pos, byte[] bytes)
38: throws SQLException {
39: return setBytes(pos, bytes, 0, bytes.length);
40: }
41:
42: /**
43: * Writes all or part of the given <code>byte</code> array to the
44: * <code>BLOB</code> value that this <code>Blob</code> object represents
45: * and returns the number of bytes written.
46: * Writing starts at position <code>pos</code> in the <code>BLOB</code>
47: * value; <code>len</code> bytes from the given byte array are written.
48: *
49: * @param pos the position in the <code>BLOB</code> object at which
50: * to start writing
51: * @param bytes the array of bytes to be written to this <code>BLOB</code>
52: * object
53: * @param offset the offset into the array <code>bytes</code> at which
54: * to start reading the bytes to be set
55: * @param len the number of bytes to be written to the <code>BLOB</code>
56: * value from the array of bytes <code>bytes</code>
57: * @return the number of bytes written
58: * @exception SQLException if there is an error accessing the
59: * <code>BLOB</code> value
60: * @see #getBytes
61: * @since 1.4
62: */
63: public synchronized int setBytes(long pos, byte[] bytes,
64: int offset, int len) throws SQLException {
65: assertPosition(pos);
66: lo.seek((int) (pos - 1));
67: lo.write(bytes, offset, len);
68: return len;
69: }
70:
71: }
|