1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.flatfile;
18
19 import java.io.IOException;
20
21 import org.apache.commons.flatfile.util.RepeatingInputStream;
22
23
24
25
26
27 public abstract class EntitySupport implements Entity {
28
29
30 private static final long serialVersionUID = 1067918863342682612L;
31
32
33
34
35 public void fill(byte b) throws IOException {
36 readFrom(RepeatingInputStream.of(b));
37 }
38
39
40
41
42 public EntitySupport clone() {
43 try {
44 return (EntitySupport) super.clone();
45 } catch (CloneNotSupportedException e) {
46 throw new RuntimeException(e);
47 }
48 }
49
50
51
52
53
54 public byte[] getValue(int offset, int length) {
55 if (offset + length > length()) {
56 throw new IndexOutOfBoundsException();
57 }
58 final byte[] value = getValue();
59 final byte[] result = new byte[length];
60 System.arraycopy(value, offset, result, 0, length);
61 return result;
62 }
63
64
65
66
67 public void setValue(byte[] b, int offset, int length) {
68 if (offset + length > b.length) {
69 throw new IndexOutOfBoundsException();
70 }
71 final byte[] subset = new byte[length];
72 System.arraycopy(b, offset, subset, 0, length);
73 setValue(subset);
74 }
75
76 }