@Test(expected = BufferUnderflowException.class) public void testSeekPastMagicBytes() { byte[] brokenMessage = HEX.decode("000000"); MAINNET.getDefaultSerializer().seekPastMagicBytes(ByteBuffer.wrap(brokenMessage)); }
@Override public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } }
BitcoinSerializer extends MessageSerializer { @Override public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } }
BitcoinSerializer extends MessageSerializer { @Override public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } BitcoinSerializer(NetworkParameters params, boolean parseRetain);  BitcoinSerializer(NetworkParameters params, int protocolVersion, boolean parseRetain); }
BitcoinSerializer extends MessageSerializer { @Override public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } BitcoinSerializer(NetworkParameters params, boolean parseRetain);  BitcoinSerializer(NetworkParameters params, int protocolVersion, boolean parseRetain); @Override BitcoinSerializer withProtocolVersion(int protocolVersion); @Override int getProtocolVersion(); @Override void serialize(String name, byte[] message, OutputStream out); @Override void serialize(Message message, OutputStream out); @Override Message deserialize(ByteBuffer in); @Override BitcoinPacketHeader deserializeHeader(ByteBuffer in); @Override Message deserializePayload(BitcoinPacketHeader header, ByteBuffer in); NetworkParameters getParameters(); @Override AddressMessage makeAddressMessage(byte[] payloadBytes, int length); @Override Message makeAlertMessage(byte[] payloadBytes); @Override Block makeBlock(final byte[] payloadBytes, final int offset, final int length); @Override Message makeBloomFilter(byte[] payloadBytes); @Override FilteredBlock makeFilteredBlock(byte[] payloadBytes); @Override InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length); @Override Transaction makeTransaction(byte[] payloadBytes, int offset, int length, byte[] hashFromHeader); @Override void seekPastMagicBytes(ByteBuffer in); @Override boolean isParseRetainMode(); @Override boolean equals(Object o); @Override int hashCode(); }
BitcoinSerializer extends MessageSerializer { @Override public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } BitcoinSerializer(NetworkParameters params, boolean parseRetain);  BitcoinSerializer(NetworkParameters params, int protocolVersion, boolean parseRetain); @Override BitcoinSerializer withProtocolVersion(int protocolVersion); @Override int getProtocolVersion(); @Override void serialize(String name, byte[] message, OutputStream out); @Override void serialize(Message message, OutputStream out); @Override Message deserialize(ByteBuffer in); @Override BitcoinPacketHeader deserializeHeader(ByteBuffer in); @Override Message deserializePayload(BitcoinPacketHeader header, ByteBuffer in); NetworkParameters getParameters(); @Override AddressMessage makeAddressMessage(byte[] payloadBytes, int length); @Override Message makeAlertMessage(byte[] payloadBytes); @Override Block makeBlock(final byte[] payloadBytes, final int offset, final int length); @Override Message makeBloomFilter(byte[] payloadBytes); @Override FilteredBlock makeFilteredBlock(byte[] payloadBytes); @Override InventoryMessage makeInventoryMessage(byte[] payloadBytes, int length); @Override Transaction makeTransaction(byte[] payloadBytes, int offset, int length, byte[] hashFromHeader); @Override void seekPastMagicBytes(ByteBuffer in); @Override boolean isParseRetainMode(); @Override boolean equals(Object o); @Override int hashCode();  }