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.io.Reader; 39 import java.io.StringReader; 40 import java.io.StringWriter; 41 import java.io.Writer; 42 import java.sql.Clob; 43 import java.sql.SQLException; 44 import java.util.logging.Level; 45 import java.util.logging.Logger; 46 47 public class StubClob implements Clob { 48 49 public String buf = "The test string 0123456789"; 50 51 @Override 52 public String getSubString(long pos, int length) throws SQLException { 53 return buf; 54 } 55 56 @Override 57 public long length() throws SQLException { 58 return buf.length(); 59 } 60 61 @Override 62 public Reader getCharacterStream() throws SQLException { 63 return new StringReader(buf); 64 } 65 66 @Override 67 public InputStream getAsciiStream() throws SQLException { 68 return new java.io.StringBufferInputStream(buf); 69 } 70 71 @Override 72 public int setString(long pos, String str) throws SQLException { 73 return str.length(); 74 } 75 76 @Override 77 public int setString(long pos, String str, int offset, int len) throws SQLException { 78 return len; 79 } 80 81 @Override 82 public long position(String searchstr, long start) throws SQLException { 83 throw new UnsupportedOperationException("Not supported yet."); 84 } 85 86 @Override 87 public long position(Clob searchstr, long start) throws SQLException { 88 throw new UnsupportedOperationException("Not supported yet."); 89 } 90 91 @Override 92 public OutputStream setAsciiStream(long pos) throws SQLException { 93 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 94 ObjectOutputStream oos = null; 95 try { 96 oos = new ObjectOutputStream(baos); 97 } catch (IOException ex) { 98 Logger.getLogger(StubBlob.class.getName()).log(Level.SEVERE, null, ex); 99 } 100 return oos; 101 } 102 103 @Override 104 public Writer setCharacterStream(long pos) throws SQLException { 105 return new StringWriter(); 106 } 107 108 @Override 109 public void truncate(long len) throws SQLException { 110 throw new UnsupportedOperationException("Not supported yet."); 111 } 112 113 @Override 114 public void free() throws SQLException { 115 } 116 117 @Override 118 public Reader getCharacterStream(long pos, long length) throws SQLException { 119 throw new UnsupportedOperationException("Not supported yet."); 120 } 121 }