1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 import java.sql.SQLException ; 29 import com.mckoi.util.PagedInputStream; 30 31 40 41 abstract class AbstractStreamableObject { 42 43 47 protected final MConnection connection; 48 49 52 protected final int result_set_id; 53 54 57 private final long streamable_object_id; 58 59 62 private final byte type; 63 64 67 private final long size; 68 69 72 AbstractStreamableObject(MConnection connection, int result_set_id, 73 byte type, long streamable_object_id, long size) { 74 this.connection = connection; 75 this.result_set_id = result_set_id; 76 this.type = type; 77 this.streamable_object_id = streamable_object_id; 78 this.size = size; 79 } 80 81 85 protected long getStreamableId() { 86 return streamable_object_id; 87 } 88 89 92 protected byte getType() { 93 return type; 94 } 95 96 102 protected long rawSize() { 103 return size; 104 } 105 106 107 108 109 110 112 116 class StreamableObjectInputStream extends PagedInputStream { 117 118 121 private final static int B_SIZE = 64 * 1024; 122 123 126 public StreamableObjectInputStream(long in_size) { 127 super(B_SIZE, in_size); 128 } 129 130 protected void readPageContent(byte[] buf, long pos, int length) 131 throws IOException { 132 try { 133 StreamableObjectPart part = connection.requestStreamableObjectPart( 135 result_set_id, streamable_object_id, pos, length); 136 System.arraycopy(part.getContents(), 0, buf, 0, length); 137 } 138 catch (SQLException e) { 139 throw new IOException("SQL Error: " + e.getMessage()); 140 } 141 } 142 143 } 144 145 } 146 147 | Popular Tags |