热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

javafilesystem追加_JavaDistributedFileSystem.append方法代码示例

importorg.apache.hadoop.hdfs.DistributedFileSystem;导入方法依赖的package包类privatevoidtestHSyncOpe

import org.apache.hadoop.hdfs.DistributedFileSystem; //导入方法依赖的package包/类

private void testHSyncOperation(boolean testWithAppend) throws IOException {

Configuration cOnf= new HdfsConfiguration();

MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();

final DistributedFileSystem fs = cluster.getFileSystem();

final Path p = new Path("/testHSync/foo");

final int len = 1 <<16;

FSDataOutputStream out = fs.create(p, FsPermission.getDefault(),

EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE, CreateFlag.SYNC_BLOCK),

4096, (short) 1, len, null);

if (testWithAppend) {

// re-open the file with append call

out.close();

out = fs.append(p, EnumSet.of(CreateFlag.APPEND, CreateFlag.SYNC_BLOCK),

4096, null);

}

out.hflush();

// hflush does not sync

checkSyncMetric(cluster, 0);

out.hsync();

// hsync on empty file does nothing

checkSyncMetric(cluster, 0);

out.write(1);

checkSyncMetric(cluster, 0);

out.hsync();

checkSyncMetric(cluster, 1);

// avoiding repeated hsyncs is a potential future optimization

out.hsync();

checkSyncMetric(cluster, 2);

out.hflush();

// hflush still does not sync

checkSyncMetric(cluster, 2);

out.close();

// close is sync&#39;ing

checkSyncMetric(cluster, 3);

// same with a file created with out SYNC_BLOCK

out = fs.create(p, FsPermission.getDefault(),

EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),

4096, (short) 1, len, null);

out.hsync();

checkSyncMetric(cluster, 3);

out.write(1);

checkSyncMetric(cluster, 3);

out.hsync();

checkSyncMetric(cluster, 4);

// repeated hsyncs

out.hsync();

checkSyncMetric(cluster, 5);

out.close();

// close does not sync (not opened with SYNC_BLOCK)

checkSyncMetric(cluster, 5);

cluster.shutdown();

}



推荐阅读
author-avatar
手机用户2502921293
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有