@@ -212,14 +212,44 @@ public static boolean deleteRegionDir(final Configuration conf, final RegionInfo
212212 */
213213 public static FSDataOutputStream create (Configuration conf , FileSystem fs , Path path ,
214214 FsPermission perm , InetSocketAddress [] favoredNodes ) throws IOException {
215+ return create (conf , fs , path , perm , favoredNodes , true );
216+ }
217+
218+ /**
219+ * Create the specified file on the filesystem. By default, this will:
220+ * <ol>
221+ * <li>overwrite the file if it exists</li>
222+ * <li>apply the umask in the configuration (if it is enabled)</li>
223+ * <li>use the fs configured buffer size (or 4096 if not set)</li>
224+ * <li>use the configured column family replication or default replication if
225+ * {@link ColumnFamilyDescriptorBuilder#DEFAULT_DFS_REPLICATION}</li>
226+ * <li>use the default block size</li>
227+ * <li>not track progress</li>
228+ * </ol>
229+ * @param conf configurations
230+ * @param fs {@link FileSystem} on which to write the file
231+ * @param path {@link Path} to the file to write
232+ * @param perm permissions
233+ * @param favoredNodes favored data nodes
234+ * @param isRecursiveCreate recursively create parent directories
235+ * @return output stream to the created file
236+ * @throws IOException if the file cannot be created
237+ */
238+ public static FSDataOutputStream create (Configuration conf , FileSystem fs , Path path ,
239+ FsPermission perm , InetSocketAddress [] favoredNodes , boolean isRecursiveCreate )
240+ throws IOException {
215241 if (fs instanceof HFileSystem ) {
216242 FileSystem backingFs = ((HFileSystem ) fs ).getBackingFs ();
217243 if (backingFs instanceof DistributedFileSystem ) {
218244 short replication = Short .parseShort (conf .get (ColumnFamilyDescriptorBuilder .DFS_REPLICATION ,
219245 String .valueOf (ColumnFamilyDescriptorBuilder .DEFAULT_DFS_REPLICATION )));
220- DistributedFileSystem .HdfsDataOutputStreamBuilder builder =
221- ((DistributedFileSystem ) backingFs ).createFile (path ).recursive ().permission (perm )
222- .create ();
246+ DistributedFileSystem .HdfsDataOutputStreamBuilder builder = null ;
247+ if (isRecursiveCreate ) {
248+ builder = ((DistributedFileSystem ) backingFs ).createFile (path ).recursive ()
249+ .permission (perm ).create ();
250+ } else {
251+ builder = ((DistributedFileSystem ) backingFs ).createFile (path ).permission (perm ).create ();
252+ }
223253 if (favoredNodes != null ) {
224254 builder .favoredNodes (favoredNodes );
225255 }
0 commit comments