@Override public Object fromMessage(HazelcastMQMessage message) throws HazelcastMQException { try { return doFromMessage(message); } catch (IOException ex) { throw new HazelcastMQException( "IO error converting message to message bytes.", ex); } }
@Override public HazelcastMQMessage toMessage(Object msgData) throws HazelcastMQException { try { return doToMessage((byte[]) msgData); } catch (IOException ex) { throw new HazelcastMQException( "IO error converting message bytes to a message.", ex); } }
private void writeLine(OutputStream outstream, String value) throws IOException { write(outstream, value); outstream.write(NEWLINE); }
private byte[] doFromMessage(HazelcastMQMessage message) throws IOException { ByteArrayOutputStream outstream = new ByteArrayOutputStream(); // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( // outstream, UTF_8)); // Command writeLine(outstream, MESSAGE_COMMAND); // Write the general headers HazelcastMQMessage hzMessage = message; marshalHeaders(hzMessage.getHeaders(), outstream); byte[] body = message.getBody(); if (body != null) { write(outstream, HEADER_CONTENT_LENGTH); outstream.write(':'); writeLine(outstream, String.valueOf(body.length)); // Blank line to start the body. outstream.write(NEWLINE); outstream.write(body); } else { outstream.write(NEWLINE); } // Write the terminating NULL character. outstream.write((byte) NULL_CHARACTER); return outstream.toByteArray(); }
/** * Marshals the given properties as STOMP message headers. * * @param props * the properties to marshal * @param writer * the writer to write to * @throws IOException */ private void marshalHeaders(Headers headers, OutputStream outstream) throws IOException { for (String name : headers.getHeaderNames()) { write(outstream, name); outstream.write(':'); write(outstream, headers.get(name).replaceAll("\n", "\\n")); outstream.write('\n'); } }