summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/org/postgresql/largeobject/PGblob.java
blob: 2959668bac0c9d3605b05b75020d7ce77a4084cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package org.postgresql.largeobject;

// IMPORTANT NOTE: This file implements the JDBC 2 version of the driver.
// If you make any modifications to this file, you must make sure that the
// changes are also made (if relevent) to the related JDBC 1 class in the
// org.postgresql.jdbc1 package.


import java.lang.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import org.postgresql.Field;
import org.postgresql.largeobject.*;
import org.postgresql.largeobject.*;

/**
 * This implements the Blob interface, which is basically another way to
 * access a LargeObject.
 *
 * $Id: PGblob.java,v 1.2 2001/10/25 05:59:59 momjian Exp $
 *
 */
public class PGblob implements java.sql.Blob
{
	private org.postgresql.Connection conn;
	private int oid;
	private LargeObject lo;

	public PGblob(org.postgresql.Connection conn, int oid) throws SQLException
	{
		this.conn = conn;
		this.oid = oid;
		LargeObjectManager lom = conn.getLargeObjectAPI();
		this.lo = lom.open(oid);
	}

	public long length() throws SQLException
	{
		return lo.size();
	}

	public InputStream getBinaryStream() throws SQLException
	{
		return lo.getInputStream();
	}

	public byte[] getBytes(long pos, int length) throws SQLException
	{
		lo.seek((int)pos, LargeObject.SEEK_SET);
		return lo.read(length);
	}

	/*
	 * For now, this is not implemented.
	 */
	public long position(byte[] pattern, long start) throws SQLException
	{
		throw org.postgresql.Driver.notImplemented();
	}

	/*
	 * This should be simply passing the byte value of the pattern Blob
	 */
	public long position(Blob pattern, long start) throws SQLException
	{
		return position(pattern.getBytes(0, (int)pattern.length()), start);
	}

}