question: public static Packet toPacket ( ByteBuffer data ) { final byte code = data . get ( ) ; final short id = ( short ) ( ( data . get ( ) ) & 0xFF ) ; final short datalen = data . getShort ( ) ; final byte [ ] authData = new byte [ 16 ] ; data . get ( authData ) ; final PacketType type = PacketType . getPacketType ( code ) ; Packet pkt = null ; switch ( type ) { case ACCESS_ACCEPT : pkt = new AccessAccept ( ) ; pkt . setAuthenticator ( new ResponseAuthenticator ( authData ) ) ; break ; case ACCESS_CHALLENGE : pkt = new AccessChallenge ( ) ; pkt . setAuthenticator ( new ResponseAuthenticator ( authData ) ) ; break ; case ACCESS_REJECT : pkt = new AccessReject ( ) ; pkt . setAuthenticator ( new ResponseAuthenticator ( authData ) ) ; break ; case ACCESS_REQUEST : pkt = new AccessRequest ( ) ; pkt . setAuthenticator ( new RequestAuthenticator ( authData ) ) ; break ; case UNKNOWN : default : LOG . log ( Level . WARNING , "Unsupported packet type code '" + code + "' received. Unable to handle packet." ) ; return null ; } pkt . setIdentifier ( id ) ; Attribute a = null ; while ( ( a = PacketFactory . nextAttribute ( data ) ) != null ) { pkt . addAttribute ( a ) ; } return pkt ; }
target:  Unmarshalls from an ByteBuffer the octet format of rfc 2865 and creates the corresponding package and instantiates its embedded authenticator and attributes.