1 32 package com.imagero.uio.buffer; 33 34 import com.imagero.uio.RandomAccess; 35 36 import java.io.IOException ; 37 38 45 public class RABuffer extends RABufferRO implements MutableBuffer { 46 47 RandomAccess ra; 48 private boolean dirty; 49 50 51 public RABuffer(RandomAccess ra, long offset, int length) { 52 super(ra, offset, length); 53 this.ra = ra; 54 } 55 56 public void flush() throws IOException { 57 if(dirty) { 58 try { 59 writeData(); 60 } 61 finally { 62 dirty = false; 63 } 64 } 65 } 66 67 private void writeData() throws IOException { 68 if(data == null) { 69 return; 70 } 71 long currentOffset = ro.getFilePointer(); 72 ra.seek(offset); 73 ra.write(data); 74 ra.seek(currentOffset); 75 } 76 77 public boolean isDirty() { 78 return dirty; 79 } 80 81 public void setDirty() { 82 this.dirty = true; 83 } 84 } 85 | Popular Tags |