You can replace these two lines with simply

    flagByte = buffer.get()

and remove byteWritable variable from the class.