public static void marshalPrimitive(DataOutputStream out, Object value) throws IOException { if (value == null) { marshalNull(out); } else if (value.getClass() == Boolean.class) { marshalBoolean(out, ((Boolean)value).booleanValue()); } else if (value.getClass() == Byte.class) { marshalByte(out, ((Byte)value).byteValue()); } else if (value.getClass() == Character.class) { marshalChar(out, ((Character)value).charValue()); } else if (value.getClass() == Short.class) { marshalShort(out, ((Short)value).shortValue()); } else if (value.getClass() == Integer.class) { marshalInt(out, ((Integer)value).intValue()); } else if (value.getClass() == Long.class) { marshalLong(out, ((Long)value).longValue()); } else if (value.getClass() == Float.class) { marshalFloat(out, ((Float)value).floatValue()); } else if (value.getClass() == Double.class) { marshalDouble(out, ((Double)value).doubleValue()); } else if (value.getClass() == byte[].class) { marshalByteArray(out, (byte[])value); } else if (value.getClass() == String.class) { marshalString(out, (String)value); } else if (value.getClass() == UTF8Buffer.class) { marshalString(out, value.toString()); } else if (value instanceof Map) { out.writeByte(MAP_TYPE); marshalPrimitiveMap((Map<String, Object>)value, out); } else if (value instanceof List) { out.writeByte(LIST_TYPE);
/** * Writes a <code>String</code> to the stream message. * * @param value the <code>String</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeString(String value) throws JMSException { initializeWriting(); try { if (value == null) { MarshallingSupport.marshalNull(dataOut); } else { MarshallingSupport.marshalString(dataOut, value); } } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
@Override public void beforeMarshall(WireFormat wireFormat) throws IOException { // Need to marshal the properties. if (marshalledProperties == null && properties != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); MarshallingSupport.marshalPrimitiveMap(properties, os); os.close(); marshalledProperties = baos.toByteSequence(); } }
switch (primitiveType) { case DataConstants.BOOLEAN: MarshallingSupport.marshalBoolean(dataOut, buffer.readBoolean()); break; case DataConstants.BYTE: MarshallingSupport.marshalByte(dataOut, buffer.readByte()); break; case DataConstants.BYTES: byte[] bytesData = new byte[len]; buffer.readBytes(bytesData); MarshallingSupport.marshalByteArray(dataOut, bytesData); break; case DataConstants.CHAR: char ch = (char) buffer.readShort(); MarshallingSupport.marshalChar(dataOut, ch); break; case DataConstants.DOUBLE: double doubleVal = Double.longBitsToDouble(buffer.readLong()); MarshallingSupport.marshalDouble(dataOut, doubleVal); break; case DataConstants.FLOAT: float floatVal = Float.intBitsToFloat(buffer.readInt()); MarshallingSupport.marshalFloat(dataOut, floatVal); break; case DataConstants.INT: MarshallingSupport.marshalInt(dataOut, buffer.readInt()); break; case DataConstants.LONG:
private static byte[] toAMQMessageMapType(final ActiveMQBuffer buffer, final boolean isCompressed) throws IOException { byte[] bytes = null; //it could be a null map if (buffer.readableBytes() > 0) { TypedProperties mapData = new TypedProperties(); mapData.decode(buffer.byteBuf()); Map<String, Object> map = mapData.getMap(); ByteArrayOutputStream out = new ByteArrayOutputStream(mapData.getEncodeSize()); OutputStream os = out; if (isCompressed) { os = new DeflaterOutputStream(os, true); } try (DataOutputStream dataOut = new DataOutputStream(os)) { MarshallingSupport.marshalPrimitiveMap(map, dataOut); dataOut.flush(); } bytes = out.toByteArray(); } return bytes; }
public static void marshalByteArray(DataOutputStream out, byte[] value) throws IOException { marshalByteArray(out, value, 0, value.length); }
/** * Writes a <code>double</code> to the stream message. * * @param value the <code>double</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeDouble(double value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalDouble(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>byte</code> to the stream message. * * @param value the <code>byte</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeByte(byte value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalByte(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>long</code> to the stream message. * * @param value the <code>long</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeLong(long value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalLong(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>float</code> to the stream message. * * @param value the <code>float</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeFloat(float value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalFloat(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>char</code> to the stream message. * * @param value the <code>char</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeChar(char value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalChar(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes an <code>int</code> to the stream message. * * @param value the <code>int</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeInt(int value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalInt(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>boolean</code> to the stream message. The value * <code>true</code> is written as the value <code>(byte)1</code>; the * value <code>false</code> is written as the value <code>(byte)0</code>. * * @param value the <code>boolean</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeBoolean(boolean value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalBoolean(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
if (value == null) { try { MarshallingSupport.marshalNull(dataOut); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe);
@Override public void beforeMarshall(WireFormat wireFormat) throws IOException { // Need to marshal the properties. if (marshalledProperties == null && properties != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); MarshallingSupport.marshalPrimitiveMap(properties, os); os.close(); marshalledProperties = baos.toByteSequence(); } }
/** * Writes a <code>String</code> to the stream message. * * @param value the <code>String</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeString(String value) throws JMSException { initializeWriting(); try { if (value == null) { MarshallingSupport.marshalNull(dataOut); } else { MarshallingSupport.marshalString(dataOut, value); } } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a portion of a byte array as a byte array field to the stream * message. <p/> * <P> * The a portion of the byte array <code>value</code> is written to the * message as a byte array field. Consecutively written byte array fields * are treated as two distinct fields when the fields are read. * * @param value the byte array value to be written * @param offset the initial offset within the byte array * @param length the number of bytes to use * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeBytes(byte[] value, int offset, int length) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalByteArray(dataOut, value, offset, length); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>double</code> to the stream message. * * @param value the <code>double</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeDouble(double value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalDouble(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>byte</code> to the stream message. * * @param value the <code>byte</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeByte(byte value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalByte(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }
/** * Writes a <code>long</code> to the stream message. * * @param value the <code>long</code> value to be written * @throws JMSException if the JMS provider fails to write the message due * to some internal error. * @throws MessageNotWriteableException if the message is in read-only mode. */ @Override public void writeLong(long value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalLong(dataOut, value); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } }