Path: blob/master/test/jdk/javax/sql/testng/util/StubClob.java
41153 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package util;2324import java.io.ByteArrayOutputStream;25import java.io.IOException;26import java.io.InputStream;27import java.io.ObjectOutputStream;28import java.io.OutputStream;29import java.io.Reader;30import java.io.StringReader;31import java.io.StringWriter;32import java.io.Writer;33import java.sql.Clob;34import java.sql.SQLException;35import java.util.logging.Level;36import java.util.logging.Logger;3738public class StubClob implements Clob {3940public String buf = "The test string 0123456789";4142@Override43public String getSubString(long pos, int length) throws SQLException {44return buf;45}4647@Override48public long length() throws SQLException {49return buf.length();50}5152@Override53public Reader getCharacterStream() throws SQLException {54return new StringReader(buf);55}5657@Override58public InputStream getAsciiStream() throws SQLException {59return new java.io.StringBufferInputStream(buf);60}6162@Override63public int setString(long pos, String str) throws SQLException {64return str.length();65}6667@Override68public int setString(long pos, String str, int offset, int len) throws SQLException {69return len;70}7172@Override73public long position(String searchstr, long start) throws SQLException {74throw new UnsupportedOperationException("Not supported yet.");75}7677@Override78public long position(Clob searchstr, long start) throws SQLException {79throw new UnsupportedOperationException("Not supported yet.");80}8182@Override83public OutputStream setAsciiStream(long pos) throws SQLException {84ByteArrayOutputStream baos = new ByteArrayOutputStream();85ObjectOutputStream oos = null;86try {87oos = new ObjectOutputStream(baos);88} catch (IOException ex) {89Logger.getLogger(StubBlob.class.getName()).log(Level.SEVERE, null, ex);90}91return oos;92}9394@Override95public Writer setCharacterStream(long pos) throws SQLException {96return new StringWriter();97}9899@Override100public void truncate(long len) throws SQLException {101throw new UnsupportedOperationException("Not supported yet.");102}103104@Override105public void free() throws SQLException {106}107108@Override109public Reader getCharacterStream(long pos, long length) throws SQLException {110throw new UnsupportedOperationException("Not supported yet.");111}112}113114115