use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.
the class BaseDataStreamMarshaller method tightUnmarshalString.
@SuppressWarnings("deprecation")
protected UTF8Buffer tightUnmarshalString(DataByteArrayInputStream dataIn, BooleanStream bs) throws IOException {
if (bs.readBoolean()) {
// ignored for now.
boolean ascii = bs.readBoolean();
int size = dataIn.readShort();
if (size == 0) {
return new UTF8Buffer("");
} else {
Buffer buffer = dataIn.readBuffer(size);
return buffer.utf8();
}
} else {
return null;
}
}
use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.
the class BaseDataStreamMarshaller method tightMarshalThrowable2.
protected void tightMarshalThrowable2(OpenWireFormat wireFormat, Throwable o, DataByteArrayOutputStream dataOut, BooleanStream bs) throws IOException {
if (bs.readBoolean()) {
String className = o instanceof OpenwireException ? ((OpenwireException) o).getClassName() : o.getClass().getName();
tightMarshalString2(new UTF8Buffer(className), dataOut, bs);
tightMarshalString2(new UTF8Buffer(o.getMessage()), dataOut, bs);
if (wireFormat.isStackTraceEnabled()) {
StackTraceElement[] stackTrace = o.getStackTrace();
dataOut.writeShort(stackTrace.length);
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement element = stackTrace[i];
tightMarshalString2(new UTF8Buffer(element.getClassName()), dataOut, bs);
tightMarshalString2(new UTF8Buffer(element.getMethodName()), dataOut, bs);
tightMarshalString2(new UTF8Buffer(element.getFileName()), dataOut, bs);
dataOut.writeInt(element.getLineNumber());
}
tightMarshalThrowable2(wireFormat, o.getCause(), dataOut, bs);
}
}
}
use of org.fusesource.hawtbuf.UTF8Buffer in project activemq-artemis by apache.
the class OpenWireMessageConverter method loadMapIntoProperties.
private static void loadMapIntoProperties(TypedProperties props, Map<String, Object> map) {
for (Entry<String, Object> entry : map.entrySet()) {
SimpleString key = new SimpleString(entry.getKey());
Object value = entry.getValue();
if (value instanceof UTF8Buffer) {
value = ((UTF8Buffer) value).toString();
}
TypedProperties.setObjectProperty(key, value, props);
}
}
use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.
the class ProducerId method setProducerSessionKey.
/**
* @param sessionKey
*/
private void setProducerSessionKey(String sessionKey) {
// Parse off the value
int p = sessionKey.lastIndexOf(":");
if (p >= 0) {
sessionId = Long.parseLong(sessionKey.substring(p + 1));
sessionKey = sessionKey.substring(0, p);
}
// The rest is the value
connectionId = new UTF8Buffer(sessionKey);
}
use of org.fusesource.hawtbuf.UTF8Buffer in project fabric8 by jboss-fuse.
the class MqttProtocol method snoopConnectionParameters.
@Override
public void snoopConnectionParameters(final SocketWrapper socket, final Buffer received, final Handler<ConnectionParameters> handler) {
final MqttProtocolDecoder h = new MqttProtocolDecoder(this);
h.errorHandler(new Handler<String>() {
@Override
public void handle(String error) {
LOG.info("STOMP protocol decoding error: " + error);
socket.close();
}
});
h.codecHandler(new Handler<MQTTFrame>() {
@Override
public void handle(MQTTFrame event) {
try {
if (event.messageType() == org.fusesource.mqtt.codec.CONNECT.TYPE) {
CONNECT connect = new CONNECT().decode(event);
ConnectionParameters parameters = new ConnectionParameters();
if (connect.clientId() != null) {
parameters.protocolClientId = connect.clientId().toString();
}
if (connect.userName() != null) {
parameters.protocolUser = connect.userName().toString();
// containing the virtual host info.
if (parameters.protocolUser.contains("/")) {
// Strip off the virtual host part of the username..
String[] parts = parameters.protocolUser.split("/", 2);
parameters.protocolVirtualHost = parts[0];
parameters.protocolUser = parts[1];
// Update the connect frame to strip out the virtual host from the username field...
connect.userName(new UTF8Buffer(parameters.protocolUser));
// re-write the received buffer /w the updated connect frame
Buffer tail = received.getBuffer((int) h.getBytesDecoded(), received.length());
BufferSupport.setLength(received, 0);
append(received, connect.encode());
received.appendBuffer(tail);
}
}
handler.handle(parameters);
} else {
LOG.info("Expected a CONNECT frame");
socket.close();
}
} catch (java.net.ProtocolException e) {
LOG.info("Invalid MQTT frame: " + e, e);
socket.close();
}
}
});
socket.readStream().dataHandler(h);
h.handle(received);
}
Aggregations