1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @modules java.sql.rowset/com.sun.rowset 27 * java.sql.rowset/com.sun.rowset.internal 28 * java.sql.rowset/com.sun.rowset.providers 29 */ 30 31 package util; 32 33 import java.io.ByteArrayOutputStream; 34 import java.io.IOException; 35 import java.io.InputStream; 36 import java.io.ObjectOutputStream; 37 import java.io.OutputStream; 38 import java.sql.Blob; 39 import java.sql.SQLException; 40 import java.util.Arrays; 41 import java.util.logging.Level; 42 import java.util.logging.Logger; 43 44 public class StubBlob implements Blob { 45 46 private byte[] bytes; 47 48 public StubBlob() { 49 bytes = new byte[]{2, 4, 6, 8}; 50 } 51 52 public long length() throws SQLException { 53 return bytes.length; 54 } 55 56 public byte[] getBytes(long pos, int length) 57 throws SQLException { 58 return Arrays.copyOfRange(bytes, (int) pos - 1, length); 59 } 60 61 public InputStream getBinaryStream() 62 throws SQLException { 63 return null; 64 } 65 66 public long position(byte[] pattern, long start) 67 throws SQLException { 68 return 0; 69 } 70 71 public long position(Blob pattern, long start) 72 throws SQLException { 73 return 0; 74 } 75 76 public int setBytes(long pos, byte[] bytes) 77 throws SQLException { 78 return 0; 79 } 80 81 public int setBytes(long pos, byte[] bytes, int offset, int len) 82 throws SQLException { 83 return 0; 84 } 85 86 public OutputStream setBinaryStream(long pos) 87 throws SQLException { 88 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 89 ObjectOutputStream oos = null; 90 try { 91 oos = new ObjectOutputStream(baos); 92 } catch (IOException ex) { 93 Logger.getLogger(StubBlob.class.getName()).log(Level.SEVERE, null, ex); 94 } 95 return oos; 96 } 97 98 public void truncate(long len) 99 throws SQLException { 100 } 101 102 public void free() throws SQLException { 103 } 104 105 public InputStream getBinaryStream(long pos, long length) throws SQLException { 106 return null; 107 } 108 }