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