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