public ByteBuffer putString(CharSequence in, int fieldSize, CharsetEncoder encoder) throws CharacterCodingException { buf.putString(in, fieldSize, encoder); return this; }
public ByteBuffer putString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException { buf.putString(in, encoder); return this; }
private ByteBuffer createDelimiterBuf(final String delimiter) { ByteBuffer tmp = ByteBuffer.allocate(delimiter.length()); try { tmp.putString(delimiter, charset.newEncoder()); tmp.flip(); return tmp; } catch (CharacterCodingException e) { LOG.error("Bad charset?", e); return null; } }
private void appendHeaderValues(final ByteBuffer buffer, final List<SipHeaderValue> values) throws CharacterCodingException { for (final Iterator<SipHeaderValue> iter = values.iterator(); iter .hasNext();) { final SipHeaderValue value = iter.next(); buffer.putString(value.getBaseValue(), m_asciiEncoder); final Map<String, String> params = value.getParams(); final Set<Map.Entry<String, String>> entries = params.entrySet(); for (final Map.Entry<String, String> entry : entries) { buffer.put(MinaCodecUtils.SEMI_COLON); buffer.putString(entry.getKey(), m_asciiEncoder); buffer.put(MinaCodecUtils.EQUALS); buffer.putString(entry.getValue(), m_asciiEncoder); } if (iter.hasNext()) { buffer.put(MinaCodecUtils.COMMA); } } }
private void encodeStartLine(final SipMessage message, final ByteBuffer buffer) { LOG.debug("Encoding start line: '{}'", message.getStartLine()); try { buffer.putString(message.getStartLine(), m_asciiEncoder); } catch (final CharacterCodingException e) { LOG.error("Bad encoding?", e); } MinaCodecUtils.appendCRLF(buffer); }
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER); if (encoder == null) { encoder = charset.newEncoder(); session.setAttribute(ENCODER, encoder); } String value = message.toString(); ByteBuffer buf = ByteBuffer.allocate(value.length()) .setAutoExpand(true); buf.putString(value, encoder); if (buf.position() > maxLineLength) { throw new IllegalArgumentException("Line length: " + buf.position()); } buf.putString(delimiter.getValue(), encoder); buf.flip(); out.write(buf); }
private void encodeHeaders(final SipMessage message, final ByteBuffer buffer) { LOG.debug("Appending headers: {}", message.getHeaders()); final Map<String, SipHeader> headers = message.getHeaders(); for (final Map.Entry<String, SipHeader> entry : headers.entrySet()) { final SipHeader header = entry.getValue(); final List<SipHeaderValue> values = header.getValues(); try { buffer.putString(header.getName(), m_asciiEncoder); buffer.put(MinaCodecUtils.COLON); buffer.put(MinaCodecUtils.SPACE); appendHeaderValues(buffer, values); MinaCodecUtils.appendCRLF(buffer); } catch (final CharacterCodingException e) { LOG.error("Bad encoding?", e); } } MinaCodecUtils.appendCRLF(buffer); }
public void visiteErrorCode(final ErrorCodeAttribute attribute) { writeHeader(attribute); // The first 21 bits are zero-filled for 32 bit alignment. We skip // the first 16 here so we can just write a full byte for the class // on the next call. m_buf.skip(2); MinaUtils.putUnsignedByte(this.m_buf, attribute.getErrorClass()); MinaUtils.putUnsignedByte(this.m_buf, attribute.getErrorNumber()); try { m_buf.putString(attribute.getReasonPhrase(), UTF_8_ENCODER); } catch (final CharacterCodingException e) { LOG.error("Could not encode reason phrase", e); throw new IllegalArgumentException( "Could not encode reason phrase", e); } }
tmp.putString(delimiter.getValue(), charset.newEncoder()); tmp.flip(); delimBuf = tmp;