01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.lucene.store.jdbc.support;
18:
19: import java.io.InputStream;
20: import java.io.OutputStream;
21: import java.sql.Blob;
22: import java.sql.SQLException;
23:
24: /**
25: * A helper class that can wrap an <code>InputStream</code> as a Jdbc <code>Blob<code>.
26: * <p>
27: * Some jdbc drivers do not support the {@link java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, int)}
28: * method, but require using {@link java.sql.PreparedStatement#setBlob(int, java.sql.Blob)}. For code that already has
29: * an <code>InputStream<code> ready, this <code>Blob</code> implementation can help.
30: *
31: * @see org.apache.lucene.store.jdbc.dialect.Dialect#useInputStreamToInsertBlob()
32: *
33: * @author kimchy
34: */
35: public class InputStreamBlob implements Blob {
36:
37: private InputStream is;
38:
39: private long length;
40:
41: public InputStreamBlob(InputStream is, long length) {
42: this .is = is;
43: this .length = length;
44: }
45:
46: public long length() throws SQLException {
47: return this .length;
48: }
49:
50: public void truncate(long len) throws SQLException {
51: throw new UnsupportedOperationException("");
52: }
53:
54: public byte[] getBytes(long pos, int length) throws SQLException {
55: throw new UnsupportedOperationException("");
56: }
57:
58: public int setBytes(long pos, byte[] bytes) throws SQLException {
59: throw new UnsupportedOperationException("");
60: }
61:
62: public int setBytes(long pos, byte[] bytes, int offset, int len)
63: throws SQLException {
64: throw new UnsupportedOperationException("");
65: }
66:
67: public long position(byte pattern[], long start)
68: throws SQLException {
69: throw new UnsupportedOperationException("");
70: }
71:
72: public InputStream getBinaryStream() throws SQLException {
73: return is;
74: }
75:
76: public void free() throws SQLException {
77: }
78:
79: public InputStream getBinaryStream(long pos, long length)
80: throws SQLException {
81: throw new UnsupportedOperationException("");
82: }
83:
84: public OutputStream setBinaryStream(long pos) throws SQLException {
85: throw new UnsupportedOperationException("");
86: }
87:
88: public long position(Blob pattern, long start) throws SQLException {
89: throw new UnsupportedOperationException("");
90: }
91: }
|