Example usage for org.apache.hadoop.fs FileSystem createNewFile

List of usage examples for org.apache.hadoop.fs FileSystem createNewFile

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileSystem createNewFile.

Prototype

public boolean createNewFile(Path f) throws IOException 

Source Link

Document

Creates the given Path as a brand-new zero-length file.

Usage

From source file:org.deeplearning4j.listeners.SparkScoreIterationListener.java

License:Apache License

public SparkScoreIterationListener(int printIterations, String pathStr) {
    this.printIterations = printIterations;
    this.pathStr = pathStr;
    FileSystem nfs = CommonUtils.openHdfsConnect();

    try {/*www  .jav a 2 s. c om*/
        Path path = new Path(pathStr);
        if (!nfs.exists(path)) {
            nfs.createNewFile(path);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        CommonUtils.closeHdfsConnect(nfs);
    }
}

From source file:org.shaf.core.process.ProcessExecutorTest.java

License:Apache License

/**
 * Perform pre-test initialization./*from  w  w w . j a v a 2s . c om*/
 * 
 * @throws Exception
 *             if the initialization fails for some reason
 */
@Before
public void setUp() throws Exception {
    FileSystem fs = IOUtils.getLocalFileSystem();

    Path inputDir = new Path(System.getProperty("java.io.tmpdir"), "some/input");
    if (!fs.exists(inputDir)) {
        fs.mkdirs(inputDir);
        fs.createNewFile(new Path(inputDir, "part"));
    }
}

From source file:org.trustedanalytics.utils.hdfs.HdfsConfigFactoryTest.java

License:Apache License

private void verifyFileSystem(FileSystem fs) throws IOException {
    fs.createNewFile(new Path(SOME_FILE_NAME));
    RemoteIterator<LocatedFileStatus> files = fs.listFiles(hdfsConfig.getPath(), false);
    assertThat("Creating file failed", files.hasNext(), equalTo(true));
    LocatedFileStatus remoteFile = files.next();
    assertThat("file wasn't created in proper folder", remoteFile.getPath().toUri().toString(),
            containsString(hdfsConfig.getPath().toUri().toString()));
    assertThat("file wasn't created in proper folder", remoteFile.getPath().toUri().toString(),
            containsString(SOME_FILE_NAME));
    assertThat("More then 1 file was created", files.hasNext(), equalTo(false));
    testAppendFunction(fs, remoteFile);//w ww. j a  v a  2  s.c o m
}