1 9 package org.ozoneDB.blob; 10 11 import java.io.*; 12 13 14 24 public class BLOBInputStream extends InputStream implements Serializable { 25 26 BLOBContainer container; 27 int index = 0; 28 29 30 public BLOBInputStream( BLOBContainer _container ) { 31 container = _container; 32 } 33 34 35 public int available() throws IOException { 36 try { 37 return container.available( index ); 38 } catch (Exception e) { 39 throw new IOException( e.getMessage() ); 40 } 41 } 42 43 44 public boolean markSupported() { 45 return false; 46 } 47 48 49 public int read( byte[] b ) throws IOException { 50 return read( b, 0, b.length ); 51 } 52 53 54 public int read( byte[] b, int off, int len ) throws IOException { 55 try { 56 if (b == null) { 57 skip( len ); 58 return len; 59 } 61 62 byte[] bb = container.read( index, len ); 63 len = bb.length; 64 System.arraycopy( bb, 0, b, off, len ); 65 index += len; 66 67 return len == 0 ? -1 : len; 68 } catch (Exception e) { 69 throw new IOException( e.getMessage() ); 70 } 71 } 72 73 74 public int read() throws IOException { 75 try { 76 byte[] bb = container.read( index, 1 ); 77 index += bb.length; 78 return bb.length == 1 ? bb[0] : -1; 79 } catch (Exception e) { 80 throw new IOException( e.getMessage() ); 81 } 82 } 83 84 85 public long skip( long n ) throws IOException { 86 int avail = available(); 87 n = Math.min( n, avail ); 88 index += n; 89 return n; 90 } 91 92 93 public void close() throws IOException { 94 } 95 } 96 | Popular Tags |