View Javadoc

1   package com.tapina.robe.runtime;
2   
3   /***
4    * This class is a data block which is nothing but a byte array.
5    */
6   public class RawDataBlock extends DataBlock {
7       private byte[] bytes;
8       private int size;
9   
10      public RawDataBlock(int address, int size) {
11          super(address);
12          this.size = size;
13          bytes = new byte[size];
14      }
15  
16      public RawDataBlock(int address, byte[] bytes) {
17          super(address);
18          this.size = bytes.length;
19          this.bytes = bytes;
20      }
21  
22      public final byte[] getBytes() {
23          return bytes;
24      }
25  
26      public final void extendBackwards(int extension) {
27          byte[] newBytes = new byte[this.size + extension];
28          System.arraycopy(bytes, 0, newBytes, extension, this.size);
29          setAddress(getAddress() - extension);
30          this.bytes = newBytes;
31          this.size += extension;
32      }
33  
34      public final void extendForwards(int extension) {
35          setSize(this.size + extension);
36      }
37  
38      public final int getSize() {
39          return size;
40      }
41  
42      public void setSize(int newSize) {
43          byte[] newBytes = new byte[newSize];
44          System.arraycopy(bytes, 0, newBytes, 0, newSize < size? newSize : size);
45          this.size = newSize;
46          this.bytes = newBytes;
47      }
48  
49      public String toString() {
50          return "Length " + size + "/&" + Integer.toHexString(size) + ": &" + Integer.toHexString(getAddress()) + "-" +
51                  Integer.toHexString(getAddress() + size - 1);
52      }
53  }