我有一个BufferedWriter
如下所示:
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new GZIPOutputStream( hdfs.create(filepath, true ))));
String line = "text";
writer.write(line);
我想找出写入文件的字节,而不像查询文件一样
hdfs = FileSystem.get( new URI( "hdfs://localhost:8020" ), configuration );
filepath = new Path("path");
hdfs.getFileStatus(filepath).getLen();
因为它会增加开销,但我不希望这样。
我也不能这样做:
line.getBytes().length;
因为它给出了压缩前的大小。
您可以使用计数输出流来自 Apache Commons IO 库。
将其放置在 GZIPOutputStream 和文件 Outputstream (hdfs.create(..)) 之间。
将内容写入文件后,您可以从 CountingOutputStream 实例中读取写入的字节数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)