1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 import java.sql.Clob ; 29 import java.sql.SQLException ; 30 31 39 40 class MStreamableClob extends AbstractStreamableObject implements Clob { 41 42 45 MStreamableClob(MConnection connection, int result_set_id, byte type, 46 long streamable_object_id, long size) { 47 super(connection, result_set_id, type, streamable_object_id, size); 48 } 49 50 52 public long length() throws SQLException { 53 if (getType() == 4) { 54 return rawSize() / 2; 55 } 56 return rawSize(); 57 } 58 59 public String getSubString(long pos, int length) throws SQLException { 60 int p = (int) (pos - 1); 61 Reader reader = getCharacterStream(); 62 try { 63 reader.skip(p); 64 StringBuffer buf = new StringBuffer (length); 65 for (int i = 0; i < length; ++i) { 66 int c = reader.read(); 67 buf.append((char) c); 68 } 69 return new String (buf); 70 } 71 catch (IOException e) { 72 e.printStackTrace(System.err); 73 throw new SQLException ("IO Error: " + e.getMessage()); 74 } 75 } 76 77 public Reader getCharacterStream() throws SQLException { 78 if (getType() == 3) { 79 return new AsciiReader(new StreamableObjectInputStream(rawSize())); 80 } 81 else if (getType() == 4) { 82 return new BinaryToUnicodeReader( 83 new StreamableObjectInputStream(rawSize())); 84 } 85 else { 86 throw new SQLException ("Unknown type."); 87 } 88 } 89 90 public java.io.InputStream getAsciiStream() throws SQLException { 91 if (getType() == 3) { 92 return new StreamableObjectInputStream(rawSize()); 93 } 94 else if (getType() == 4) { 95 return new AsciiInputStream(getCharacterStream()); 96 } 97 else { 98 throw new SQLException ("Unknown type."); 99 } 100 } 101 102 public long position(String searchstr, long start) throws SQLException { 103 throw MSQLException.unsupported(); 104 } 105 106 public long position(Clob searchstr, long start) throws SQLException { 107 throw MSQLException.unsupported(); 108 } 109 110 112 114 public int setString(long pos, String str) throws SQLException { 115 throw MSQLException.unsupported(); 116 } 117 118 public int setString(long pos, String str, int offset, int len) 119 throws SQLException { 120 throw MSQLException.unsupported(); 121 } 122 123 public java.io.OutputStream setAsciiStream(long pos) throws SQLException { 124 throw MSQLException.unsupported(); 125 } 126 127 public java.io.Writer setCharacterStream(long pos) throws SQLException { 128 throw MSQLException.unsupported(); 129 } 130 131 public void truncate(long len) throws SQLException { 132 throw MSQLException.unsupported(); 133 } 134 135 137 } 138 139 | Popular Tags |