Ejemplo n.º 1
0
 /// <summary>
 /// Reads all bytes from inputStream and writes them to
 /// outputStream. When all bytes are read,
 /// outputStream.ToByteBuffer is called and obtained
 /// NativePooledByteBuffer is returned.
 /// </summary>
 /// <param name="inputStream">
 /// The input stream to read from.
 /// </param>
 /// <param name="outputStream">
 /// The output stream used to transform content of input
 /// stream to NativePooledByteBuffer.
 /// </param>
 /// <returns>
 /// An instance of NativePooledByteBuffer.
 /// </returns>
 /// <exception cref="IOException">
 /// An I/O error occurs.
 /// </exception>
 internal IPooledByteBuffer NewByteBuf(
     Stream inputStream,
     NativePooledByteBufferOutputStream outputStream)
 {
     _pooledByteStreams.Copy(inputStream, outputStream);
     return(outputStream.ToByteBuffer());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new NativePooledByteBuffer instance by reading
        /// in the entire contents of the input stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to read from.
        /// </param>
        /// <returns>
        /// An instance of the NativePooledByteBuffer.
        /// </returns>
        /// <exception cref="IOException">
        /// An I/O error occurs.
        /// </exception>
        public IPooledByteBuffer NewByteBuffer(Stream inputStream)
        {
            NativePooledByteBufferOutputStream outputStream =
                new NativePooledByteBufferOutputStream(_pool);

            try
            {
                return(NewByteBuf(inputStream, outputStream));
            }
            finally
            {
                outputStream.Dispose();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new NativePooledByteBuffer instance by reading
        /// in the entire contents of the byte array.
        /// </summary>
        /// <param name="bytes">
        /// The byte array to read from.
        /// </param>
        /// <returns>
        /// An instance of the NativePooledByteBuffer.
        /// </returns>
        public IPooledByteBuffer NewByteBuffer(byte[] bytes)
        {
            NativePooledByteBufferOutputStream outputStream =
                new NativePooledByteBufferOutputStream(_pool, bytes.Length);

            try
            {
                outputStream.Write(bytes, 0, bytes.Length);
                return(outputStream.ToByteBuffer());
            }
            catch (IOException)
            {
                throw;
            }
            finally
            {
                outputStream.Dispose();
            }
        }