Exemple #1
0
        /// <exception cref="System.IO.IOException"/>
        public override void AppendToFile(Path path, int numBlocks, params Options.CreateOpts
                                          [] options)
        {
            Options.CreateOpts.BlockSize blockSizeOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BlockSize
                                                                                   >(options);
            long blockSize = blockSizeOpt != null?blockSizeOpt.GetValue() : DefaultBlockSize;

            FSDataOutputStream @out;

            @out = fs.Append(path);
            byte[] data = GetFileData(numBlocks, blockSize);
            @out.Write(data, 0, data.Length);
            @out.Close();
        }
Exemple #2
0
        /*
         * Create files with numBlocks blocks each with block size blockSize.
         */
        /// <exception cref="System.IO.IOException"/>
        public static long CreateFile(FileContext fc, Path path, int numBlocks, params Options.CreateOpts
                                      [] options)
        {
            Options.CreateOpts.BlockSize blockSizeOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BlockSize
                                                                                   >(options);
            long blockSize = blockSizeOpt != null?blockSizeOpt.GetValue() : DefaultBlockSize;

            FSDataOutputStream @out = fc.Create(path, EnumSet.Of(CreateFlag.Create), options);

            byte[] data = GetFileData(numBlocks, blockSize);
            @out.Write(data, 0, data.Length);
            @out.Close();
            return(data.Length);
        }
Exemple #3
0
        /// <exception cref="Org.Apache.Hadoop.Security.AccessControlException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        /// <exception cref="System.IO.FileNotFoundException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.ParentNotDirectoryException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
        /// <exception cref="System.IO.IOException"/>
        public override FSDataOutputStream Create(Path f, EnumSet <CreateFlag> createFlag,
                                                  params Options.CreateOpts[] opts)
        {
            // Need to translate the FileContext-style options into FileSystem-style
            // Permissions with umask
            Options.CreateOpts.Perms permOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.Perms
                                                                          >(opts);
            FsPermission umask      = FsPermission.GetUMask(fs.GetConf());
            FsPermission permission = (permOpt != null) ? permOpt.GetValue() : FsPermission.GetFileDefault
                                          ().ApplyUMask(umask);

            permission = permission.ApplyUMask(umask);
            // Overwrite
            bool overwrite = createFlag.Contains(CreateFlag.Overwrite);
            // bufferSize
            int bufferSize = fs.GetConf().GetInt(CommonConfigurationKeysPublic.IoFileBufferSizeKey
                                                 , CommonConfigurationKeysPublic.IoFileBufferSizeDefault);

            Options.CreateOpts.BufferSize bufOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BufferSize
                                                                              >(opts);
            bufferSize = (bufOpt != null) ? bufOpt.GetValue() : bufferSize;
            // replication
            short replication = fs.GetDefaultReplication(f);

            Options.CreateOpts.ReplicationFactor repOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.ReplicationFactor
                                                                                     >(opts);
            replication = (repOpt != null) ? repOpt.GetValue() : replication;
            // blockSize
            long blockSize = fs.GetDefaultBlockSize(f);

            Options.CreateOpts.BlockSize blockOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.BlockSize
                                                                               >(opts);
            blockSize = (blockOpt != null) ? blockOpt.GetValue() : blockSize;
            // Progressable
            Progressable progress = null;

            Options.CreateOpts.Progress progressOpt = Options.CreateOpts.GetOpt <Options.CreateOpts.Progress
                                                                                 >(opts);
            progress = (progressOpt != null) ? progressOpt.GetValue() : progress;
            return(fs.Create(f, permission, overwrite, bufferSize, replication, blockSize, progress
                             ));
        }