Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: Java | Size: 1.49 KB | Hits: 66 | Expires: Never
Copy text to clipboard
  1.      Path file1 = new Path("/simpleAppend.dat");
  2.         FSDataOutputStream stm = AppendTestUtil.createFile(fs, file1, 1);
  3.         System.out.println("Created file simpleAppend.dat");
  4.  
  5.         // write to file
  6.         int mid = 186;   // io.bytes.per.checksum bytes
  7.         System.out.println("Writing " + mid + " bytes to file " + file1);
  8.         stm.write(fileContents, 0, mid);
  9.         stm.close();
  10.         System.out.println("Wrote and Closed first part of file.");
  11.  
  12.         // write to file
  13.         int mid2 = 607;   // io.bytes.per.checksum bytes
  14.         System.out.println("Writing " + mid + " bytes to file " + file1);
  15.         stm = fs.append(file1);
  16.         stm.write(fileContents, mid, mid2-mid);
  17.         stm.close();
  18.         System.out.println("Wrote and Closed second part of file.");
  19.  
  20.         // write the remainder of the file
  21.         stm = fs.append(file1);
  22.  
  23.         // ensure getPos is set to reflect existing size of the file
  24.         assertTrue(stm.getPos() > 0);
  25.  
  26.         System.out.println("Writing " + (AppendTestUtil.FILE_SIZE - mid2) +
  27.             " bytes to file " + file1);
  28.         stm.write(fileContents, mid2, AppendTestUtil.FILE_SIZE - mid2);
  29.         System.out.println("Written second part of file");
  30.         stm.close();
  31.         System.out.println("Wrote and Closed second part of file.");
  32.  
  33.         // verify that entire file is good
  34.         AppendTestUtil.checkFullFile(fs, file1, AppendTestUtil.FILE_SIZE,
  35.             fileContents, "Read 2");
  36.       }