1 25 26 package org.jrobin.core; 27 28 import java.io.IOException ; 29 30 33 public class RrdMemoryBackend extends RrdBackend { 34 private byte[] buffer = new byte[0]; 35 36 protected RrdMemoryBackend(String path) { 37 super(path); 38 } 39 40 protected synchronized void write(long offset, byte[] b) throws IOException { 41 int pos = (int) offset; 42 for(int i = 0; i < b.length; i++) { 43 buffer[pos++] = b[i]; 44 } 45 } 46 47 protected synchronized void read(long offset, byte[] b) throws IOException { 48 int pos = (int) offset; 49 if(pos + b.length <= buffer.length) { 50 for(int i = 0; i < b.length; i++) { 51 b[i] = buffer[pos++]; 52 } 53 } 54 else { 55 throw new IOException ("Not enough bytes available in memory " + getPath()); 56 } 57 } 58 59 63 public long getLength() { 64 return buffer.length; 65 } 66 67 72 protected void setLength(long newLength) throws IOException { 73 if(newLength > Integer.MAX_VALUE) { 74 throw new IOException ("Cannot create this big memory backed RRD"); 75 } 76 buffer = new byte[(int) newLength]; 77 } 78 79 83 public void close() { 84 } 86 } 87 | Popular Tags |