View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2009, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.dataset.datatype;
22  
23  import java.io.InputStream;
24  import java.io.OutputStream;
25  import java.sql.Blob;
26  import java.sql.SQLException;
27  
28  /**
29   * @author John Hurst
30   * @version $Revision$
31   * @since 2.4.8
32   */
33  public class TestBlob implements Blob
34  {
35      private byte[] data = new byte[0];
36  
37      public TestBlob(byte[] data)
38      {
39          this.data = data;
40      }
41  
42      public long length() throws SQLException
43      { // used in DbUnit
44          return data.length;
45      }
46  
47      public byte[] getBytes(long pos, int length) throws SQLException
48      { // used in DbUnit
49          byte[] result = new byte[length];
50          System.arraycopy(data, (int) pos - 1, result, 0, length);
51          return result;
52      }
53  
54      public InputStream getBinaryStream() throws SQLException
55      {
56          throw new SQLException("TestBlob does not support getBinaryStream()");
57      }
58  
59      public long position(byte[] pattern, long start) throws SQLException
60      {
61          throw new SQLException("TestBlob does not support position(byte[], long)");
62      }
63  
64      public long position(Blob pattern, long start) throws SQLException
65      {
66          throw new SQLException("TestBlob does not support position(Blob, long)");
67      }
68  
69      public int setBytes(long pos, byte[] bytes) throws SQLException
70      {
71          throw new SQLException("TestBlob does not support setBytes(long, byte[])");
72      }
73  
74      public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
75      {
76          throw new SQLException("TestBlob does not support setBytes(long, byte[], int, int)");
77      }
78  
79      public OutputStream setBinaryStream(long pos) throws SQLException
80      {
81          throw new SQLException("TestBlob does not support setBinaryStream(long)");
82      }
83  
84      public void truncate(long len) throws SQLException
85      {
86          throw new SQLException("TestBlob does not support truncate(long)");
87      }
88  
89      public void free() throws SQLException
90      {
91          throw new SQLException("TestBlob does not support free()");
92      }
93  
94      public InputStream getBinaryStream(long pos, long length) throws SQLException
95      {
96          throw new SQLException("TestBlob does not support getBinaryStream(long, long)");
97      }
98  }