Exemplo n.º 1
0
        private MemoryStream CopyInputStream()
        {
            if (InputStream.CanSeek)
            {
                InputStream.Seek(0, SeekOrigin.Begin);
            }
            MemoryStream copy = new MemoryStream();

            InputStream.CopyTo(copy);
            copy.Seek(0, SeekOrigin.Begin);
            return(copy);
        }
Exemplo n.º 2
0
        public void SaveAs(string destination, bool overwrite = false, bool autoCreateDirectory = true)
        {
            if (autoCreateDirectory)
            {
                var directory = new FileInfo(destination).Directory;
                if (directory != null)
                {
                    directory.Create();
                }
            }

            using (var file = new FileStream(destination, overwrite ? FileMode.Create : FileMode.CreateNew))
                InputStream.CopyTo(file);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Convenient method to read the InputStream and return a byte array
        /// </summary>
        /// <returns>
        /// The byte array.
        /// </returns>
        public byte[] ReadAsBytes()
        {
            MemoryStream stream;

            try {
                long length = InputStream.Length;
                stream = new MemoryStream((int)length);
            }
            catch (NotSupportedException) {
                stream = new MemoryStream();
            }
            InputStream.CopyTo(stream);
            byte[] buffer;
            if (stream.GetBuffer().LongLength != stream.Length)
            {
                buffer = new byte[stream.Length];
                Array.Copy(stream.GetBuffer(), buffer, (int)stream.Length);
            }
            else
            {
                buffer = stream.GetBuffer();
            }
            return(buffer);
        }