Search in sources :

Example 1 with LineOrientedRequest

use of org.opennms.netmgt.provision.detector.simple.request.LineOrientedRequest in project opennms by OpenNMS.

the class LineOrientedEncoder method encode.

/**
 * {@inheritDoc}
 */
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final LineOrientedRequest request = (LineOrientedRequest) message;
    if (request.getRequest().contains("null")) {
        return;
    }
    CharsetEncoder encoder = (CharsetEncoder) session.getAttribute(ENCODER);
    if (encoder == null) {
        encoder = m_charset.newEncoder();
        session.setAttribute(ENCODER, encoder);
    }
    final String value = request.getRequest();
    IoBuffer buffer = null;
    try {
        buffer = IoBuffer.allocate(value.length()).setAutoExpand(true);
        buffer.putString(request.getRequest(), encoder);
        buffer.flip();
        LOG.debug("Client sending: {}", value.trim());
        out.write(buffer);
    } finally {
        if (buffer != null) {
            buffer.free();
        }
    }
}
Also used : LineOrientedRequest(org.opennms.netmgt.provision.detector.simple.request.LineOrientedRequest) CharsetEncoder(java.nio.charset.CharsetEncoder) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Aggregations

CharsetEncoder (java.nio.charset.CharsetEncoder)1 IoBuffer (org.apache.mina.core.buffer.IoBuffer)1 LineOrientedRequest (org.opennms.netmgt.provision.detector.simple.request.LineOrientedRequest)1