1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.vfs2.provider.hdfs;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.apache.commons.vfs2.provider.AbstractRandomAccessContent;
23 import org.apache.commons.vfs2.util.RandomAccessMode;
24 import org.apache.hadoop.fs.FSDataInputStream;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27
28
29
30
31
32
33
34 public class HdfsRandomAccessContent extends AbstractRandomAccessContent {
35
36 private final FSDataInputStream fis;
37 private final FileSystem fs;
38 private final Path path;
39
40
41
42
43
44
45
46
47 public HdfsRandomAccessContent(final Path path, final FileSystem fs) throws IOException {
48 super(RandomAccessMode.READ);
49 this.fs = fs;
50 this.path = path;
51 this.fis = this.fs.open(this.path);
52 }
53
54
55
56
57 @Override
58 public void close() throws IOException {
59 this.fis.close();
60 }
61
62
63
64
65 @Override
66 public long getFilePointer() throws IOException {
67 return this.fis.getPos();
68 }
69
70
71
72
73 @Override
74 public InputStream getInputStream() throws IOException {
75 return this.fis;
76 }
77
78
79
80
81 @Override
82 public long length() throws IOException {
83 return this.fs.getFileStatus(this.path).getLen();
84 }
85
86
87
88
89 @Override
90 public boolean readBoolean() throws IOException {
91 return this.fis.readBoolean();
92 }
93
94
95
96
97 @Override
98 public byte readByte() throws IOException {
99 return this.fis.readByte();
100 }
101
102
103
104
105 @Override
106 public char readChar() throws IOException {
107 return this.fis.readChar();
108 }
109
110
111
112
113 @Override
114 public double readDouble() throws IOException {
115 return this.fis.readDouble();
116 }
117
118
119
120
121 @Override
122 public float readFloat() throws IOException {
123 return this.fis.readFloat();
124 }
125
126
127
128
129 @Override
130 public void readFully(final byte[] b) throws IOException {
131 throw new UnsupportedOperationException();
132 }
133
134
135
136
137 @Override
138 public void readFully(final byte[] b, final int off, final int len) throws IOException {
139 throw new UnsupportedOperationException();
140 }
141
142
143
144
145 @Override
146 public int readInt() throws IOException {
147 return this.fis.readInt();
148 }
149
150
151
152
153 @Override
154 @SuppressWarnings("deprecation")
155 public String readLine() throws IOException {
156 return this.fis.readLine();
157 }
158
159
160
161
162 @Override
163 public long readLong() throws IOException {
164 return this.fis.readLong();
165 }
166
167
168
169
170 @Override
171 public short readShort() throws IOException {
172 return this.fis.readShort();
173 }
174
175
176
177
178 @Override
179 public int readUnsignedByte() throws IOException {
180 return this.fis.readUnsignedByte();
181 }
182
183
184
185
186 @Override
187 public int readUnsignedShort() throws IOException {
188 return this.fis.readUnsignedShort();
189 }
190
191
192
193
194 @Override
195 public String readUTF() throws IOException {
196 return this.fis.readUTF();
197 }
198
199
200
201
202 @Override
203 public void seek(final long pos) throws IOException {
204 this.fis.seek(pos);
205 }
206
207
208
209
210 @Override
211 public void setLength(final long newLength) throws IOException {
212 throw new UnsupportedOperationException();
213 }
214
215
216
217
218 @Override
219 public int skipBytes(final int n) throws IOException {
220 throw new UnsupportedOperationException();
221 }
222
223 }