1 package org.hibernate.lob; 3 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.io.OutputStream ; 7 import java.io.Reader ; 8 import java.io.StringReader ; 9 import java.io.Writer ; 10 import java.sql.Clob ; 11 import java.sql.SQLException ; 12 13 18 public class ClobImpl implements Clob { 19 20 private Reader reader; 21 private int length; 22 private boolean needsReset = false; 23 24 public ClobImpl(String string) { 25 reader = new StringReader (string); 26 length = string.length(); 27 } 28 29 public ClobImpl(Reader reader, int length) { 30 this.reader = reader; 31 this.length = length; 32 } 33 34 37 public long length() throws SQLException { 38 return length; 39 } 40 41 44 public void truncate(long pos) throws SQLException { 45 excep(); 46 } 47 48 51 public InputStream getAsciiStream() throws SQLException { 52 try { 53 if (needsReset) reader.reset(); 54 } 55 catch (IOException ioe) { 56 throw new SQLException ("could not reset reader"); 57 } 58 needsReset = true; 59 return new ReaderInputStream(reader); 60 } 61 62 65 public OutputStream setAsciiStream(long pos) throws SQLException { 66 excep(); return null; 67 } 68 69 72 public Reader getCharacterStream() throws SQLException { 73 try { 74 if (needsReset) reader.reset(); 75 } 76 catch (IOException ioe) { 77 throw new SQLException ("could not reset reader"); 78 } 79 needsReset = true; 80 return reader; 81 } 82 83 86 public Writer setCharacterStream(long pos) throws SQLException { 87 excep(); return null; 88 } 89 90 93 public String getSubString(long pos, int len) throws SQLException { 94 excep(); return null; 95 } 96 97 100 public int setString(long pos, String string) throws SQLException { 101 excep(); return 0; 102 } 103 104 107 public int setString(long pos, String string, int i, int j) 108 throws SQLException { 109 excep(); return 0; 110 } 111 112 115 public long position(String string, long pos) throws SQLException { 116 excep(); return 0; 117 } 118 119 122 public long position(Clob colb, long pos) throws SQLException { 123 excep(); return 0; 124 } 125 126 127 private static void excep() { 128 throw new UnsupportedOperationException ("Blob may not be manipulated from creating session"); 129 } 130 131 } 132 133 134 135 136 137 138 | Popular Tags |