1 9 package org.ozoneDB.blob; 10 11 import org.ozoneDB.OzoneObject; 12 13 14 21 public class BLOBPageImpl extends OzoneObject implements BLOBPage { 22 23 byte[] data; 24 int space; 25 int size; 26 27 28 public BLOBPageImpl() { 29 } 30 31 32 public void init( int _space ) { 33 space = _space; 34 data = new byte[space]; 35 size = 0; 36 } 37 38 39 public int size() { 40 return size; 41 } 42 43 44 45 public void write( byte[] b, int off ) { 46 if (off == 0 && b.length == space) { 47 data = b; 48 size = space; 49 } else { 50 int len = b.length; 51 len = Math.max( Math.min( space - off, len ), 0 ); 53 54 System.arraycopy( b, 0, data, off, len ); 55 size = off + len; 56 } 57 } 58 59 60 61 public byte[] read( int off, int len ) { 62 len = Math.max( Math.min( size - off, len ), 0 ); 64 65 byte[] result = new byte[len]; 66 System.arraycopy( data, off, result, 0, len ); 67 68 71 return result; 72 } 73 74 } 75 | Popular Tags |