001: /*
002: * $Id: ByteArrayBlob.java,v 1.3 2007/11/13 19:04:02 rwald Exp $
003: * =======================================================================
004: * Copyright (c) 2003 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.types;
042:
043: import java.io.ByteArrayInputStream;
044: import java.io.InputStream;
045: import java.io.OutputStream;
046: import java.sql.Blob;
047: import java.sql.SQLException;
048:
049: import org.axiondb.jdbc.AxionBlob;
050:
051: /**
052: * A {@link Blob} based upon a simple byte array.
053: *
054: * @version $Revision: 1.3 $ $Date: 2007/11/13 19:04:02 $
055: * @author Rodney Waldhoff
056: */
057: public class ByteArrayBlob implements AxionBlob {
058:
059: public ByteArrayBlob(byte[] value) {
060: if (null == value) {
061: throw new NullPointerException();
062: }
063: _value = value;
064: }
065:
066: public InputStream getBinaryStream() throws SQLException {
067: return new ByteArrayInputStream(_value);
068: }
069:
070: public byte[] getBytes() {
071: return _value;
072: }
073:
074: public byte[] getBytes(long pos, int length) throws SQLException {
075: if (pos > length() || pos < 0) {
076: throw new SQLException("position " + pos
077: + " is out of bounds.");
078: }
079: if (length < 0) {
080: throw new SQLException("length" + length + " is invalid.");
081: }
082: if (length + pos > length()) {
083: length = (int) (length() - pos);
084: }
085: byte[] returning = new byte[length];
086: System.arraycopy(_value, (int) pos, returning, 0, length);
087: return returning;
088: }
089:
090: public long length() throws SQLException {
091: return _value.length;
092: }
093:
094: public long position(Blob pattern, long start) throws SQLException {
095: throw new SQLException("Not supported");
096: }
097:
098: public long position(byte[] pattern, long start)
099: throws SQLException {
100: throw new SQLException("Not supported");
101: }
102:
103: public OutputStream setBinaryStream(long pos) throws SQLException {
104: throw new SQLException("Not supported");
105: }
106:
107: public int setBytes(long pos, byte[] bytes, int offset, int len)
108: throws SQLException {
109: throw new SQLException("Not supported");
110: }
111:
112: public int setBytes(long pos, byte[] bytes) throws SQLException {
113: throw new SQLException("Not supported");
114: }
115:
116: public void truncate(long len) throws SQLException {
117: throw new SQLException("Not supported");
118: }
119:
120: private byte[] _value = null;
121:
122: @Override
123: public void free() throws SQLException {
124: throw new SQLException("Not supported");
125: }
126:
127: @Override
128: public InputStream getBinaryStream(long arg0, long arg1)
129: throws SQLException {
130: throw new SQLException("Not supported");
131: }
132: }
|