* @throws IOException
* @throws InterruptedException
*/
public static Command getCommand(Connection conn) throws IOException, InterruptedException {
byte[] cmdData = null;
FlapHeader hdr = null;
SNACPacket pkt = null;
List tlvs = null;
try {
hdr = FlapHeader.getHeader(conn);
} catch (IllegalStateException e1) {
e1.printStackTrace();
}
if (hdr != null) {
/* get the length of the data portion */
int dataLength = hdr.getDataLength();
/* now load the data portion */
cmdData = new byte[dataLength];
int count = 0;
while (count != cmdData.length) {
try {
count += conn.read(cmdData, count, cmdData.length - count);
} catch (IOException e) {
e.printStackTrace();
}
}
// create the SNAC from the buffer
if (hdr.getChannelId() == FlapConstants.FLAP_CHANNEL_SNAC) {
// create snac packet
pkt = new SNACPacket(cmdData);
// moved all SNAC data into the SNACPacket
cmdData = null;
} else if (hdr.getChannelId() == FlapConstants.FLAP_CHANNEL_DISCONNECT) {
// anything left MAY/MAY not be a list of TLVs -
tlvs = TLV.getTLVs(cmdData, 0);
}