/** 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); } }
/* * 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(); }
public static void createFile(FileContext fc, Path path) throws IOException { createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.createParent()); }
public static void createFile(FileContext fc, Path path, int numBlocks, int blockSize) throws IOException { createFile(fc, path, numBlocks, CreateOpts.blockSize(blockSize), CreateOpts.createParent()); }
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(); }