/** * Reads data from the buffer and stores them into <code>messageData</code>. * The data can be later fetched using one of the <code>getMessage</code> * methods. * @param buffer the buffer containing the message data; must contain exactly * the data of the message (not zero terminated nor length tagged) * @see #getMessage() * @see #getMessage(String) */ public void setData(ByteBuffer buffer) throws PDUException, NotEnoughDataInByteBufferException, TerminatingZeroNotFoundException { byte[] messageData = null; int length = 0; if (buffer != null) { messageData = buffer.getBuffer(); length = messageData == null ? 0 : messageData.length; checkString(minLength, length, maxLength); } this.message = null; this.messageData = messageData; this.length = length; }
/** * Sets the message to a value with given encoding. * @param message the message * @param encoding the encoding of the message provided * @exception WrongLengthOfStringException thrown when the message * too short or long * @exception UnsupportedEncodingException if the required encoding is not * available for the Java Runtime system */ public void setMessage(String message, String encoding) throws WrongLengthOfStringException, UnsupportedEncodingException { checkString(message, minLength, maxLength, encoding); if (message != null) { try { messageData = message.getBytes(encoding); } catch (UnsupportedEncodingException e) { debug.write("encoding " + encoding + " not supported. Exception " + e); event.write(e, "encoding " + encoding + " not supported"); throw e; // re-throw } this.message = message; this.length = messageData.length; this.encoding = encoding; } else { this.message = null; this.messageData = null; this.encoding = encoding; this.length = 0; } }