HDFS-LocalFileSystem
LocalFileSystem
Hadoop LocalFileSystem是客户端校验的类。在使用LocalFileSystem写文件时,会透明的创建一个.filename.crc的文件。校验文件大小的字节数由io.bytes.per.checksum属性设置,默认是512bytes,即每512字节就生成一个CRC-32校验和。
.filename.crc文件会存 io.bytes.per.checksum的信息。在读取的时候,会根据此文件进行校验。
事实上LocalFileSystem是通过继承ChecksumFileSystem实现校验的工作。
写例子:
package com.bigdata.io; import java.io.IOException; import java.io.OutputStream; import java.net.URI; import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.LocalFileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.RawLocalFileSystem; public class WriteToLocal { public static void main(String[] args) throws IOException, URISyntaxException { Configuration conf = new Configuration(); LocalFileSystem fs = new LocalFileSystem(new RawLocalFileSystem()); fs.initialize(new URI("file:///home/peter/abc1"), conf); // put the conf object to filesystem instance OutputStream out = fs.create(new Path("file:///home/peter/abc1")); for(int i = 0; i < 512*10;i++){ out.write(97); } out.close(); Path file = fs.getChecksumFile(new Path("file:///home/peter/abc1")); System.out.println(file.getName()); fs.close(); } }
相关推荐
minerd 2020-10-28
Kafka 2020-09-18
Wepe0 2020-10-30
杜倩 2020-10-29
windle 2020-10-29
mengzuchao 2020-10-22
Junzizhiai 2020-10-10
bxqybxqy 2020-09-30
风之沙城 2020-09-24
kingszelda 2020-09-22
大唐帝国前营 2020-08-18
yixu0 2020-08-17
TangCuYu 2020-08-15
xiaoboliu00 2020-08-15
songshijiazuaa 2020-08-15
xclxcl 2020-08-03
zmzmmf 2020-08-03
newfarhui 2020-08-03
likesyour 2020-08-01