コード例 #1
0
ファイル: LoadGenerator.java プロジェクト: FloodDragon/hadoop
    /** Create a file with a length of <code>fileSize</code>. The file is filled with 'a'. */
    private void genFile(Path file, long fileSize) throws IOException {
      long startTime = Time.now();
      FSDataOutputStream out = null;
      try {
        out =
            fc.create(
                file,
                EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),
                CreateOpts.createParent(),
                CreateOpts.bufferSize(4096),
                CreateOpts.repFac((short) 3));
        executionTime[CREATE] += (Time.now() - startTime);
        numOfOps[CREATE]++;

        long i = fileSize;
        while (i > 0) {
          long s = Math.min(fileSize, WRITE_CONTENTS.length);
          out.write(WRITE_CONTENTS, 0, (int) s);
          i -= s;
        }

        startTime = Time.now();
        executionTime[WRITE_CLOSE] += (Time.now() - startTime);
        numOfOps[WRITE_CLOSE]++;
      } finally {
        IOUtils.cleanup(LOG, out);
      }
    }
コード例 #2
0
 /*
  * Create files with numBlocks blocks each with block size blockSize.
  */
 public static void createFile(FileContext fc, Path path, int numBlocks, CreateOpts... options)
     throws IOException {
   BlockSize blockSizeOpt = (BlockSize) CreateOpts.getOpt(CreateOpts.BlockSize.class, options);
   long blockSize = blockSizeOpt != null ? blockSizeOpt.getValue() : DEFAULT_BLOCK_SIZE;
   FSDataOutputStream out = fc.create(path, EnumSet.of(CreateFlag.CREATE), options);
   byte[] data = getFileData(numBlocks, blockSize);
   out.write(data, 0, data.length);
   out.close();
 }
コード例 #3
0
 public static void createFile(FileContext fc, Path path) throws IOException {
   createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.createParent());
 }
コード例 #4
0
 public static void createFile(FileContext fc, Path path, int numBlocks, int blockSize)
     throws IOException {
   createFile(fc, path, numBlocks, CreateOpts.blockSize(blockSize), CreateOpts.createParent());
 }
コード例 #5
0
 public static void writeFile(FileContext fc, Path path, byte b[]) throws IOException {
   FSDataOutputStream out =
       fc.create(path, EnumSet.of(CreateFlag.CREATE), CreateOpts.createParent());
   out.write(b);
   out.close();
 }