Beispiel #1
0
        // open a stream for read access
        private Stream OpenMemoryStreamForRead(string path)
        {
            // check for the stream and return it
            if (m_streams.ContainsKey(path))
            {
                // grab the stream
                SiteStorageMemoryStream stream = m_streams[path] as SiteStorageMemoryStream;

                // confirm that the stream was closed prior to being opened for reading
                if (stream.FinalLength != -1)
                {
                    // return a new stream based on the buffer in the already
                    // written to stream
                    return(new MemoryStream(stream.GetBuffer(), 0, stream.FinalLength, false));
                }

                // user writing the stream never closed it -- you can't read a stream that
                // has been written to until it has been closed
                else
                {
                    throw new SiteStorageException(
                              null, SiteStorageException.StreamNotClosed, path);
                }
            }
            else
            {
                // throw exception indicating we couldn't find the path
                throw new
                      SiteStorageException(null, SiteStorageException.PathNotFound, path);
            }
        }
Beispiel #2
0
        // open a stream for write access (overwrites existing stream if any)
        private Stream OpenMemoryStreamForWrite(string path)
        {
            // if the stream already exists then remove it
            // (issue: does memory 'leak' for a period of time here in the
            // absence of a very smart garbage collector?)
            if (m_streams.ContainsKey(path))
            {
                m_streams.Remove(path);
            }

            // create a new stream, store it away, and return a reference to it
            SiteStorageMemoryStream newStream = new SiteStorageMemoryStream();

            m_streams.Add(path, newStream);
            return(newStream);
        }
        // open a stream for write access (overwrites existing stream if any)
        private Stream OpenMemoryStreamForWrite(string path)
        {
            // if the stream already exists then remove it
            // (issue: does memory 'leak' for a period of time here in the
            // absence of a very smart garbage collector?)
            if (m_streams.ContainsKey(path))
                m_streams.Remove(path);

            // create a new stream, store it away, and return a reference to it
            SiteStorageMemoryStream newStream = new SiteStorageMemoryStream();
            m_streams.Add(path, newStream);
            return newStream;
        }