@Test public void testExecute() throws Exception { String filePath = "/testWriteFile/fadsfa/213"; long size = 10000; writeFile(filePath, size); HdfsFileStatus fileStatus = dfs.getClient().getFileInfo(filePath); Assert.assertTrue(fileStatus.getLen() == size); }
@Override protected void execute() throws Exception { if (filePath == null) { throw new IllegalArgumentException("File parameter is missing! "); } if (length == -1) { throw new IllegalArgumentException("Write Action provides wrong length! "); } appendLog( String.format( "Action starts at %s : Write %s with length %s", Utils.getFormatedCurrentTime(), filePath, length)); Path path = new Path(filePath); FileSystem fileSystem = path.getFileSystem(conf); int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication(); final FSDataOutputStream out = fileSystem.create(path, true, replication); byte[] buffer = new byte[bufferSize]; new Random().nextBytes(buffer); appendLog(String.format("Generate random data with length %d", length)); for (long pos = 0; pos < length; pos += bufferSize) { long writeLength = pos + bufferSize < length ? bufferSize : length - pos; out.write(buffer, 0, (int) writeLength); } out.close(); appendLog("Write Successfully!"); }
WriteFileAction extends HdfsAction { @Override protected void execute() throws Exception { if (filePath == null) { throw new IllegalArgumentException("File parameter is missing! "); } if (length == -1) { throw new IllegalArgumentException("Write Action provides wrong length! "); } appendLog( String.format( "Action starts at %s : Write %s with length %s", Utils.getFormatedCurrentTime(), filePath, length)); Path path = new Path(filePath); FileSystem fileSystem = path.getFileSystem(conf); int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication(); final FSDataOutputStream out = fileSystem.create(path, true, replication); byte[] buffer = new byte[bufferSize]; new Random().nextBytes(buffer); appendLog(String.format("Generate random data with length %d", length)); for (long pos = 0; pos < length; pos += bufferSize) { long writeLength = pos + bufferSize < length ? bufferSize : length - pos; out.write(buffer, 0, (int) writeLength); } out.close(); appendLog("Write Successfully!"); } }
WriteFileAction extends HdfsAction { @Override protected void execute() throws Exception { if (filePath == null) { throw new IllegalArgumentException("File parameter is missing! "); } if (length == -1) { throw new IllegalArgumentException("Write Action provides wrong length! "); } appendLog( String.format( "Action starts at %s : Write %s with length %s", Utils.getFormatedCurrentTime(), filePath, length)); Path path = new Path(filePath); FileSystem fileSystem = path.getFileSystem(conf); int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication(); final FSDataOutputStream out = fileSystem.create(path, true, replication); byte[] buffer = new byte[bufferSize]; new Random().nextBytes(buffer); appendLog(String.format("Generate random data with length %d", length)); for (long pos = 0; pos < length; pos += bufferSize) { long writeLength = pos + bufferSize < length ? bufferSize : length - pos; out.write(buffer, 0, (int) writeLength); } out.close(); appendLog("Write Successfully!"); }  }
WriteFileAction extends HdfsAction { @Override protected void execute() throws Exception { if (filePath == null) { throw new IllegalArgumentException("File parameter is missing! "); } if (length == -1) { throw new IllegalArgumentException("Write Action provides wrong length! "); } appendLog( String.format( "Action starts at %s : Write %s with length %s", Utils.getFormatedCurrentTime(), filePath, length)); Path path = new Path(filePath); FileSystem fileSystem = path.getFileSystem(conf); int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication(); final FSDataOutputStream out = fileSystem.create(path, true, replication); byte[] buffer = new byte[bufferSize]; new Random().nextBytes(buffer); appendLog(String.format("Generate random data with length %d", length)); for (long pos = 0; pos < length; pos += bufferSize) { long writeLength = pos + bufferSize < length ? bufferSize : length - pos; out.write(buffer, 0, (int) writeLength); } out.close(); appendLog("Write Successfully!"); }  @Override void init(Map<String, String> args); }
WriteFileAction extends HdfsAction { @Override protected void execute() throws Exception { if (filePath == null) { throw new IllegalArgumentException("File parameter is missing! "); } if (length == -1) { throw new IllegalArgumentException("Write Action provides wrong length! "); } appendLog( String.format( "Action starts at %s : Write %s with length %s", Utils.getFormatedCurrentTime(), filePath, length)); Path path = new Path(filePath); FileSystem fileSystem = path.getFileSystem(conf); int replication = fileSystem.getServerDefaults(new Path(filePath)).getReplication(); final FSDataOutputStream out = fileSystem.create(path, true, replication); byte[] buffer = new byte[bufferSize]; new Random().nextBytes(buffer); appendLog(String.format("Generate random data with length %d", length)); for (long pos = 0; pos < length; pos += bufferSize) { long writeLength = pos + bufferSize < length ? bufferSize : length - pos; out.write(buffer, 0, (int) writeLength); } out.close(); appendLog("Write Successfully!"); }  @Override void init(Map<String, String> args); static final String LENGTH; static final String BUF_SIZE; }