File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
src/main/java/qiniu/ip17mon Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,31 @@ public static Locator loadFromLocal(String filePath) throws IOException {
154154
155155 return loadBinary (b );
156156 }
157+
158+ public static Locator loadFromHDFS (String dfsPath ) throws Exception {
159+ Configuration conf = new Configuration ();
160+ FileSystem fs = FileSystem .get (conf );
161+
162+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
163+
164+ Path filePath = new Path (dfsPath );
165+
166+ if (fs .exists (filePath )){
167+ FSDataInputStream in = fs .open (filePath );
168+ byte [] buffer = new byte [1 ];
169+
170+ while (in .read (buffer ) != -1 ){
171+ byteArrayOutputStream .write (buffer );
172+ }
173+ } else {
174+ throw new Exception ("File does not exists!" );
175+ }
176+
177+ // Using in Spark, don't close it.
178+ //fs.close();
179+
180+ return loadBinary (byteArrayOutputStream .toByteArray ());
181+ }
157182
158183 public static Locator loadBinary (byte [] ipdb ) {
159184 return new Locator (ipdb );
You can’t perform that action at this time.
0 commit comments