Java Code Examples for io.netty.buffer.ByteBufInputStream#available()
The following examples show how to use
io.netty.buffer.ByteBufInputStream#available() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BufferedJestHttpClientTest.java From log4j2-elasticsearch with Apache License 2.0 | 5 votes |
@Test public void prepareRequestCreatesRequestWithSerializedBulk() throws IOException { // given ItemSource<ByteBuf> payload1 = createDefaultTestItemSource("test1"); ItemSource<ByteBuf> payload2 = createDefaultTestItemSource("test2"); BufferedBulk.Builder builder = spy(new BufferedBulk.Builder()); ByteBufItemSource buffer = new ByteBufItemSource(byteBufAllocator.buffer(32), source -> { }); builder.withBuffer(buffer); Bulk bulk = createTestBatch(builder, payload1, payload2); // when BufferedJestHttpClient client = createDefaultTestHttpClient(); HttpUriRequest request = client.prepareRequest((BufferedBulk) bulk); // then ByteBufInputStream byteBufInputStream = new ByteBufInputStream(buffer.getSource()); byte[] expectedBody = new byte[byteBufInputStream.available()]; byteBufInputStream.read(expectedBody); byteBufInputStream.reset(); HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); ByteBufInputStream content = (ByteBufInputStream) entity.getContent(); byte[] actualBody = new byte[content.available()]; content.read(actualBody); Assert.assertEquals(new String(expectedBody), new String(actualBody)); }
Example 2
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String correctHost = in.readUTF(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; return new WrongHost(requestId, segment, correctHost, serverStackTrace); }
Example 3
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; long offset = (in.available() >= Long.BYTES) ? in.readLong() : -1L; return new SegmentIsSealed(requestId, segment, serverStackTrace, offset); }
Example 4
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); long startOffset = in.readLong(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; long offset = (in.available() >= Long.BYTES) ? in.readLong() : -1L; return new SegmentIsTruncated(requestId, segment, startOffset, serverStackTrace, offset); }
Example 5
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; long offset = (in.available() >= Long.BYTES) ? in.readLong() : -1L; return new NoSuchSegment(requestId, segment, serverStackTrace, offset); }
Example 6
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { UUID writerId = new UUID(in.readLong(), in.readLong()); long eventNumber = in.readLong(); long previousEventNumber = in.available() >= Long.BYTES ? in.readLong() : -1L; long requestId = in.available() >= Long.BYTES ? in.readLong() : -1L; long currentSegmentWriteOffset = in.available() >= Long.BYTES ? in.readLong() : -1L; return new DataAppended(requestId, writerId, eventNumber, previousEventNumber, currentSegmentWriteOffset); }
Example 7
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { String segment = in.readUTF(); long offset = in.readLong(); int suggestedLength = in.readInt(); String delegationToken = in.readUTF(); long requestId = in.available() >= Long.BYTES ? in.readLong() : -1L; return new ReadSegment(segment, offset, suggestedLength, delegationToken, requestId); }
Example 8
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String target = in.readUTF(); String source = in.readUTF(); long newTargetWriteOffset = in.available() > 0 ? in.readLong() : -1; return new SegmentsMerged(requestId, target, source, newTargetWriteOffset); }
Example 9
Source File: WireCommands.java From pravega with Apache License 2.0 | 5 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; // errorCode is a new field and wasn't present earlier. Doing this to allow it to work with older clients. int errorCode = in.available() >= Integer.BYTES ? in.readInt() : -1; return new AuthTokenCheckFailed(requestId, serverStackTrace, ErrorCode.valueOf(errorCode)); }
Example 10
Source File: WireCommands.java From pravega with Apache License 2.0 | 4 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String segment = in.readUTF(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; return new SegmentAlreadyExists(requestId, segment, serverStackTrace); }
Example 11
Source File: WireCommands.java From pravega with Apache License 2.0 | 4 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { UUID writerId = new UUID(in.readLong(), in.readLong()); long eventNumber = in.readLong(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; return new InvalidEventNumber(writerId, eventNumber, serverStackTrace); }
Example 12
Source File: WireCommands.java From pravega with Apache License 2.0 | 4 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { long requestId = in.readLong(); String operationName = in.readUTF(); String serverStackTrace = (in.available() > 0) ? in.readUTF() : EMPTY_STACK_TRACE; return new OperationUnsupported(requestId, operationName, serverStackTrace); }
Example 13
Source File: WireCommands.java From pravega with Apache License 2.0 | 4 votes |
public static WireCommand readFrom(ByteBufInputStream in, int length) throws IOException { UUID writerId = new UUID(in.readLong(), in.readLong()); long offset = in.readLong(); long requestId = in.available() >= Long.BYTES ? in.readLong() : -1L; return new ConditionalCheckFailed(writerId, offset, requestId); }