@@ -0,0 +1,2537 @@
+/**%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements. See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership. The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License. You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage hdfs.jsr203;%0A%0Aimport java.io.BufferedWriter;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.net.URI;%0Aimport java.nio.charset.Charset;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0A%0Aimport org.apache.hadoop.conf.Configuration;%0Aimport org.apache.hadoop.fs.FileUtil;%0Aimport org.apache.hadoop.hdfs.MiniDFSCluster;%0Aimport org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Apublic class TestDocUseCases %7B%0A%0A%09private static MiniDFSCluster cluster;%0A%09private static URI clusterUri;%0A%0A%09@BeforeClass%0A%09public static void setUpBeforeClass() throws Exception %7B%0A%09%09cluster = startMini(TestFileSystem.class.getName());%0A%09%09clusterUri = cluster.getFileSystem().getUri();%0A%09%7D%0A%0A%09@AfterClass%0A%09public static void teardownClass() throws Exception %7B%0A%09%09if (cluster != null) %7B%0A%09%09%09cluster.shutdown();%0A%09%09%7D%0A%09%7D%0A%0A%09private static MiniDFSCluster startMini(String testName) throws IOException %7B%0A%09%09File baseDir = new File(%22./target/hdfs/%22 + testName).getAbsoluteFile();%0A%09%09FileUtil.fullyDelete(baseDir);%0A%09%09Configuration conf = new Configuration();%0A%09%09conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath());%0A%09%09MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf);%0A%09%09MiniDFSCluster hdfsCluster = builder.clusterId(testName).build();%0A%09%09hdfsCluster.waitActive();%0A%09%09return hdfsCluster;%0A%09%7D%0A%0A%09@Test%0A%09public void testWriteBuffered() throws IOException %7B%0A%09%09Path rootPath = Paths.get(clusterUri);%0A%0A%09%09Path file = rootPath.resolve(rootPath.resolve(%22temp_file.txt%22));%0A%0A%09%09Charset charset = Charset.forName(%22US-ASCII%22);%0A%09%09String s = %22this is a test%22;%0A%09%09BufferedWriter writer = Files.newBufferedWriter(file, charset);%0A%09%09writer.write(s, 0, s.length());%0A%09%09writer.close();%0A%09%7D%0A%09%0A%09%0A%0A%7D%0A

Add more unit test from Oracle NIO documentation.