code: private ArrayList<byte []> splitPackets(byte[] bin){
  
          ArrayList<byte []> packets = new ArrayList<byte []>();
          int noOfPackets = getLengthFromByteArray(getBytes(bin, 0, 2)); //in.read(bin, 0, 2);
          int j = 2;
  
          for(int i = 0; i < noOfPackets; i++){
              int sizeOfPacket = getLengthFromByteArray(getBytes(bin, j, j + 2));//in.read(bin, j, j+2);
              byte[] packet = Arrays.copyOfRange(bin, j + 2, j + 2 + sizeOfPacket);
              packets.add(packet);
              j = j + 2 + sizeOfPacket;
          }
          return packets;
      }
docs: Each byte stream contains many packets. This method reads first two bits and calculates number of packets in the byte stream and split it.