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 import java.io.InputStream;
21 import java.io.OutputStream;
22
23
24
25
26
27 public class Field extends PadJustifyFieldSupport {
28
29 private static final long serialVersionUID = 3939293448043882440L;
30
31 private Overflow overflow;
32 private byte[] buffer;
33
34
35
36
37
38 public Field(int size) {
39 this(new byte[size]);
40 }
41
42
43
44
45
46 public Field(byte[] buffer) {
47 this.buffer = buffer;
48 }
49
50
51
52
53 public int length() {
54 return buffer.length;
55 }
56
57
58
59
60 public synchronized void readFrom(InputStream is) throws IOException {
61 is.read(buffer);
62 }
63
64
65
66
67 public synchronized void writeTo(OutputStream os) throws IOException {
68 os.write(buffer);
69 }
70
71
72
73
74 public void setValue(byte[] b) {
75 getOverflow().check(b, buffer.length);
76 super.setValue(b);
77 }
78
79
80
81
82 public byte[] getValue() {
83 return buffer;
84 }
85
86
87
88
89 public Field clone() {
90 Field result = (Field) super.clone();
91 result.buffer = new byte[buffer.length];
92 System.arraycopy(buffer, 0, result.buffer, 0, buffer.length);
93 return result;
94 }
95
96
97
98
99
100 public Overflow getOverflow() {
101 return overflow == null ? Overflow.ERROR : overflow;
102 }
103
104
105
106
107
108 public void setOverflow(Overflow overflow) {
109 this.overflow = overflow;
110 }
111
112
113
114
115 protected int getPadJustifyLength() {
116 return length();
117 }
118 }