2
* Copyright (c) 2004, 2005 TADA AB - Taby Sweden
2
* Copyright (c) 2004, 2005, 2006 TADA AB - Taby Sweden
3
3
* Distributed under the terms shown in the file COPYRIGHT
4
4
* found in the root folder of this project or at
5
5
* http://eng.tada.se/osprojects/COPYRIGHT.html
20
20
public class BlobValue extends InputStream implements Blob
22
public static int getStreamLength(InputStream value) throws SQLException
26
value.mark(Integer.MAX_VALUE);
27
long length = value.skip(Long.MAX_VALUE);
28
if(length > Integer.MAX_VALUE)
29
throw new SQLException("stream content too large");
35
throw new SQLException(e.getMessage());
39
private long m_markPos;
40
private final long m_nBytes;
22
41
private final InputStream m_stream;
23
private final long m_nBytes;
24
43
private long m_streamPos;
25
private long m_markPos;
27
45
public BlobValue(byte[] bytes)
29
47
this(new ByteArrayInputStream(bytes), bytes.length);
32
49
public BlobValue(InputStream stream, long nBytes)
40
//***************************************
41
// Implementation of java.sql.Blob
42
//***************************************
58
//***************************************
59
// Implementation of java.io.InputStream
60
//***************************************
61
public int available()
64
return m_stream.available();
48
67
public InputStream getBinaryStream()
86
public long position(byte[] pattern, long start)
88
throw new UnsupportedOperationException();
94
public long position(Blob pattern, long start)
96
throw new UnsupportedOperationException();
99
//*************************************************************************
100
// Implementation of java.sql.Blob JDK 1.4 methods
102
// Those method are intended to provide a channel to the underlying data
103
// storage as an alternatvie to the setBinaryStream
104
// on the preparedStatement and are not implemented by the BlobValue.
106
//*************************************************************************
108
* In this method is not supported by <code>BlobValue</code>
110
public OutputStream setBinaryStream(long pos)
112
throw new UnsupportedOperationException();
116
* In this method is not supported by <code>BlobValue</code>
118
public int setBytes(long pos, byte[] bytes)
120
throw new UnsupportedOperationException();
124
* In this method is not supported by <code>BlobValue</code>
126
public int setBytes(long pos, byte[] bytes, int offset, int len)
128
throw new UnsupportedOperationException();
132
* In this method is not supported by <code>BlobValue</code>
134
public void truncate(long len)
136
throw new UnsupportedOperationException();
139
//***************************************
140
// Implementation of java.io.InputStream
141
//***************************************
142
public int available()
145
return m_stream.available();
148
public synchronized void mark(int readLimit)
150
m_stream.mark(readLimit);
151
m_markPos = m_streamPos;
154
public boolean markSupported()
156
return m_stream.markSupported();
159
public synchronized int read()
162
int rs = m_stream.read();
167
public synchronized int read(byte[] b)
170
int rs = m_stream.read(b);
176
103
* Called from within...
177
104
* @param buf a buffer that reflects the internally allocated bytea buffer.
178
105
* This size of this buffer will be exactly the size returned by a call to
203
130
m_streamPos += rs;
133
//***************************************
134
// Implementation of java.sql.Blob
135
//***************************************
141
public synchronized void mark(int readLimit)
143
m_stream.mark(readLimit);
144
m_markPos = m_streamPos;
147
public boolean markSupported()
149
return m_stream.markSupported();
155
public long position(Blob pattern, long start)
157
throw new UnsupportedOperationException();
163
public long position(byte[] pattern, long start)
165
throw new UnsupportedOperationException();
168
public synchronized int read()
171
int rs = m_stream.read();
176
public synchronized int read(byte[] b)
179
int rs = m_stream.read(b);
206
184
public synchronized int read(byte[] b, int off, int len)
207
185
throws IOException
192
public synchronized void reset()
196
m_streamPos = m_markPos;
199
//*************************************************************************
200
// Implementation of java.sql.Blob JDK 1.4 methods
202
// Those method are intended to provide a channel to the underlying data
203
// storage as an alternatvie to the setBinaryStream
204
// on the preparedStatement and are not implemented by the BlobValue.
206
//*************************************************************************
208
* In this method is not supported by <code>BlobValue</code>
210
public OutputStream setBinaryStream(long pos)
212
throw new UnsupportedOperationException();
216
* In this method is not supported by <code>BlobValue</code>
218
public int setBytes(long pos, byte[] bytes)
220
throw new UnsupportedOperationException();
224
* In this method is not supported by <code>BlobValue</code>
226
public int setBytes(long pos, byte[] bytes, int offset, int len)
228
throw new UnsupportedOperationException();
214
231
public synchronized long skip(long nBytes)
215
232
throws IOException