/// <summary>
        /// Gets a media contents of a member resource.
        /// </summary>
        /// <param name="collectionName">Name of the target collection.</param>
        /// <param name="memberResourceId">The Id of the member resource.</param>
        /// <param name="outputStream">A stream containing the media corresponding to the specified resource. If no matching media is found, null is returned.</param>
        /// <exception cref="ArgumentNullException">Throws exception if memberResourceId is null/empty
        /// or outputStream is null.</exception>
        /// <exception cref="ArgumentException">Throws exception if outputStream stream is not readable.</exception>
        void IAtomPubStoreReader.GetMedia(string collectionName, string memberResourceId, Stream outputStream)
        {
            if (string.IsNullOrEmpty(collectionName))
            {
                throw new ArgumentNullException("collectionName");
            }

            if (string.IsNullOrEmpty(memberResourceId))
            {
                throw new ArgumentNullException("memberResourceId");
            }

            if (null == outputStream)
            {
                throw new ArgumentNullException("outputStream");
            }

            if (!AtomPubHelper.IsValidGuid(memberResourceId))
            {
                throw new ArgumentException(Resources.ATOMPUB_INVALID_RESOURCE_ID);
            }

            if (!outputStream.CanWrite)
            {
                throw new ArgumentException(Properties.Resources.ATOMPUB_CANNOT_WRITE_ON_STREAM, "outputStream");
            }

            using (ZentityContext context = CoreHelper.CreateZentityContext())
            {
                ResourceType collectionType = coreHelper.GetResourceType(collectionName);

                // Prepare a query to get a resource with specified Id and specified type.
                string commandText = string.Format(CultureInfo.InvariantCulture, AtomPubConstants.EsqlToGetFileContents,
                                                   collectionType.FullName);

                ObjectQuery <Core.File> query = new ObjectQuery <Core.File>(commandText, context);
                query.Parameters.Add(new ObjectParameter("Id", new Guid(memberResourceId)));
                Core.File mediaFile = query.FirstOrDefault();

                if (null == mediaFile)
                {
                    throw new ResourceNotFoundException(Resources.ATOMPUB_RESOURCE_NOT_FOUND);
                }

                if (!mediaFile.Authorize("Read", context, CoreHelper.GetAuthenticationToken()))
                {
                    throw new UnauthorizedException(Resources.ATOMPUB_UNAUTHORIZED);
                }

                context.DownloadFileContent(mediaFile, outputStream);
            }
        }