1417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespackage SQLite;
2417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
3417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughesimport java.io.*;
4417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
5417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/**
6417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Internal class implementing java.io.InputStream on
7417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * SQLite 3.4.0 incremental blob I/O interface.
8417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */
9417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
10417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughesclass BlobR extends InputStream {
11417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
12417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
13417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Blob instance
14417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
15417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
16417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private Blob blob;
17417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
18417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
19417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Read position, file pointer.
20417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
21417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
22417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private int pos;
23417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
24417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
25417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Contruct InputStream from blob instance.
26417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
27417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
28417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    BlobR(Blob blob) {
297a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	this.blob = blob;
307a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	this.pos = 0;
31417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
32417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
335cd52ed8fd9244cbbb9c2553e58b511344f75d8bElliott Hughes    /**
345cd52ed8fd9244cbbb9c2553e58b511344f75d8bElliott Hughes     * Return number of available bytes for reading.
355cd52ed8fd9244cbbb9c2553e58b511344f75d8bElliott Hughes     * @return available input bytes
365cd52ed8fd9244cbbb9c2553e58b511344f75d8bElliott Hughes     */
375cd52ed8fd9244cbbb9c2553e58b511344f75d8bElliott Hughes
38417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public int available() throws IOException {
397a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	int ret = blob.size - pos;
407a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return (ret < 0) ? 0 : ret;
41417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
42417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
43417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
44417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Mark method; dummy to satisfy InputStream class.
45417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
46417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
47417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void mark(int limit) {
48417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
49417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
50417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
51417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Reset method; dummy to satisfy InputStream class.
52417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
53417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
54417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void reset() throws IOException {
55417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
56417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
57417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
58417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Mark support; not for this class.
59417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return always false
60417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
61417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
62417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public boolean markSupported() {
637a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return false;
64417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
65417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
66417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
67417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Close this blob InputStream.
68417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
69417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
70417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void close() throws IOException {
71417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes        blob.close();
727a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	blob = null;
737a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	pos = 0;
74417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
75417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
76417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
77417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Skip over blob data.
78417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
79417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
80417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public long skip(long n) throws IOException {
817a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	long ret = pos + n;
827a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (ret < 0) {
837a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    ret = 0;
847a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos = 0;
857a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	} else if (ret > blob.size) {
867a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    ret = blob.size;
877a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos = blob.size;
887a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	} else {
897a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos = (int) ret;
907a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
917a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return ret;
92417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
93417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
94417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
95417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Read single byte from blob.
96417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return byte read
97417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
98417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
99417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public int read() throws IOException {
1007a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	byte b[] = new byte[1];
1017a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	int n = blob.read(b, 0, pos, b.length);
1027a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (n > 0) {
1037a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos += n;
1047a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    return b[0];
1057a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1067a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return -1;
107417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
108417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
109417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
110417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Read byte array from blob.
111417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be filled
112417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return number of bytes read
113417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
114417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
115417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public int read(byte b[]) throws IOException {
1167a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	int n = blob.read(b, 0, pos, b.length);
1177a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (n > 0) {
1187a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos += n;
1197a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    return n;
1207a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1217a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return -1;
122417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
123417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
124417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
125417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Read slice of byte array from blob.
126417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be filled
127417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param off offset into byte array
128417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param len length to be read
129417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return number of bytes read
130417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
131417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
132417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public int read(byte b[], int off, int len) throws IOException {
1337a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (off + len > b.length) {
1347a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    len = b.length - off;
1357a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1367a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (len < 0) {
1377a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    return -1;
1387a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1397a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (len == 0) {
1407a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    return 0;
1417a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1427a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	int n = blob.read(b, off, pos, len);
1437a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (n > 0) {
1447a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos += n;
1457a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    return n;
1467a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
1477a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return -1;
148417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
149417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes}
150417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
151417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/**
152417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Internal class implementing java.io.OutputStream on
153417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * SQLite 3.4.0 incremental blob I/O interface.
154417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */
155417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
156417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughesclass BlobW extends OutputStream {
157417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
158417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
159417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Blob instance
160417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
161417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
162417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private Blob blob;
163417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
164417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
165417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Read position, file pointer.
166417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
167417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
168417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private int pos;
169417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
170417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
171417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Contruct OutputStream from blob instance.
172417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
173417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
174417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    BlobW(Blob blob) {
1757a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	this.blob = blob;
1767a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	this.pos = 0;
177417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
178417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
179417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
180417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Flush blob; dummy to satisfy OutputStream class.
181417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
182417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
183417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void flush() throws IOException {
184417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
185417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
186417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
187417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Close this blob OutputStream.
188417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
189417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
190417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void close() throws IOException {
191417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes        blob.close();
1927a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	blob = null;
1937a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	pos = 0;
194417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
195417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
196417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
197417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Write blob data.
198417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param v byte to be written at current position.
199417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
200417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
201417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void write(int v) throws IOException {
2027a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	byte b[] = new byte[1];
2037a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	b[0] = (byte) v;
2047a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	pos += blob.write(b, 0, pos, 1);
205417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
206417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
207417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
208417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Write blob data.
209417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be written at current position.
210417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
211417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
212417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void write(byte[] b) throws IOException {
2137a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (b != null && b.length > 0) {
2147a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos += blob.write(b, 0, pos, b.length);
2157a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
216417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
217417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
218417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
219417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Write blob data.
220417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be written.
221417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param off offset within byte array
222417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param len length of data to be written
223417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
224417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
225417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public void write(byte[] b, int off, int len) throws IOException {
2267a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	if (b != null) {
2277a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    if (off + len > b.length) {
2287a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes		len = b.length - off;
2297a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    }
2307a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    if (len <= 0) {
2317a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes		return;
2327a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    }
2337a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	    pos += blob.write(b, off, pos, len);
2347a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	}
235417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
236417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes}
237417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
238417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes/**
239417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Class to represent SQLite3 3.4.0 incremental blob I/O interface.
240417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes *
241417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * Note, that all native methods of this class are
242417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * not synchronized, i.e. it is up to the caller
243417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * to ensure that only one thread is in these
244417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes * methods at any one time.
245417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes */
246417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
247417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughespublic class Blob {
248417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
249417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
250417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal handle for the SQLite3 blob.
251417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
252417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
253417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private long handle = 0;
254417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
255417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
256417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Cached size of blob, setup right after blob
257417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * has been opened.
258417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
259417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
260417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    protected int size = 0;
261417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
262417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
263417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Return InputStream for this blob
264417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return InputStream
265417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
266417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
267417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public InputStream getInputStream() {
2687a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return (InputStream) new BlobR(this);
269417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
270417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
271417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
272417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Return OutputStream for this blob
273417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return OutputStream
274417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
275417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
276417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public OutputStream getOutputStream() {
2777a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	return (OutputStream) new BlobW(this);
278417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
279417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
280417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
281417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Close blob.
282417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
283417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
284417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    public native void close();
285417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
286417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
287417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal blob write method.
288417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be written
289417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param off offset into byte array
290417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param pos offset into blob
291417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param len length to be written
292417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return number of bytes written to blob
293417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
294417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
295417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    native int write(byte[] b, int off, int pos, int len) throws IOException;
296417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
297417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
298417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal blob read method.
299417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param b byte array to be written
300417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param off offset into byte array
301417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param pos offset into blob
302417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @param len length to be written
303417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * @return number of bytes written to blob
304417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
305417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
306417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    native int read(byte[] b, int off, int pos, int len) throws IOException;
307417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
308417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
309417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Destructor for object.
310417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
311417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
312417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    protected native void finalize();
313417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
314417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    /**
315417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     * Internal native initializer.
316417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes     */
317417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
318417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    private static native void internal_init();
319417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes
320417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    static {
3217a647e8547e57ca573541be55b3728ef7ce376feElliott Hughes	internal_init();
322417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes    }
323417deb1db112103aff04231b6ca79772ff7d3a21Elliott Hughes}
324