/** * Encode this into a byte array. This is used when the body has been set as a binary array and * you want to encode the body as a byte array for transmission. * * @return a byte array containing the SIPRequest encoded as a byte array. */ public byte[] encodeAsBytes(String transport) { if (this.isNullRequest()) { // Encoding a null message for keepalive. return "\r\n\r\n".getBytes(); } else if (this.requestLine == null) { return new byte[0]; } byte[] rlbytes = null; if (requestLine != null) { try { rlbytes = requestLine.encode().getBytes("UTF-8"); } catch (UnsupportedEncodingException ex) { InternalErrorHandler.handleException(ex); } } byte[] superbytes = super.encodeAsBytes(transport); byte[] retval = new byte[rlbytes.length + superbytes.length]; System.arraycopy(rlbytes, 0, retval, 0, rlbytes.length); System.arraycopy(superbytes, 0, retval, rlbytes.length, superbytes.length); return retval; }