importorg.apache.hadoop.conf.Configuration;
importorg.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.*;
public class MyFSDataInputStream extendsFSDataInputStream {
public MyFSDataInputStream(InputStream in){
super(in);
}
public static Stringreadline(BufferedReader br) throws IOException {
char[] data = new char[1024];
int read = -1;
int off = 0;
while ( (read = br.read(data, off, 1)) !=-1 ) {
if(String.valueOf(data[off]).equals("\n") ) {
off += 1;
break;
}
off += 1;
}
if (off > 0) {
return String.valueOf(data);
} else {
return null;
}
}
public static void cat(Configuration conf,String remoteFilePath) throws IOException {
FileSystem fs = FileSystem.get(conf);
PathremotePath = new Path(remoteFilePath);
FSDataInputStream in = fs.open(remotePath);
BufferedReader br = new BufferedReader(newInputStreamReader(in));
String line = null;
while ( (line =MyFSDataInputStream.readline(br)) != null ) {
System.out.println(line);
}
br.close();
in.close();
fs.close();
}
public static void main(String[] args) {
Configuration conf = new Configuration();
conf.set("fs.default.name","hdfs://localhost:9000");
String remoteFilePath ="/user/hadoop/text.txt";
try {
MyFSDataInputStream.cat(conf,remoteFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
importorg.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.*;
public class MyFSDataInputStream extendsFSDataInputStream {
public MyFSDataInputStream(InputStream in){
super(in);
}
public static Stringreadline(BufferedReader br) throws IOException {
char[] data = new char[1024];
int read = -1;
int off = 0;
while ( (read = br.read(data, off, 1)) !=-1 ) {
if(String.valueOf(data[off]).equals("\n") ) {
off += 1;
break;
}
off += 1;
}
if (off > 0) {
return String.valueOf(data);
} else {
return null;
}
}
public static void cat(Configuration conf,String remoteFilePath) throws IOException {
FileSystem fs = FileSystem.get(conf);
PathremotePath = new Path(remoteFilePath);
FSDataInputStream in = fs.open(remotePath);
BufferedReader br = new BufferedReader(newInputStreamReader(in));
String line = null;
while ( (line =MyFSDataInputStream.readline(br)) != null ) {
System.out.println(line);
}
br.close();
in.close();
fs.close();
}
public static void main(String[] args) {
Configuration conf = new Configuration();
conf.set("fs.default.name","hdfs://localhost:9000");
String remoteFilePath ="/user/hadoop/text.txt";
try {
MyFSDataInputStream.cat(conf,remoteFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}