the documentation from
copyBytes
(共)
IOUtils
复制字节:
public static void copyBytes(InputStream in,
OutputStream out,
int buffSize,
boolean close) throws IOException
从一个流复制到另一个流。
参数:
in - InputStrem to read from
out - OutputStream to write to
buffSize - the size of the buffer
close - whether or not close the InputStream and OutputStream at the end. The streams are closed in the finally clause.
抛出:
IOException
因此,考虑到这些信息,我得到了这样的数据结构:
List<String> inputLinesObject = IOUtils.readLines(in, "UTF-8");
复制字节
方法
然而,以下是我调用
复制字节
方法:
IOUtils.copyBytes(in, inputLinesObject, 4096, false);
inputLinesObject
,我想把我的可扩展数组列表放在这里,它可以收集数据并将其转换为字符串格式-但我现在这样做的方式并不正确-我不知何故被卡住了-我看不到以字符串数组列表格式收集数据的正确方法(
inputSteam
这是否意味着
byteArray
?).
HDFS
and-应该(尽管目前没有)将它们输出到字符串数组列表中-最终将使用
System.out.println
.
// this concatenates output to terminal from hdfs
public static void main(String[] args) throws IOException {
// supply this as input
String uri = args[0];
// reading in from hdfs
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(uri), conf);
FSDataInputStream in = null;
// create arraylist for hdfs file to flow into
//List<String> inputLinesObject = new ArrayList<String>();
List<String> inputLinesObject = IOUtils.readLines(in, "UTF-8");
// TODO: how to make this go to a file rather than to the System.out?
try
{
in = fs.open(new Path(uri));
// The way:
IOUtils.copyBytes(in, inputLinesObject, 4096, false);
}
finally{
IOUtils.closeStream(in);
}