1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 import java.sql.Blob ; 29 import java.sql.SQLException ; 30 31 39 40 class MStreamableBlob extends AbstractStreamableObject implements Blob { 41 42 45 MStreamableBlob(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 return rawSize(); 54 } 55 56 public byte[] getBytes(long pos, int length) throws SQLException { 57 --pos; 59 if (pos < 0 || pos + length > length()) { 60 throw new SQLException ("Out of bounds."); 61 } 62 63 byte[] buf = new byte[length]; 65 InputStream i_stream = getBinaryStream(); 66 try { 67 i_stream.skip(pos); 68 for (int i = 0; i < length; ++i) { 69 buf[i] = (byte) i_stream.read(); 70 } 71 } 72 catch (IOException e) { 73 e.printStackTrace(System.err); 74 throw new SQLException ("IO Error: " + e.getMessage()); 75 } 76 77 return buf; 78 } 79 80 public InputStream getBinaryStream() throws SQLException { 81 return new StreamableObjectInputStream(rawSize()); 82 } 83 84 public long position(byte[] pattern, long start) throws SQLException { 85 throw MSQLException.unsupported(); 86 } 87 88 public long position(Blob pattern, long start) throws SQLException { 89 throw MSQLException.unsupported(); 90 } 91 92 94 96 public int setBytes(long pos, byte[] bytes) throws SQLException { 97 98 throw MSQLException.unsupported(); 99 } 100 101 public int setBytes(long pos, byte[] bytes, int offset, int len) 102 throws SQLException { 103 throw MSQLException.unsupported(); 104 } 105 106 public java.io.OutputStream setBinaryStream(long pos) throws SQLException { 107 throw MSQLException.unsupported(); 108 } 109 110 public void truncate(long len) throws SQLException { 111 throw MSQLException.unsupported(); 112 } 113 114 116 } 117 118 | Popular Tags |