@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public Byte get(CompositeBuffer buffer) { return buffer.get(); } });
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public byte read() throws IOException { final byte result = compositeBuffer.get(); compositeBuffer.shrink(); return result; }
@Override public Byte getIndexed(CompositeBuffer buffer, int index) { return buffer.get(index); } }, 1);
/** * {@inheritDoc} */ public ASN1Reader skipElement() throws IOException { // Read the header if haven't done so already peekLength(); readLimiter.checkLimit(peekLength); for (int i = 0; i < peekLength; i++) { buffer.get(); } state = ELEMENT_READ_STATE_NEED_TYPE; return this; }
/** * Internal helper method reading the ASN.1 type byte and transition to the * next state if successful. * * @param ensureRead * <code>true</code> to check for availability first. * @return <code>true</code> if the type byte was successfully read * @throws IOException * If an error occurs while trying to decode an ASN1 element. */ private boolean needTypeState(final boolean ensureRead) throws IOException { // Read just the type. if (ensureRead && (readLimiter.remaining() <= 0)) { return false; } readLimiter.checkLimit(1); peekType = buffer.get(); state = ELEMENT_READ_STATE_NEED_FIRST_LENGTH_BYTE; return true; } }
public SequenceLimiter endSequence() throws IOException { parent.checkLimit(remaining()); if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINE) && remaining() > 0) { StaticUtils.DEBUG_LOG.fine(String.format( "Ignoring %d unused trailing bytes in ASN.1 SEQUENCE", remaining())); } for (int i = 0; i < remaining(); i++) { buffer.get(); } return parent; }
/** * {@inheritDoc} */ public boolean readBoolean() throws IOException { // Read the header if haven't done so already peekLength(); if (peekLength != 1) { final LocalizableMessage message = ERR_ASN1_BOOLEAN_INVALID_LENGTH.get(peekLength); throw DecodeException.fatalError(message); } readLimiter.checkLimit(peekLength); final byte readByte = buffer.get(); if (StaticUtils.DEBUG_LOG.isLoggable(Level.FINEST)) { StaticUtils.DEBUG_LOG.finest(String.format( "READ ASN.1 BOOLEAN(type=0x%x, length=%d, value=%s)", peekType, peekLength, String.valueOf(readByte != 0x00))); } state = ELEMENT_READ_STATE_NEED_TYPE; return readByte != 0x00; }
@Test public void testEmptyBufferPrepend() { Buffer buffer1 = Buffers.wrap(mm, "1234"); buffer1.position(3); Buffer buffer2 = mm.allocate(0); CompositeBuffer compositeBuffer = createCompositeBuffer(buffer1); assertEquals('4', (char) compositeBuffer.get(0)); Buffer resultBuffer = Buffers.appendBuffers(mm, buffer2, compositeBuffer); assertEquals(resultBuffer.toStringContent(), "4"); }
@Test public void testBuffers() { Buffer sampleBuffer = Buffers.wrap(mm, new byte[]{-1, 0, 1, 1, 2, 3, 4}); Buffer b1 = mm.allocate(3); Buffer b2 = mm.allocate(4); CompositeBuffer compositeBuffer = createCompositeBuffer(b1, b2); compositeBuffer.put(sampleBuffer); compositeBuffer.flip(); sampleBuffer.flip(); while (sampleBuffer.hasRemaining()) { assertEquals(sampleBuffer.get(), compositeBuffer.get()); } }