ExistsWithBucketCheck() private method

private ExistsWithBucketCheck ( bool &bucketExists ) : bool
bucketExists bool
return bool
Exemplo n.º 1
0
        internal S3FileStream(AmazonS3 s3Client, string bucket, string key, FileMode mode, FileAccess access, int buffersize)
        {
            file        = new S3FileInfo(s3Client, bucket, key);
            buffer      = new MemoryStream(buffersize);
            this.mode   = mode;
            this.access = access;

            fileExist = file.ExistsWithBucketCheck(out bucketExist);

            if ((access & FileAccess.Read) != FileAccess.Read)
            {
                canRead = false;
            }
            if ((access & FileAccess.Write) != FileAccess.Write)
            {
                canWrite = false;
            }

            switch (mode)
            {
            case FileMode.Append:
                if ((access & FileAccess.Write) != FileAccess.Write)
                {
                    throw new ArgumentException("Append requires Write access");
                }
                PopulateData();
                buffer.Seek(0, SeekOrigin.End);
                startPosition = buffer.Position;
                break;

            case FileMode.Create:
                if ((access & FileAccess.Write) != FileAccess.Write)
                {
                    throw new ArgumentException("Create requires Write access");
                }
                break;

            case FileMode.CreateNew:
                if (fileExist)
                {
                    throw new IOException("CreateNew requires the file not to already exist");
                }
                if ((access & FileAccess.Write) != FileAccess.Write)
                {
                    throw new ArgumentException("Create requires Write access");
                }
                break;

            case FileMode.Open:
                if (!fileExist)
                {
                    throw new IOException("Open requires the file to already exist");
                }
                PopulateData();
                break;

            case FileMode.OpenOrCreate:
                if (fileExist)
                {
                    if ((access & FileAccess.Write) != FileAccess.Write)
                    {
                        throw new ArgumentException("Create requires Write access");
                    }
                }
                break;

            case FileMode.Truncate:
                if (!fileExist)
                {
                    throw new IOException("Truncate requires the file to already exist");
                }
                if ((access & FileAccess.Write) != FileAccess.Write)
                {
                    throw new ArgumentException("Truncate requires Write access");
                }
                break;

            default:
                throw new ArgumentException("Invalid value", "mode");
            }
        }
Exemplo n.º 2
0
        internal S3FileStream(AmazonS3 s3Client, string bucket, string key, FileMode mode, FileAccess access, int buffersize)
        {
            file = new S3FileInfo(s3Client, bucket, key);
            buffer = new MemoryStream(buffersize);
            this.mode = mode;
            this.access = access;

            fileExist = file.ExistsWithBucketCheck(out bucketExist);

            if ((access & FileAccess.Read) != FileAccess.Read)
            {
                canRead = false;
            }
            if ((access & FileAccess.Write) != FileAccess.Write)
            {
                canWrite = false;
            }

            switch (mode)
            {
                case FileMode.Append:
                    if ((access & FileAccess.Write) != FileAccess.Write)
                    {
                        throw new ArgumentException("Append requires Write access");
                    }
                    PopulateData();
                    buffer.Seek(0, SeekOrigin.End);
                    startPosition = buffer.Position;
                    break;

                case FileMode.Create:
                    if ((access & FileAccess.Write) != FileAccess.Write)
                    {
                        throw new ArgumentException("Create requires Write access");
                    }
                    break;

                case FileMode.CreateNew:
                    if (fileExist)
                    {
                        throw new IOException("CreateNew requires the file not to already exist");
                    }
                    if ((access & FileAccess.Write) != FileAccess.Write)
                    {
                        throw new ArgumentException("Create requires Write access");
                    }
                    break;

                case FileMode.Open:
                    if (!fileExist)
                    {
                        throw new IOException("Open requires the file to already exist");
                    }
                    PopulateData();
                    break;

                case FileMode.OpenOrCreate:
                    if (fileExist)
                    {
                        if ((access & FileAccess.Write) != FileAccess.Write)
                        {
                            throw new ArgumentException("Create requires Write access");
                        }
                    }
                    break;

                case FileMode.Truncate:
                    if (!fileExist)
                    {
                        throw new IOException("Truncate requires the file to already exist");
                    }
                    if ((access & FileAccess.Write) != FileAccess.Write)
                    {
                        throw new ArgumentException("Truncate requires Write access");
                    }
                    break;

                default:
                    throw new ArgumentException("Invalid value", "mode");
            }
        }