示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowErrorWithRemoteAddressWhenClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowErrorWithRemoteAddressWhenClosed()
        {
            Channel          channel   = mock(typeof(Channel));
            ByteBufAllocator allocator = mock(typeof(ByteBufAllocator));

            when(allocator.buffer(anyInt())).thenReturn(Unpooled.buffer());
            when(channel.alloc()).thenReturn(allocator);
            SocketAddress remoteAddress       = mock(typeof(SocketAddress));
            string        remoteAddressString = "client.server.com:7687";

            when(remoteAddress.ToString()).thenReturn(remoteAddressString);
            when(channel.remoteAddress()).thenReturn(remoteAddress);

            ChunkedOutput output = new ChunkedOutput(channel, DEFAULT_TEST_BUFFER_SIZE, DEFAULT_TEST_BUFFER_SIZE, NO_THROTTLE);

            output.Dispose();

            try
            {
                output.WriteInt(42);
                fail("Exception expected");
            }
            catch (PackOutputClosedException e)
            {
                assertThat(e.Message, containsString(remoteAddressString));
            }
        }
示例#2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
        public override ByteBuf ReadChunk(ByteBufAllocator allocator)
        {
            if (_endOfInput)
            {
                return(null);
            }
            ByteBuf data = _byteBufAwareMarshal.readChunk(allocator);

            if (data == null)
            {
                return(null);
            }
            _endOfInput = _byteBufAwareMarshal.EndOfInput;
            CompositeByteBuf allData = new CompositeByteBuf(allocator, false, 2);

            allData.addComponent(true, data);
            try
            {
                bool    isFirstChunk     = Progress() == 0;
                int     metaDataCapacity = MetadataSize(isFirstChunk);
                ByteBuf metaDataBuffer   = allocator.buffer(metaDataCapacity, metaDataCapacity);
                allData.addComponent(true, 0, WriteMetadata(isFirstChunk, _byteBufAwareMarshal.EndOfInput, _contentType, metaDataBuffer));
                _progress += allData.readableBytes();
                Debug.Assert(_progress > 0);                           // logic relies on this
                return(allData);
            }
            catch (Exception e)
            {
                allData.release();
                throw e;
            }
        }
示例#3
0
            public override ByteBuf ReadChunk(ByteBufAllocator allocator)
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                int?size = Sizes.next();

                if (size == null)
                {
                    return(null);
                }
                return(allocator.buffer(size).writerIndex(size));
            }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public io.netty.buffer.ByteBuf readChunk(io.netty.buffer.ByteBufAllocator allocator) throws Exception
            public override ByteBuf ReadChunk(ByteBufAllocator allocator)
            {
                if (IsEndOfInput)
                {
                    return(null);
                }
                ByteBuf buffer = allocator.buffer();

                Marshaller.accept(new BoundedNetworkWritableChannel(buffer));
                IsEndOfInput = true;
                Offset       = buffer.readableBytes();
                return(buffer);
            }
示例#5
0
        public override ByteBuf ReadChunk(ByteBufAllocator allocator)
        {
            _hasRead = true;
            if (EndOfInput)
            {
                return(null);
            }
            int     toWrite = Math.Min(Available(), _chunkSize);
            ByteBuf buffer  = allocator.buffer(toWrite);

            try
            {
                buffer.writeBytes(_content, _pos, toWrite);
                _pos += toWrite;
                return(buffer);
            }
            catch (Exception t)
            {
                buffer.release();
                throw t;
            }
        }
示例#6
0
 public override ByteBuf Buffer()
 {
     return(Add(_allocator.buffer()));
 }
示例#7
0
 private ByteBuf AllocateNewBuffer()
 {
     return(_allocator.buffer(_initSize, _maxChunkSize));
 }