1 package org.hibernate.lob; 3 4 import java.io.ByteArrayInputStream ; 5 import java.io.IOException ; 6 import java.io.InputStream ; 7 import java.io.OutputStream ; 8 import java.sql.Blob ; 9 import java.sql.SQLException ; 10 11 16 public class BlobImpl implements Blob { 17 18 private InputStream stream; 19 private int length; 20 private boolean needsReset = false; 21 22 public BlobImpl(byte[] bytes) { 23 this.stream = new ByteArrayInputStream (bytes); 24 this.length = bytes.length; 25 } 26 27 public BlobImpl(InputStream stream, int length) { 28 this.stream = stream; 29 this.length = length; 30 } 31 32 35 public long length() throws SQLException { 36 return length; 37 } 38 39 42 public void truncate(long pos) throws SQLException { 43 excep(); 44 } 45 46 49 public byte[] getBytes(long pos, int len) throws SQLException { 50 excep(); return null; 51 } 52 53 56 public int setBytes(long pos, byte[] bytes) throws SQLException { 57 excep(); return 0; 58 } 59 60 63 public int setBytes(long pos, byte[] bytes, int i, int j) 64 throws SQLException { 65 excep(); return 0; 66 } 67 68 71 public long position(byte[] bytes, long pos) throws SQLException { 72 excep(); return 0; 73 } 74 75 78 public InputStream getBinaryStream() throws SQLException { 79 try { 80 if (needsReset) stream.reset(); 81 } 82 catch (IOException ioe) { 83 throw new SQLException ("could not reset reader"); 84 } 85 needsReset = true; 86 return stream; 87 } 88 89 92 public OutputStream setBinaryStream(long pos) throws SQLException { 93 excep(); return null; 94 } 95 96 99 public long position(Blob blob, long pos) throws SQLException { 100 excep(); return 0; 101 } 102 103 private static void excep() { 104 throw new UnsupportedOperationException ("Blob may not be manipulated from creating session"); 105 } 106 107 } 108 109 110 111 112 113 114 | Popular Tags |