|
@@ -24,6 +24,7 @@ import java.io.OutputStream;
|
|
|
import java.net.URI;
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.EnumSet;
|
|
|
import java.util.HashSet;
|
|
@@ -35,6 +36,8 @@ import java.util.Stack;
|
|
|
import java.util.TreeSet;
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
+import javax.annotation.Nonnull;
|
|
|
+
|
|
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
@@ -694,6 +697,69 @@ public class FileContext {
|
|
|
}.resolve(this, absF);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * {@link FSDataOutputStreamBuilder} for {@liink FileContext}.
|
|
|
+ */
|
|
|
+ private static final class FCDataOutputStreamBuilder extends
|
|
|
+ FSDataOutputStreamBuilder<
|
|
|
+ FSDataOutputStream, FCDataOutputStreamBuilder> {
|
|
|
+ private final FileContext fc;
|
|
|
+
|
|
|
+ private FCDataOutputStreamBuilder(
|
|
|
+ @Nonnull FileContext fc, @Nonnull Path p) throws IOException {
|
|
|
+ super(fc, p);
|
|
|
+ this.fc = fc;
|
|
|
+ Preconditions.checkNotNull(fc);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FCDataOutputStreamBuilder getThisBuilder() {
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FSDataOutputStream build() throws IOException {
|
|
|
+ final EnumSet<CreateFlag> flags = getFlags();
|
|
|
+ List<CreateOpts> createOpts = new ArrayList<>(Arrays.asList(
|
|
|
+ CreateOpts.blockSize(getBlockSize()),
|
|
|
+ CreateOpts.bufferSize(getBufferSize()),
|
|
|
+ CreateOpts.repFac(getReplication()),
|
|
|
+ CreateOpts.perms(getPermission())
|
|
|
+ ));
|
|
|
+ if (getChecksumOpt() != null) {
|
|
|
+ createOpts.add(CreateOpts.checksumParam(getChecksumOpt()));
|
|
|
+ }
|
|
|
+ if (getProgress() != null) {
|
|
|
+ createOpts.add(CreateOpts.progress(getProgress()));
|
|
|
+ }
|
|
|
+ if (isRecursive()) {
|
|
|
+ createOpts.add(CreateOpts.createParent());
|
|
|
+ }
|
|
|
+ return fc.create(getPath(), flags,
|
|
|
+ createOpts.toArray(new CreateOpts[0]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a {@link FSDataOutputStreamBuilder} for creating or overwriting
|
|
|
+ * a file on indicated path.
|
|
|
+ *
|
|
|
+ * @param f the file path to create builder for.
|
|
|
+ * @return {@link FSDataOutputStreamBuilder} to build a
|
|
|
+ * {@link FSDataOutputStream}.
|
|
|
+ *
|
|
|
+ * Upon {@link FSDataOutputStreamBuilder#build()} being invoked,
|
|
|
+ * builder parameters will be verified by {@link FileContext} and
|
|
|
+ * {@link AbstractFileSystem#create}. And filesystem states will be modified.
|
|
|
+ *
|
|
|
+ * Client should expect {@link FSDataOutputStreamBuilder#build()} throw the
|
|
|
+ * same exceptions as create(Path, EnumSet, CreateOpts...).
|
|
|
+ */
|
|
|
+ public FSDataOutputStreamBuilder<FSDataOutputStream, ?> create(final Path f)
|
|
|
+ throws IOException {
|
|
|
+ return new FCDataOutputStreamBuilder(this, f).create();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Make(create) a directory and all the non-existent parents.
|
|
|
*
|