1 package org.treetank.filelistener.file.data;
2
3 import java.io.DataOutput;
4 import java.io.IOException;
5
6 import org.treetank.api.IData;
7 import org.treetank.exception.TTIOException;
8
9 import com.google.common.hash.Funnel;
10 import com.google.common.hash.PrimitiveSink;
11
12
13
14
15
16
17
18
19
20
21
22 public class FileData implements IData {
23
24
25
26
27
28
29
30 enum FileNodeFunnel implements Funnel<IData> {
31 INSTANCE;
32 public void funnel(IData data, PrimitiveSink into) {
33 final FileData from = (FileData)data;
34 into.putLong(from.dataKey).putBytes(from.val).putBoolean(from.header).putBoolean(from.eof);
35 }
36 }
37
38
39
40
41 private final long dataKey;
42
43
44
45
46 public static final int FILENODESIZE = 1024 * 16;
47
48
49
50
51 private final byte[] val;
52
53
54
55
56 private final boolean header;
57
58
59
60
61 private final boolean eof;
62
63
64
65
66
67
68
69
70 public FileData(long dataKey, byte[] content, boolean header, boolean eof) {
71 this.dataKey = dataKey;
72 this.val = content;
73 this.header = header;
74 this.eof = eof;
75 }
76
77
78
79
80
81
82 public void serialize(final DataOutput output) throws TTIOException {
83 try {
84 output.writeLong(dataKey);
85 output.writeBoolean(header);
86 output.writeBoolean(eof);
87 output.writeInt(val.length);
88 output.write(val);
89 } catch (final IOException exc) {
90 throw new TTIOException(exc);
91 }
92 }
93
94 @Override
95 public long getDataKey() {
96 return this.dataKey;
97 }
98
99
100
101
102
103
104 public boolean isHeader() {
105 return header;
106 }
107
108
109
110
111
112
113 public boolean isEof() {
114 return eof;
115 }
116
117
118
119
120 public byte[] getVal() {
121 return val;
122 }
123
124
125
126
127 @Override
128 public Funnel<IData> getFunnel() {
129 return FileNodeFunnel.INSTANCE;
130 }
131
132 }