Package org.apache.hadoop.fs

Examples of org.apache.hadoop.fs.FSDataOutputStream.sync()


    byte [] bytes = Bytes.toBytes(getName());
    // First verify that using streams all works.
    Path p = new Path(dir, getName() + ".fsdos");
    FSDataOutputStream out = fs.create(p);
    out.write(bytes);
    out.sync();
    FSDataInputStream in = fs.open(p);
    assertTrue(in.available() > 0);
    byte [] buffer = new byte [1024];
    int read = in.read(buffer);
    assertEquals(bytes.length, read);
View Full Code Here


      stm.close();
      // open the file again for append
      stm = fs.append(fileToAppend);
      int mid = rawData.length - 1;
      stm.write(rawData, 1, mid - 1);
      stm.sync();

      /*
       * wait till token used in stm expires
       */
      Token<BlockTokenIdentifier> token = DFSTestUtil.getAccessToken(stm);
View Full Code Here

      FSDataOutputStream stm = writeFile(fs, fileToWrite, (short) numDataNodes,
          BLOCK_SIZE);
      // write a partial block
      int mid = rawData.length - 1;
      stm.write(rawData, 0, mid);
      stm.sync();

      /*
       * wait till token used in stm expires
       */
      Token<BlockTokenIdentifier> token = DFSTestUtil.getAccessToken(stm);
View Full Code Here

    try {
      // create a new file.
      FSDataOutputStream stm = fs.create(p);
      stm.write(1);
      stm.sync();
      stm.write(2);
      stm.close();

      // verify that entire file is good
      FSDataInputStream in = fs.open(p);
View Full Code Here

      Path file1 = new Path(dir, "file1");
      FSDataOutputStream stm1 = TestFileCreation.createFile(fs, file1, 1);
      System.out.println("testFileCreationDeleteParent: "
          + "Created file " + file1);
      TestFileCreation.writeFile(stm1, 1000);
      stm1.sync();

      // create file2.
      Path file2 = new Path("/file2");
      FSDataOutputStream stm2 = TestFileCreation.createFile(fs, file2, 1);
      System.out.println("testFileCreationDeleteParent: "
View Full Code Here

      Path file2 = new Path("/file2");
      FSDataOutputStream stm2 = TestFileCreation.createFile(fs, file2, 1);
      System.out.println("testFileCreationDeleteParent: "
          + "Created file " + file2);
      TestFileCreation.writeFile(stm2, 1000);
      stm2.sync();

      // rm dir
      fs.delete(dir, true);

      // restart cluster with the same namenode port as before.
View Full Code Here

    Path file1 = new Path("/unfinished-block");
    FSDataOutputStream out = fileSystem.create(file1);

    int writeSize = blockSize / 2;
    out.write(DFSTestUtil.generateSequentialBytes(0, writeSize));
    out.sync();
   
    FSDataInputStream in = fileSystem.open(file1);
   
    byte[] buf = new byte[4096];
    in.readFully(0, buf);
View Full Code Here

    Path srcPath = new Path(src);
    Path dstPath = new Path(dst);
    FSDataOutputStream fos = fs.create(srcPath);
  
    AppendTestUtil.write(fos, 0, writeSize);
    fos.sync();
   
    // renaming a file out from under a client will cause close to fail
    // and result in the lease remaining while the blocks are finalized on
    // the DNs
    fs.rename(srcPath, dstPath);
View Full Code Here

  private FSDataOutputStream writeFileAndSync(FileSystem fs, Path src,
      String fileContent) throws IOException {
    FSDataOutputStream fo = fs.create(src);
    fo.writeBytes(fileContent);
    fo.sync();
    return fo;
  }
}
View Full Code Here

    System.out.println("size=" + size);
    stm.write(buffer, 0, size);

    // sync file
    AppendTestUtil.LOG.info("sync");
    stm.sync();
    if (triggerSoftLease) {
      AppendTestUtil.LOG.info("leasechecker.interruptAndJoin()");
      dfs.dfs.getLeaseRenewer().interruptAndJoin();
    }
    return filepath;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.