You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2012/03/01 16:42:53 UTC
svn commit: r1295627 [10/12] - in
/qpid/branches/rg-amqp-1-0-sandbox/qpid/java: ./ bdbstore/ bdbstore/src/main/
bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/
bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/tuples/
bdbst...
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQType.java Thu Mar 1 15:42:44 2012
@@ -20,8 +20,8 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.IOException;
import java.math.BigDecimal;
@@ -61,12 +61,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLongStringBytes(buffer, (String) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLongString(buffer);
}
@@ -107,12 +107,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeUnsignedInteger(buffer, (Long) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readUnsignedInteger(buffer);
}
@@ -138,7 +138,7 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
BigDecimal bd = (BigDecimal) value;
@@ -151,7 +151,7 @@ public enum AMQType
EncodingUtils.writeInteger(buffer, unscaled);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
byte places = EncodingUtils.readByte(buffer);
@@ -183,12 +183,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLong(buffer, (Long) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLong(buffer);
}
@@ -247,7 +247,7 @@ public enum AMQType
* @param value An instance of the type.
* @param buffer The byte buffer to write it to.
*/
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
// Ensure that the value is a FieldTable.
if (!(value instanceof FieldTable))
@@ -268,7 +268,7 @@ public enum AMQType
*
* @return An instance of the type.
*/
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
try
{
@@ -302,10 +302,10 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer)
+ public void writeValueImpl(Object value, DataOutput buffer)
{ }
- public Object readValueFromBuffer(DataInputStream buffer)
+ public Object readValueFromBuffer(DataInput buffer)
{
return null;
}
@@ -331,12 +331,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLongstr(buffer, (byte[]) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLongstr(buffer);
}
@@ -361,12 +361,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLongStringBytes(buffer, (String) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLongString(buffer);
}
@@ -392,12 +392,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLongStringBytes(buffer, (String) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLongString(buffer);
}
@@ -427,12 +427,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeBoolean(buffer, (Boolean) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readBoolean(buffer);
}
@@ -462,12 +462,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeChar(buffer, (Character) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readChar(buffer);
}
@@ -497,12 +497,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeByte(buffer, (Byte) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readByte(buffer);
}
@@ -536,12 +536,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeShort(buffer, (Short) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readShort(buffer);
}
@@ -578,12 +578,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeInteger(buffer, (Integer) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readInteger(buffer);
}
@@ -596,6 +596,22 @@ public enum AMQType
return EncodingUtils.encodedLongLength();
}
+ public int getEncodingSize(long value)
+ {
+ return EncodingUtils.encodedLongLength();
+ }
+
+ public AMQTypedValue asTypedValue(long value)
+ {
+ return AMQTypedValue.createAMQTypedValue(value);
+ }
+
+ public void writeToBuffer(long value, DataOutput buffer) throws IOException
+ {
+ buffer.writeByte(identifier());
+ EncodingUtils.writeLong(buffer, value);
+ }
+
public Object toNativeValue(Object value)
{
if (value instanceof Long)
@@ -625,12 +641,18 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeLong(buffer, (Long) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public long readLongFromBuffer(DataInput buffer) throws IOException
+ {
+ return EncodingUtils.readLong(buffer);
+ }
+
+
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readLong(buffer);
}
@@ -660,12 +682,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeFloat(buffer, (Float) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readFloat(buffer);
}
@@ -699,12 +721,12 @@ public enum AMQType
}
}
- public void writeValueImpl(Object value, DataOutputStream buffer) throws IOException
+ public void writeValueImpl(Object value, DataOutput buffer) throws IOException
{
EncodingUtils.writeDouble(buffer, (Double) value);
}
- public Object readValueFromBuffer(DataInputStream buffer) throws IOException
+ public Object readValueFromBuffer(DataInput buffer) throws IOException
{
return EncodingUtils.readDouble(buffer);
}
@@ -761,7 +783,7 @@ public enum AMQType
*/
public AMQTypedValue asTypedValue(Object value)
{
- return new AMQTypedValue(this, toNativeValue(value));
+ return AMQTypedValue.createAMQTypedValue(this, toNativeValue(value));
}
/**
@@ -771,7 +793,7 @@ public enum AMQType
* @param value An instance of the type.
* @param buffer The byte buffer to write it to.
*/
- public void writeToBuffer(Object value, DataOutputStream buffer) throws IOException
+ public void writeToBuffer(Object value, DataOutput buffer) throws IOException
{
buffer.writeByte(identifier());
writeValueImpl(value, buffer);
@@ -783,7 +805,7 @@ public enum AMQType
* @param value An instance of the type.
* @param buffer The byte buffer to write it to.
*/
- abstract void writeValueImpl(Object value, DataOutputStream buffer) throws IOException;
+ abstract void writeValueImpl(Object value, DataOutput buffer) throws IOException;
/**
* Reads an instance of the type from a specified byte buffer.
@@ -792,5 +814,5 @@ public enum AMQType
*
* @return An instance of the type.
*/
- abstract Object readValueFromBuffer(DataInputStream buffer) throws IOException;
+ abstract Object readValueFromBuffer(DataInput buffer) throws IOException;
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/AMQTypedValue.java Thu Mar 1 15:42:44 2012
@@ -20,9 +20,7 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
+import java.io.*;
import java.util.Date;
import java.util.Map;
import java.math.BigDecimal;
@@ -42,81 +40,223 @@ import java.math.BigDecimal;
* <tr><td> Extract the value from a fully typed AMQP value.
* </table>
*/
-public class AMQTypedValue
+public abstract class AMQTypedValue
{
- /** The type of the value. */
- private final AMQType _type;
- /** The Java native representation of the AMQP typed value. */
- private final Object _value;
+ public abstract AMQType getType();
- public AMQTypedValue(AMQType type, Object value)
+ public abstract Object getValue();
+
+ public abstract void writeToBuffer(DataOutput buffer) throws IOException;
+
+ public abstract int getEncodingSize();
+
+
+ private static final class GenericTypedValue extends AMQTypedValue
{
- if (type == null)
+ /** The type of the value. */
+ private final AMQType _type;
+
+ /** The Java native representation of the AMQP typed value. */
+ private final Object _value;
+
+ private GenericTypedValue(AMQType type, Object value)
{
- throw new NullPointerException("Cannot create a typed value with null type");
+ if (type == null)
+ {
+ throw new NullPointerException("Cannot create a typed value with null type");
+ }
+
+ _type = type;
+ _value = type.toNativeValue(value);
}
- _type = type;
- _value = type.toNativeValue(value);
- }
+ private GenericTypedValue(AMQType type, DataInput buffer) throws IOException
+ {
+ _type = type;
+ _value = type.readValueFromBuffer(buffer);
+ }
+
+
+ public AMQType getType()
+ {
+ return _type;
+ }
+
+ public Object getValue()
+ {
+ return _value;
+ }
+
+ public void writeToBuffer(DataOutput buffer) throws IOException
+ {
+ _type.writeToBuffer(_value, buffer);
+ }
+
+ public int getEncodingSize()
+ {
+ return _type.getEncodingSize(_value);
+ }
+
+
+ public String toString()
+ {
+ return "[" + getType() + ": " + getValue() + "]";
+ }
+
+
+ public boolean equals(Object o)
+ {
+ if(o instanceof GenericTypedValue)
+ {
+ GenericTypedValue other = (GenericTypedValue) o;
+ return _type == other._type && (_value == null ? other._value == null : _value.equals(other._value));
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public int hashCode()
+ {
+ return _type.hashCode() ^ (_value == null ? 0 : _value.hashCode());
+ }
- private AMQTypedValue(AMQType type, DataInputStream buffer) throws IOException
- {
- _type = type;
- _value = type.readValueFromBuffer(buffer);
}
- public AMQType getType()
+ private static final class LongTypedValue extends AMQTypedValue
{
- return _type;
+
+ private final long _value;
+
+ private LongTypedValue(long value)
+ {
+ _value = value;
+ }
+
+ public LongTypedValue(DataInput buffer) throws IOException
+ {
+ _value = EncodingUtils.readLong(buffer);
+ }
+
+ public AMQType getType()
+ {
+ return AMQType.LONG;
+ }
+
+
+ public Object getValue()
+ {
+ return _value;
+ }
+
+ public void writeToBuffer(DataOutput buffer) throws IOException
+ {
+ EncodingUtils.writeByte(buffer,AMQType.LONG.identifier());
+ EncodingUtils.writeLong(buffer,_value);
+ }
+
+
+ public int getEncodingSize()
+ {
+ return EncodingUtils.encodedLongLength();
+ }
}
- public Object getValue()
+ private static final class IntTypedValue extends AMQTypedValue
{
- return _value;
+ @Override
+ public String toString()
+ {
+ return "[INT: " + String.valueOf(_value) + "]";
+ }
+
+ private final int _value;
+
+ public IntTypedValue(int value)
+ {
+ _value = value;
+ }
+
+ public AMQType getType()
+ {
+ return AMQType.INT;
+ }
+
+
+ public Object getValue()
+ {
+ return _value;
+ }
+
+ public void writeToBuffer(DataOutput buffer) throws IOException
+ {
+ EncodingUtils.writeByte(buffer,AMQType.INT.identifier());
+ EncodingUtils.writeInteger(buffer, _value);
+ }
+
+
+ public int getEncodingSize()
+ {
+ return EncodingUtils.encodedIntegerLength();
+ }
}
- public void writeToBuffer(DataOutputStream buffer) throws IOException
+
+ public static AMQTypedValue readFromBuffer(DataInput buffer) throws IOException
{
- _type.writeToBuffer(_value, buffer);
+ AMQType type = AMQTypeMap.getType(buffer.readByte());
+
+ switch(type)
+ {
+ case LONG:
+ return new LongTypedValue(buffer);
+
+ case INT:
+ int value = EncodingUtils.readInteger(buffer);
+ return createAMQTypedValue(value);
+
+ default:
+ return new GenericTypedValue(type, buffer);
+ }
+
}
- public int getEncodingSize()
+ private static final AMQTypedValue[] INT_VALUES = new AMQTypedValue[16];
+ static
{
- return _type.getEncodingSize(_value);
+ for(int i = 0 ; i < 16; i ++)
+ {
+ INT_VALUES[i] = new IntTypedValue(i);
+ }
}
- public static AMQTypedValue readFromBuffer(DataInputStream buffer) throws IOException
+ public static AMQTypedValue createAMQTypedValue(int i)
{
- AMQType type = AMQTypeMap.getType(buffer.readByte());
-
- return new AMQTypedValue(type, buffer);
+ return (i & 0x0f) == i ? INT_VALUES[i] : new IntTypedValue(i);
}
- public String toString()
+
+ public static AMQTypedValue createAMQTypedValue(long value)
{
- return "[" + getType() + ": " + getValue() + "]";
+ return new LongTypedValue(value);
}
-
- public boolean equals(Object o)
+ public static AMQTypedValue createAMQTypedValue(AMQType type, Object value)
{
- if(o instanceof AMQTypedValue)
+ switch(type)
{
- AMQTypedValue other = (AMQTypedValue) o;
- return _type == other._type && (_value == null ? other._value == null : _value.equals(other._value));
- }
- else
- {
- return false;
+ case LONG:
+ return new LongTypedValue((Long) AMQType.LONG.toNativeValue(value));
+ case INT:
+ return new IntTypedValue((Integer) AMQType.INT.toNativeValue(value));
+
+ default:
+ return new GenericTypedValue(type, value);
}
}
- public int hashCode()
- {
- return _type.hashCode() ^ (_value == null ? 0 : _value.hashCode());
- }
public static AMQTypedValue toTypedValue(Object val)
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BasicContentHeaderProperties.java Thu Mar 1 15:42:44 2012
@@ -20,8 +20,9 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
import org.slf4j.Logger;
@@ -80,6 +81,7 @@ public class BasicContentHeaderPropertie
private static final int USER_ID_MASK = 1 << 4;
private static final int APPLICATION_ID_MASK = 1 << 3;
private static final int CLUSTER_ID_MASK = 1 << 2;
+ private byte[] _encodedForm;
public BasicContentHeaderProperties()
@@ -87,6 +89,12 @@ public class BasicContentHeaderPropertie
public int getPropertyListSize()
{
+ if(_encodedForm != null && (_headers == null || _headers.isClean()))
+ {
+ return _encodedForm.length;
+ }
+ else
+ {
int size = 0;
if ((_propertyFlags & (CONTENT_TYPE_MASK)) > 0)
@@ -167,6 +175,7 @@ public class BasicContentHeaderPropertie
}
return size;
+ }
}
public void setPropertyFlags(int propertyFlags)
@@ -179,87 +188,94 @@ public class BasicContentHeaderPropertie
return _propertyFlags;
}
- public void writePropertyListPayload(DataOutputStream buffer) throws IOException
+ public void writePropertyListPayload(DataOutput buffer) throws IOException
{
- if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0)
+ if(_encodedForm != null && (_headers == null || !_headers.isClean()))
{
- EncodingUtils.writeShortStringBytes(buffer, _contentType);
+ buffer.write(_encodedForm);
}
-
- if ((_propertyFlags & ENCODING_MASK) != 0)
+ else
{
- EncodingUtils.writeShortStringBytes(buffer, _encoding);
- }
+ if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _contentType);
+ }
- if ((_propertyFlags & HEADERS_MASK) != 0)
- {
- EncodingUtils.writeFieldTableBytes(buffer, _headers);
- }
+ if ((_propertyFlags & ENCODING_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _encoding);
+ }
- if ((_propertyFlags & DELIVERY_MODE_MASK) != 0)
- {
- buffer.writeByte(_deliveryMode);
- }
+ if ((_propertyFlags & HEADERS_MASK) != 0)
+ {
+ EncodingUtils.writeFieldTableBytes(buffer, _headers);
+ }
- if ((_propertyFlags & PRIORITY_MASK) != 0)
- {
- buffer.writeByte(_priority);
- }
+ if ((_propertyFlags & DELIVERY_MODE_MASK) != 0)
+ {
+ buffer.writeByte(_deliveryMode);
+ }
- if ((_propertyFlags & CORRELATION_ID_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _correlationId);
- }
+ if ((_propertyFlags & PRIORITY_MASK) != 0)
+ {
+ buffer.writeByte(_priority);
+ }
- if ((_propertyFlags & REPLY_TO_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _replyTo);
- }
+ if ((_propertyFlags & CORRELATION_ID_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _correlationId);
+ }
- if ((_propertyFlags & EXPIRATION_MASK) != 0)
- {
- if (_expiration == 0L)
+ if ((_propertyFlags & REPLY_TO_MASK) != 0)
{
- EncodingUtils.writeShortStringBytes(buffer, ZERO_STRING);
+ EncodingUtils.writeShortStringBytes(buffer, _replyTo);
}
- else
+
+ if ((_propertyFlags & EXPIRATION_MASK) != 0)
{
- EncodingUtils.writeShortStringBytes(buffer, String.valueOf(_expiration));
+ if (_expiration == 0L)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, ZERO_STRING);
+ }
+ else
+ {
+ EncodingUtils.writeShortStringBytes(buffer, String.valueOf(_expiration));
+ }
}
- }
- if ((_propertyFlags & MESSAGE_ID_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _messageId);
- }
+ if ((_propertyFlags & MESSAGE_ID_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _messageId);
+ }
- if ((_propertyFlags & TIMESTAMP_MASK) != 0)
- {
- EncodingUtils.writeTimestamp(buffer, _timestamp);
- }
+ if ((_propertyFlags & TIMESTAMP_MASK) != 0)
+ {
+ EncodingUtils.writeTimestamp(buffer, _timestamp);
+ }
- if ((_propertyFlags & TYPE_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _type);
- }
+ if ((_propertyFlags & TYPE_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _type);
+ }
- if ((_propertyFlags & USER_ID_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _userId);
- }
+ if ((_propertyFlags & USER_ID_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _userId);
+ }
- if ((_propertyFlags & APPLICATION_ID_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _appId);
- }
+ if ((_propertyFlags & APPLICATION_ID_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _appId);
+ }
- if ((_propertyFlags & CLUSTER_ID_MASK) != 0)
- {
- EncodingUtils.writeShortStringBytes(buffer, _clusterId);
+ if ((_propertyFlags & CLUSTER_ID_MASK) != 0)
+ {
+ EncodingUtils.writeShortStringBytes(buffer, _clusterId);
+ }
}
}
- public void populatePropertiesFromBuffer(DataInputStream buffer, int propertyFlags, int size) throws AMQFrameDecodingException, IOException
+ public void populatePropertiesFromBuffer(DataInput buffer, int propertyFlags, int size) throws AMQFrameDecodingException, IOException
{
_propertyFlags = propertyFlags;
@@ -268,26 +284,40 @@ public class BasicContentHeaderPropertie
_logger.debug("Property flags: " + _propertyFlags);
}
- decode(buffer);
+ _encodedForm = new byte[size];
+ buffer.readFully(_encodedForm);
+
+ ByteArrayDataInput input = new ByteArrayDataInput(_encodedForm);
+
+ decode(input);
+
}
- private void decode(DataInputStream buffer) throws IOException, AMQFrameDecodingException
+ private void decode(ByteArrayDataInput buffer) throws IOException, AMQFrameDecodingException
{
// ByteBuffer buffer = ByteBuffer.wrap(_encodedForm);
+ int headersOffset = 0;
+
if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0)
{
- _contentType = EncodingUtils.readAMQShortString(buffer);
+ _contentType = buffer.readAMQShortString();
+ headersOffset += EncodingUtils.encodedShortStringLength(_contentType);
}
if ((_propertyFlags & ENCODING_MASK) != 0)
{
- _encoding = EncodingUtils.readAMQShortString(buffer);
+ _encoding = buffer.readAMQShortString();
+ headersOffset += EncodingUtils.encodedShortStringLength(_encoding);
}
if ((_propertyFlags & HEADERS_MASK) != 0)
{
- _headers = EncodingUtils.readFieldTable(buffer);
+ long length = EncodingUtils.readUnsignedInteger(buffer);
+
+ _headers = new FieldTable(_encodedForm, headersOffset+4, (int)length);
+
+ buffer.skipBytes((int)length);
}
if ((_propertyFlags & DELIVERY_MODE_MASK) != 0)
@@ -302,12 +332,12 @@ public class BasicContentHeaderPropertie
if ((_propertyFlags & CORRELATION_ID_MASK) != 0)
{
- _correlationId = EncodingUtils.readAMQShortString(buffer);
+ _correlationId = buffer.readAMQShortString();
}
if ((_propertyFlags & REPLY_TO_MASK) != 0)
{
- _replyTo = EncodingUtils.readAMQShortString(buffer);
+ _replyTo = buffer.readAMQShortString();
}
if ((_propertyFlags & EXPIRATION_MASK) != 0)
@@ -317,7 +347,7 @@ public class BasicContentHeaderPropertie
if ((_propertyFlags & MESSAGE_ID_MASK) != 0)
{
- _messageId = EncodingUtils.readAMQShortString(buffer);
+ _messageId = buffer.readAMQShortString();
}
if ((_propertyFlags & TIMESTAMP_MASK) != 0)
@@ -327,22 +357,22 @@ public class BasicContentHeaderPropertie
if ((_propertyFlags & TYPE_MASK) != 0)
{
- _type = EncodingUtils.readAMQShortString(buffer);
+ _type = buffer.readAMQShortString();
}
if ((_propertyFlags & USER_ID_MASK) != 0)
{
- _userId = EncodingUtils.readAMQShortString(buffer);
+ _userId = buffer.readAMQShortString();
}
if ((_propertyFlags & APPLICATION_ID_MASK) != 0)
{
- _appId = EncodingUtils.readAMQShortString(buffer);
+ _appId = buffer.readAMQShortString();
}
if ((_propertyFlags & CLUSTER_ID_MASK) != 0)
{
- _clusterId = EncodingUtils.readAMQShortString(buffer);
+ _clusterId = buffer.readAMQShortString();
}
@@ -363,11 +393,12 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= (CONTENT_TYPE_MASK);
_contentType = contentType;
+ _encodedForm = null;
}
public void setContentType(String contentType)
{
- setContentType((contentType == null) ? null : new AMQShortString(contentType));
+ setContentType((contentType == null) ? null : AMQShortString.valueOf(contentType));
}
public String getEncodingAsString()
@@ -384,13 +415,15 @@ public class BasicContentHeaderPropertie
public void setEncoding(String encoding)
{
_propertyFlags |= ENCODING_MASK;
- _encoding = (encoding == null) ? null : new AMQShortString(encoding);
+ _encoding = (encoding == null) ? null : AMQShortString.valueOf(encoding);
+ _encodedForm = null;
}
public void setEncoding(AMQShortString encoding)
{
_propertyFlags |= ENCODING_MASK;
_encoding = encoding;
+ _encodedForm = null;
}
public FieldTable getHeaders()
@@ -407,6 +440,7 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= HEADERS_MASK;
_headers = headers;
+ _encodedForm = null;
}
public byte getDeliveryMode()
@@ -418,6 +452,7 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= DELIVERY_MODE_MASK;
_deliveryMode = deliveryMode;
+ _encodedForm = null;
}
public byte getPriority()
@@ -429,6 +464,7 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= PRIORITY_MASK;
_priority = priority;
+ _encodedForm = null;
}
public AMQShortString getCorrelationId()
@@ -443,13 +479,14 @@ public class BasicContentHeaderPropertie
public void setCorrelationId(String correlationId)
{
- setCorrelationId((correlationId == null) ? null : new AMQShortString(correlationId));
+ setCorrelationId((correlationId == null) ? null : AMQShortString.valueOf(correlationId));
}
public void setCorrelationId(AMQShortString correlationId)
{
_propertyFlags |= CORRELATION_ID_MASK;
_correlationId = correlationId;
+ _encodedForm = null;
}
public String getReplyToAsString()
@@ -464,13 +501,14 @@ public class BasicContentHeaderPropertie
public void setReplyTo(String replyTo)
{
- setReplyTo((replyTo == null) ? null : new AMQShortString(replyTo));
+ setReplyTo((replyTo == null) ? null : AMQShortString.valueOf(replyTo));
}
public void setReplyTo(AMQShortString replyTo)
{
_propertyFlags |= REPLY_TO_MASK;
_replyTo = replyTo;
+ _encodedForm = null;
}
public long getExpiration()
@@ -482,6 +520,7 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= EXPIRATION_MASK;
_expiration = expiration;
+ _encodedForm = null;
}
public AMQShortString getMessageId()
@@ -498,12 +537,14 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= MESSAGE_ID_MASK;
_messageId = (messageId == null) ? null : new AMQShortString(messageId);
+ _encodedForm = null;
}
public void setMessageId(AMQShortString messageId)
{
_propertyFlags |= MESSAGE_ID_MASK;
_messageId = messageId;
+ _encodedForm = null;
}
public long getTimestamp()
@@ -515,6 +556,7 @@ public class BasicContentHeaderPropertie
{
_propertyFlags |= TIMESTAMP_MASK;
_timestamp = timestamp;
+ _encodedForm = null;
}
public String getTypeAsString()
@@ -529,13 +571,14 @@ public class BasicContentHeaderPropertie
public void setType(String type)
{
- setType((type == null) ? null : new AMQShortString(type));
+ setType((type == null) ? null : AMQShortString.valueOf(type));
}
public void setType(AMQShortString type)
{
_propertyFlags |= TYPE_MASK;
_type = type;
+ _encodedForm = null;
}
public String getUserIdAsString()
@@ -550,13 +593,14 @@ public class BasicContentHeaderPropertie
public void setUserId(String userId)
{
- setUserId((userId == null) ? null : new AMQShortString(userId));
+ setUserId((userId == null) ? null : AMQShortString.valueOf(userId));
}
public void setUserId(AMQShortString userId)
{
_propertyFlags |= USER_ID_MASK;
_userId = userId;
+ _encodedForm = null;
}
public String getAppIdAsString()
@@ -571,13 +615,14 @@ public class BasicContentHeaderPropertie
public void setAppId(String appId)
{
- setAppId((appId == null) ? null : new AMQShortString(appId));
+ setAppId((appId == null) ? null : AMQShortString.valueOf(appId));
}
public void setAppId(AMQShortString appId)
{
_propertyFlags |= APPLICATION_ID_MASK;
_appId = appId;
+ _encodedForm = null;
}
public String getClusterIdAsString()
@@ -592,13 +637,14 @@ public class BasicContentHeaderPropertie
public void setClusterId(String clusterId)
{
- setClusterId((clusterId == null) ? null : new AMQShortString(clusterId));
+ setClusterId((clusterId == null) ? null : AMQShortString.valueOf(clusterId));
}
public void setClusterId(AMQShortString clusterId)
{
_propertyFlags |= CLUSTER_ID_MASK;
_clusterId = clusterId;
+ _encodedForm = null;
}
public String toString()
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BodyFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BodyFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BodyFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/BodyFactory.java Thu Mar 1 15:42:44 2012
@@ -20,7 +20,8 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
+import org.apache.qpid.codec.MarkableDataInput;
+
import java.io.IOException;
/**
@@ -28,5 +29,5 @@ import java.io.IOException;
*/
public interface BodyFactory
{
- AMQBody createBody(DataInputStream in, long bodySize) throws AMQFrameDecodingException, IOException;
+ AMQBody createBody(MarkableDataInput in, long bodySize) throws AMQFrameDecodingException, IOException;
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/CompositeAMQDataBlock.java Thu Mar 1 15:42:44 2012
@@ -20,7 +20,7 @@
*/
package org.apache.qpid.framing;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
public class CompositeAMQDataBlock extends AMQDataBlock implements EncodableAMQDataBlock
@@ -50,7 +50,7 @@ public class CompositeAMQDataBlock exten
return frameSize;
}
- public void writePayload(DataOutputStream buffer) throws IOException
+ public void writePayload(DataOutput buffer) throws IOException
{
for (int i = 0; i < _blocks.length; i++)
{
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBody.java Thu Mar 1 15:42:44 2012
@@ -20,9 +20,11 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
+import java.nio.ByteBuffer;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
import org.apache.qpid.AMQException;
@@ -37,10 +39,10 @@ public class ContentBody implements AMQB
{
}
- public ContentBody(DataInputStream buffer, long size) throws AMQFrameDecodingException, IOException
+ public ContentBody(DataInput buffer, long size) throws AMQFrameDecodingException, IOException
{
_payload = new byte[(int)size];
- buffer.read(_payload);
+ buffer.readFully(_payload);
}
@@ -59,7 +61,7 @@ public class ContentBody implements AMQB
return _payload == null ? 0 : _payload.length;
}
- public void writePayload(DataOutputStream buffer) throws IOException
+ public void writePayload(DataOutput buffer) throws IOException
{
buffer.write(_payload);
}
@@ -84,11 +86,62 @@ public class ContentBody implements AMQB
{
}
+ private static class BufferContentBody implements AMQBody
+ {
+ private final int _length;
+ private final int _offset;
+ private final ByteBuffer _buf;
+
+ private BufferContentBody( ByteBuffer buf, int offset, int length)
+ {
+ _length = length;
+ _offset = offset;
+ _buf = buf;
+ }
+
+ public byte getFrameType()
+ {
+ return TYPE;
+ }
+
+
+ public int getSize()
+ {
+ return _length;
+ }
+ public void writePayload(DataOutput buffer) throws IOException
+ {
+ if(_buf.hasArray())
+ {
+ buffer.write(_buf.array(), _buf.arrayOffset() + _offset, _length);
+ }
+ else
+ {
+ byte[] data = new byte[_length];
+ ByteBuffer buf = _buf.duplicate();
+
+ buf.position(_offset);
+ buf.limit(_offset+_length);
+ buf.get(data);
+ buffer.write(data);
+ }
+ }
+
+
+ public void handle(int channelId, AMQVersionAwareProtocolSession amqProtocolSession) throws AMQException
+ {
+ throw new RuntimeException("Buffered Body only to be used for outgoing data");
+ }
+ }
+
+ public static AMQFrame createAMQFrame(int channelId, ByteBuffer buf, int offset, int length)
+ {
+ return new AMQFrame(channelId, new BufferContentBody(buf, offset, length));
+ }
public static AMQFrame createAMQFrame(int channelId, ContentBody body)
{
- final AMQFrame frame = new AMQFrame(channelId, body);
- return frame;
+ return new AMQFrame(channelId, body);
}
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentBodyFactory.java Thu Mar 1 15:42:44 2012
@@ -20,9 +20,9 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
import java.io.IOException;
+import org.apache.qpid.codec.MarkableDataInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +42,7 @@ public class ContentBodyFactory implemen
_log.debug("Creating content body factory");
}
- public AMQBody createBody(DataInputStream in, long bodySize) throws AMQFrameDecodingException, IOException
+ public AMQBody createBody(MarkableDataInput in, long bodySize) throws AMQFrameDecodingException, IOException
{
return new ContentBody(in, bodySize);
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBody.java Thu Mar 1 15:42:44 2012
@@ -20,8 +20,9 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
@@ -45,7 +46,7 @@ public class ContentHeaderBody implement
{
}
- public ContentHeaderBody(DataInputStream buffer, long size) throws AMQFrameDecodingException, IOException
+ public ContentHeaderBody(DataInput buffer, long size) throws AMQFrameDecodingException, IOException
{
classId = buffer.readUnsignedShort();
weight = buffer.readUnsignedShort();
@@ -106,7 +107,7 @@ public class ContentHeaderBody implement
return 2 + 2 + 8 + 2 + properties.getPropertyListSize();
}
- public void writePayload(DataOutputStream buffer) throws IOException
+ public void writePayload(DataOutput buffer) throws IOException
{
EncodingUtils.writeUnsignedShort(buffer, classId);
EncodingUtils.writeUnsignedShort(buffer, weight);
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderBodyFactory.java Thu Mar 1 15:42:44 2012
@@ -20,9 +20,9 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
import java.io.IOException;
+import org.apache.qpid.codec.MarkableDataInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,7 +42,7 @@ public class ContentHeaderBodyFactory im
_log.debug("Creating content header body factory");
}
- public AMQBody createBody(DataInputStream in, long bodySize) throws AMQFrameDecodingException, IOException
+ public AMQBody createBody(MarkableDataInput in, long bodySize) throws AMQFrameDecodingException, IOException
{
// all content headers are the same - it is only the properties that differ.
// the content header body further delegates construction of properties
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderProperties.java Thu Mar 1 15:42:44 2012
@@ -20,8 +20,9 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
@@ -35,7 +36,7 @@ public interface ContentHeaderProperties
* Writes the property list to the buffer, in a suitably encoded form.
* @param buffer The buffer to write to
*/
- void writePropertyListPayload(DataOutputStream buffer) throws IOException;
+ void writePropertyListPayload(DataOutput buffer) throws IOException;
/**
* Populates the properties from buffer.
@@ -43,7 +44,7 @@ public interface ContentHeaderProperties
* @param propertyFlags he property flags.
* @throws AMQFrameDecodingException when the buffer does not contain valid data
*/
- void populatePropertiesFromBuffer(DataInputStream buffer, int propertyFlags, int size)
+ void populatePropertiesFromBuffer(DataInput buffer, int propertyFlags, int size)
throws AMQFrameDecodingException, IOException;
/**
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ContentHeaderPropertiesFactory.java Thu Mar 1 15:42:44 2012
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
@@ -39,7 +40,7 @@ public class ContentHeaderPropertiesFact
}
public ContentHeaderProperties createContentHeaderProperties(int classId, int propertyFlags,
- DataInputStream buffer, int size)
+ DataInput buffer, int size)
throws AMQFrameDecodingException, IOException
{
ContentHeaderProperties properties;
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/EncodingUtils.java Thu Mar 1 15:42:44 2012
@@ -219,7 +219,7 @@ public class EncodingUtils
return 0;
}
- public static void writeShortStringBytes(DataOutputStream buffer, String s) throws IOException
+ public static void writeShortStringBytes(DataOutput buffer, String s) throws IOException
{
if (s != null)
{
@@ -243,7 +243,7 @@ public class EncodingUtils
}
}
- public static void writeShortStringBytes(DataOutputStream buffer, AMQShortString s) throws IOException
+ public static void writeShortStringBytes(DataOutput buffer, AMQShortString s) throws IOException
{
if (s != null)
{
@@ -257,7 +257,7 @@ public class EncodingUtils
}
}
- public static void writeLongStringBytes(DataOutputStream buffer, String s) throws IOException
+ public static void writeLongStringBytes(DataOutput buffer, String s) throws IOException
{
assert (s == null) || (s.length() <= 0xFFFE);
if (s != null)
@@ -279,7 +279,7 @@ public class EncodingUtils
}
}
- public static void writeLongStringBytes(DataOutputStream buffer, char[] s) throws IOException
+ public static void writeLongStringBytes(DataOutput buffer, char[] s) throws IOException
{
assert (s == null) || (s.length <= 0xFFFE);
if (s != null)
@@ -300,7 +300,7 @@ public class EncodingUtils
}
}
- public static void writeLongStringBytes(DataOutputStream buffer, byte[] bytes) throws IOException
+ public static void writeLongStringBytes(DataOutput buffer, byte[] bytes) throws IOException
{
assert (bytes == null) || (bytes.length <= 0xFFFE);
if (bytes != null)
@@ -314,13 +314,13 @@ public class EncodingUtils
}
}
- public static void writeUnsignedByte(DataOutputStream buffer, short b) throws IOException
+ public static void writeUnsignedByte(DataOutput buffer, short b) throws IOException
{
byte bv = (byte) b;
buffer.write(bv);
}
- public static void writeUnsignedShort(DataOutputStream buffer, int s) throws IOException
+ public static void writeUnsignedShort(DataOutput buffer, int s) throws IOException
{
// TODO: Is this comparison safe? Do I need to cast RHS to long?
if (s < Short.MAX_VALUE)
@@ -340,7 +340,7 @@ public class EncodingUtils
return 4;
}
- public static void writeUnsignedInteger(DataOutputStream buffer, long l) throws IOException
+ public static void writeUnsignedInteger(DataOutput buffer, long l) throws IOException
{
// TODO: Is this comparison safe? Do I need to cast RHS to long?
if (l < Integer.MAX_VALUE)
@@ -360,7 +360,7 @@ public class EncodingUtils
}
}
- public static void writeFieldTableBytes(DataOutputStream buffer, FieldTable table) throws IOException
+ public static void writeFieldTableBytes(DataOutput buffer, FieldTable table) throws IOException
{
if (table != null)
{
@@ -372,12 +372,12 @@ public class EncodingUtils
}
}
- public static void writeContentBytes(DataOutputStream buffer, Content content)
+ public static void writeContentBytes(DataOutput buffer, Content content)
{
// TODO: New Content class required for AMQP 0-9.
}
- public static void writeBooleans(DataOutputStream buffer, boolean[] values) throws IOException
+ public static void writeBooleans(DataOutput buffer, boolean[] values) throws IOException
{
byte packedValue = 0;
for (int i = 0; i < values.length; i++)
@@ -391,13 +391,13 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value) throws IOException
+ public static void writeBooleans(DataOutput buffer, boolean value) throws IOException
{
buffer.write(value ? (byte) 1 : (byte) 0);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1) throws IOException
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -409,7 +409,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2) throws IOException
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -426,7 +426,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2, boolean value3) throws IOException
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2, boolean value3) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -448,7 +448,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2, boolean value3,
boolean value4) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -476,7 +476,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2, boolean value3,
boolean value4, boolean value5) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -509,7 +509,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2, boolean value3,
boolean value4, boolean value5, boolean value6) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -547,7 +547,7 @@ public class EncodingUtils
buffer.write(packedValue);
}
- public static void writeBooleans(DataOutputStream buffer, boolean value0, boolean value1, boolean value2, boolean value3,
+ public static void writeBooleans(DataOutput buffer, boolean value0, boolean value1, boolean value2, boolean value3,
boolean value4, boolean value5, boolean value6, boolean value7) throws IOException
{
byte packedValue = value0 ? (byte) 1 : (byte) 0;
@@ -596,7 +596,7 @@ public class EncodingUtils
* @param buffer
* @param data
*/
- public static void writeLongstr(DataOutputStream buffer, byte[] data) throws IOException
+ public static void writeLongstr(DataOutput buffer, byte[] data) throws IOException
{
if (data != null)
{
@@ -609,12 +609,12 @@ public class EncodingUtils
}
}
- public static void writeTimestamp(DataOutputStream buffer, long timestamp) throws IOException
+ public static void writeTimestamp(DataOutput buffer, long timestamp) throws IOException
{
writeLong(buffer, timestamp);
}
- public static boolean[] readBooleans(DataInputStream buffer) throws IOException
+ public static boolean[] readBooleans(DataInput buffer) throws IOException
{
final byte packedValue = buffer.readByte();
if (packedValue == 0)
@@ -641,7 +641,7 @@ public class EncodingUtils
return result;
}
- public static FieldTable readFieldTable(DataInputStream buffer) throws AMQFrameDecodingException, IOException
+ public static FieldTable readFieldTable(DataInput buffer) throws AMQFrameDecodingException, IOException
{
long length = ((long)(buffer.readInt())) & 0xFFFFFFFFL;
if (length == 0)
@@ -654,19 +654,19 @@ public class EncodingUtils
}
}
- public static Content readContent(DataInputStream buffer) throws AMQFrameDecodingException
+ public static Content readContent(DataInput buffer) throws AMQFrameDecodingException
{
// TODO: New Content class required for AMQP 0-9.
return null;
}
- public static AMQShortString readAMQShortString(DataInputStream buffer) throws IOException
+ public static AMQShortString readAMQShortString(DataInput buffer) throws IOException
{
return AMQShortString.readFromBuffer(buffer);
}
- public static String readShortString(DataInputStream buffer) throws IOException
+ public static String readShortString(DataInput buffer) throws IOException
{
short length = (short) (((short)buffer.readByte()) & 0xFF);
if (length == 0)
@@ -681,7 +681,7 @@ public class EncodingUtils
// this approach here is valid since we know that all the chars are
// ASCII (0-127)
byte[] stringBytes = new byte[length];
- buffer.read(stringBytes, 0, length);
+ buffer.readFully(stringBytes, 0, length);
char[] stringChars = new char[length];
for (int i = 0; i < stringChars.length; i++)
{
@@ -692,7 +692,7 @@ public class EncodingUtils
}
}
- public static String readLongString(DataInputStream buffer) throws IOException
+ public static String readLongString(DataInput buffer) throws IOException
{
long length = ((long)(buffer.readInt())) & 0xFFFFFFFFL;
if (length == 0)
@@ -707,7 +707,7 @@ public class EncodingUtils
// this approach here is valid since we know that all the chars are
// ASCII (0-127)
byte[] stringBytes = new byte[(int) length];
- buffer.read(stringBytes, 0, (int) length);
+ buffer.readFully(stringBytes, 0, (int) length);
char[] stringChars = new char[(int) length];
for (int i = 0; i < stringChars.length; i++)
{
@@ -718,7 +718,7 @@ public class EncodingUtils
}
}
- public static byte[] readLongstr(DataInputStream buffer) throws IOException
+ public static byte[] readLongstr(DataInput buffer) throws IOException
{
long length = ((long)(buffer.readInt())) & 0xFFFFFFFFL;
if (length == 0)
@@ -728,13 +728,13 @@ public class EncodingUtils
else
{
byte[] result = new byte[(int) length];
- buffer.read(result);
+ buffer.readFully(result);
return result;
}
}
- public static long readTimestamp(DataInputStream buffer) throws IOException
+ public static long readTimestamp(DataInput buffer) throws IOException
{
// Discard msb from AMQ timestamp
// buffer.getUnsignedInt();
@@ -818,12 +818,12 @@ public class EncodingUtils
// AMQP_BOOLEAN_PROPERTY_PREFIX
- public static void writeBoolean(DataOutputStream buffer, Boolean aBoolean) throws IOException
+ public static void writeBoolean(DataOutput buffer, boolean aBoolean) throws IOException
{
buffer.write(aBoolean ? 1 : 0);
}
- public static boolean readBoolean(DataInputStream buffer) throws IOException
+ public static boolean readBoolean(DataInput buffer) throws IOException
{
byte packedValue = buffer.readByte();
@@ -836,12 +836,12 @@ public class EncodingUtils
}
// AMQP_BYTE_PROPERTY_PREFIX
- public static void writeByte(DataOutputStream buffer, Byte aByte) throws IOException
+ public static void writeByte(DataOutput buffer, byte aByte) throws IOException
{
buffer.writeByte(aByte);
}
- public static byte readByte(DataInputStream buffer) throws IOException
+ public static byte readByte(DataInput buffer) throws IOException
{
return buffer.readByte();
}
@@ -852,12 +852,12 @@ public class EncodingUtils
}
// AMQP_SHORT_PROPERTY_PREFIX
- public static void writeShort(DataOutputStream buffer, Short aShort) throws IOException
+ public static void writeShort(DataOutput buffer, short aShort) throws IOException
{
buffer.writeShort(aShort);
}
- public static short readShort(DataInputStream buffer) throws IOException
+ public static short readShort(DataInput buffer) throws IOException
{
return buffer.readShort();
}
@@ -868,12 +868,12 @@ public class EncodingUtils
}
// INTEGER_PROPERTY_PREFIX
- public static void writeInteger(DataOutputStream buffer, Integer aInteger) throws IOException
+ public static void writeInteger(DataOutput buffer, int aInteger) throws IOException
{
buffer.writeInt(aInteger);
}
- public static int readInteger(DataInputStream buffer) throws IOException
+ public static int readInteger(DataInput buffer) throws IOException
{
return buffer.readInt();
}
@@ -884,12 +884,12 @@ public class EncodingUtils
}
// AMQP_LONG_PROPERTY_PREFIX
- public static void writeLong(DataOutputStream buffer, Long aLong) throws IOException
+ public static void writeLong(DataOutput buffer, long aLong) throws IOException
{
buffer.writeLong(aLong);
}
- public static long readLong(DataInputStream buffer) throws IOException
+ public static long readLong(DataInput buffer) throws IOException
{
return buffer.readLong();
}
@@ -900,12 +900,12 @@ public class EncodingUtils
}
// Float_PROPERTY_PREFIX
- public static void writeFloat(DataOutputStream buffer, Float aFloat) throws IOException
+ public static void writeFloat(DataOutput buffer, float aFloat) throws IOException
{
buffer.writeFloat(aFloat);
}
- public static float readFloat(DataInputStream buffer) throws IOException
+ public static float readFloat(DataInput buffer) throws IOException
{
return buffer.readFloat();
}
@@ -916,12 +916,12 @@ public class EncodingUtils
}
// Double_PROPERTY_PREFIX
- public static void writeDouble(DataOutputStream buffer, Double aDouble) throws IOException
+ public static void writeDouble(DataOutput buffer, Double aDouble) throws IOException
{
buffer.writeDouble(aDouble);
}
- public static double readDouble(DataInputStream buffer) throws IOException
+ public static double readDouble(DataInput buffer) throws IOException
{
return buffer.readDouble();
}
@@ -931,7 +931,7 @@ public class EncodingUtils
return 8;
}
- public static byte[] readBytes(DataInputStream buffer) throws IOException
+ public static byte[] readBytes(DataInput buffer) throws IOException
{
long length = ((long)(buffer.readInt())) & 0xFFFFFFFFL;
if (length == 0)
@@ -941,13 +941,13 @@ public class EncodingUtils
else
{
byte[] dataBytes = new byte[(int)length];
- buffer.read(dataBytes, 0, (int) length);
+ buffer.readFully(dataBytes, 0, (int) length);
return dataBytes;
}
}
- public static void writeBytes(DataOutputStream buffer, byte[] data) throws IOException
+ public static void writeBytes(DataOutput buffer, byte[] data) throws IOException
{
if (data != null)
{
@@ -969,19 +969,19 @@ public class EncodingUtils
return encodedByteLength();
}
- public static char readChar(DataInputStream buffer) throws IOException
+ public static char readChar(DataInput buffer) throws IOException
{
// This is valid as we know that the Character is ASCII 0..127
- return (char) buffer.read();
+ return (char) buffer.readByte();
}
- public static void writeChar(DataOutputStream buffer, char character) throws IOException
+ public static void writeChar(DataOutput buffer, char character) throws IOException
{
// This is valid as we know that the Character is ASCII 0..127
writeByte(buffer, (byte) character);
}
- public static long readLongAsShortString(DataInputStream buffer) throws IOException
+ public static long readLongAsShortString(DataInput buffer) throws IOException
{
short length = (short) buffer.readUnsignedByte();
short pos = 0;
@@ -1018,7 +1018,7 @@ public class EncodingUtils
return result;
}
- public static long readUnsignedInteger(DataInputStream buffer) throws IOException
+ public static long readUnsignedInteger(DataInput buffer) throws IOException
{
long l = 0xFF & buffer.readByte();
l <<= 8;
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java Thu Mar 1 15:42:44 2012
@@ -25,11 +25,7 @@ import org.slf4j.LoggerFactory;
import org.apache.qpid.AMQPInvalidClassException;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
+import java.io.*;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.Enumeration;
@@ -44,18 +40,27 @@ import java.util.Set;
public class FieldTable
{
private static final Logger _logger = LoggerFactory.getLogger(FieldTable.class);
- private static final String STRICT_AMQP = "STRICT_AMQP";
- private final boolean _strictAMQP = Boolean.valueOf(System.getProperty(STRICT_AMQP, "false"));
+ private static final String STRICT_AMQP_NAME = "STRICT_AMQP";
+ private static final boolean STRICT_AMQP = Boolean.valueOf(System.getProperty(STRICT_AMQP_NAME, "false"));
private byte[] _encodedForm;
+ private int _encodedFormOffset;
private LinkedHashMap<AMQShortString, AMQTypedValue> _properties = null;
private long _encodedSize;
private static final int INITIAL_HASHMAP_CAPACITY = 16;
private static final int INITIAL_ENCODED_FORM_SIZE = 256;
+ private final boolean _strictAMQP;
public FieldTable()
{
+ this(STRICT_AMQP);
+ }
+
+
+ public FieldTable(boolean strictAMQP)
+ {
super();
+ _strictAMQP = strictAMQP;
}
/**
@@ -64,14 +69,28 @@ public class FieldTable
* @param buffer the buffer from which to read data. The length byte must be read already
* @param length the length of the field table. Must be > 0.
*/
- public FieldTable(DataInputStream buffer, long length) throws IOException
+ public FieldTable(DataInput buffer, long length) throws IOException
{
this();
_encodedForm = new byte[(int) length];
- buffer.read(_encodedForm);
+ buffer.readFully(_encodedForm);
_encodedSize = length;
}
+ public FieldTable(byte[] encodedForm, int offset, int length) throws IOException
+ {
+ this();
+ _encodedForm = encodedForm;
+ _encodedFormOffset = offset;
+ _encodedSize = length;
+ }
+
+
+ public boolean isClean()
+ {
+ return _encodedForm != null;
+ }
+
public AMQTypedValue getProperty(AMQShortString string)
{
checkPropertyName(string);
@@ -181,7 +200,7 @@ public class FieldTable
public Boolean getBoolean(String string)
{
- return getBoolean(new AMQShortString(string));
+ return getBoolean(AMQShortString.valueOf(string));
}
public Boolean getBoolean(AMQShortString string)
@@ -199,7 +218,7 @@ public class FieldTable
public Byte getByte(String string)
{
- return getByte(new AMQShortString(string));
+ return getByte(AMQShortString.valueOf(string));
}
public Byte getByte(AMQShortString string)
@@ -217,7 +236,7 @@ public class FieldTable
public Short getShort(String string)
{
- return getShort(new AMQShortString(string));
+ return getShort(AMQShortString.valueOf(string));
}
public Short getShort(AMQShortString string)
@@ -235,7 +254,7 @@ public class FieldTable
public Integer getInteger(String string)
{
- return getInteger(new AMQShortString(string));
+ return getInteger(AMQShortString.valueOf(string));
}
public Integer getInteger(AMQShortString string)
@@ -253,7 +272,7 @@ public class FieldTable
public Long getLong(String string)
{
- return getLong(new AMQShortString(string));
+ return getLong(AMQShortString.valueOf(string));
}
public Long getLong(AMQShortString string)
@@ -271,7 +290,7 @@ public class FieldTable
public Float getFloat(String string)
{
- return getFloat(new AMQShortString(string));
+ return getFloat(AMQShortString.valueOf(string));
}
public Float getFloat(AMQShortString string)
@@ -289,7 +308,7 @@ public class FieldTable
public Double getDouble(String string)
{
- return getDouble(new AMQShortString(string));
+ return getDouble(AMQShortString.valueOf(string));
}
public Double getDouble(AMQShortString string)
@@ -307,7 +326,7 @@ public class FieldTable
public String getString(String string)
{
- return getString(new AMQShortString(string));
+ return getString(AMQShortString.valueOf(string));
}
public String getString(AMQShortString string)
@@ -330,7 +349,7 @@ public class FieldTable
public Character getCharacter(String string)
{
- return getCharacter(new AMQShortString(string));
+ return getCharacter(AMQShortString.valueOf(string));
}
public Character getCharacter(AMQShortString string)
@@ -348,7 +367,7 @@ public class FieldTable
public byte[] getBytes(String string)
{
- return getBytes(new AMQShortString(string));
+ return getBytes(AMQShortString.valueOf(string));
}
public byte[] getBytes(AMQShortString string)
@@ -374,7 +393,7 @@ public class FieldTable
*/
public FieldTable getFieldTable(String string)
{
- return getFieldTable(new AMQShortString(string));
+ return getFieldTable(AMQShortString.valueOf(string));
}
/**
@@ -401,7 +420,7 @@ public class FieldTable
public Object getObject(String string)
{
- return getObject(new AMQShortString(string));
+ return getObject(AMQShortString.valueOf(string));
}
public Object getObject(AMQShortString string)
@@ -447,7 +466,7 @@ public class FieldTable
// ************ Setters
public Object setBoolean(String string, Boolean b)
{
- return setBoolean(new AMQShortString(string), b);
+ return setBoolean(AMQShortString.valueOf(string), b);
}
public Object setBoolean(AMQShortString string, Boolean b)
@@ -457,7 +476,7 @@ public class FieldTable
public Object setByte(String string, Byte b)
{
- return setByte(new AMQShortString(string), b);
+ return setByte(AMQShortString.valueOf(string), b);
}
public Object setByte(AMQShortString string, Byte b)
@@ -467,7 +486,7 @@ public class FieldTable
public Object setShort(String string, Short i)
{
- return setShort(new AMQShortString(string), i);
+ return setShort(AMQShortString.valueOf(string), i);
}
public Object setShort(AMQShortString string, Short i)
@@ -475,29 +494,29 @@ public class FieldTable
return setProperty(string, AMQType.SHORT.asTypedValue(i));
}
- public Object setInteger(String string, Integer i)
+ public Object setInteger(String string, int i)
{
- return setInteger(new AMQShortString(string), i);
+ return setInteger(AMQShortString.valueOf(string), i);
}
- public Object setInteger(AMQShortString string, Integer i)
+ public Object setInteger(AMQShortString string, int i)
{
- return setProperty(string, AMQType.INT.asTypedValue(i));
+ return setProperty(string, AMQTypedValue.createAMQTypedValue(i));
}
- public Object setLong(String string, Long l)
+ public Object setLong(String string, long l)
{
- return setLong(new AMQShortString(string), l);
+ return setLong(AMQShortString.valueOf(string), l);
}
- public Object setLong(AMQShortString string, Long l)
+ public Object setLong(AMQShortString string, long l)
{
- return setProperty(string, AMQType.LONG.asTypedValue(l));
+ return setProperty(string, AMQTypedValue.createAMQTypedValue(l));
}
public Object setFloat(String string, Float f)
{
- return setFloat(new AMQShortString(string), f);
+ return setFloat(AMQShortString.valueOf(string), f);
}
public Object setFloat(AMQShortString string, Float v)
@@ -507,7 +526,7 @@ public class FieldTable
public Object setDouble(String string, Double d)
{
- return setDouble(new AMQShortString(string), d);
+ return setDouble(AMQShortString.valueOf(string), d);
}
public Object setDouble(AMQShortString string, Double v)
@@ -517,7 +536,7 @@ public class FieldTable
public Object setString(String string, String s)
{
- return setString(new AMQShortString(string), s);
+ return setString(AMQShortString.valueOf(string), s);
}
public Object setAsciiString(AMQShortString string, String value)
@@ -546,7 +565,7 @@ public class FieldTable
public Object setChar(String string, char c)
{
- return setChar(new AMQShortString(string), c);
+ return setChar(AMQShortString.valueOf(string), c);
}
public Object setChar(AMQShortString string, char c)
@@ -556,7 +575,7 @@ public class FieldTable
public Object setBytes(String string, byte[] b)
{
- return setBytes(new AMQShortString(string), b);
+ return setBytes(AMQShortString.valueOf(string), b);
}
public Object setBytes(AMQShortString string, byte[] bytes)
@@ -566,7 +585,7 @@ public class FieldTable
public Object setBytes(String string, byte[] bytes, int start, int length)
{
- return setBytes(new AMQShortString(string), bytes, start, length);
+ return setBytes(AMQShortString.valueOf(string), bytes, start, length);
}
public Object setBytes(AMQShortString string, byte[] bytes, int start, int length)
@@ -579,7 +598,7 @@ public class FieldTable
public Object setObject(String string, Object o)
{
- return setObject(new AMQShortString(string), o);
+ return setObject(AMQShortString.valueOf(string), o);
}
public Object setTimestamp(AMQShortString string, long datetime)
@@ -617,7 +636,7 @@ public class FieldTable
*/
public Object setFieldTable(String string, FieldTable ftValue)
{
- return setFieldTable(new AMQShortString(string), ftValue);
+ return setFieldTable(AMQShortString.valueOf(string), ftValue);
}
/**
@@ -681,7 +700,7 @@ public class FieldTable
public boolean isNullStringValue(String name)
{
- AMQTypedValue value = getProperty(new AMQShortString(name));
+ AMQTypedValue value = getProperty(AMQShortString.valueOf(name));
return (value != null) && (value.getType() == AMQType.VOID);
}
@@ -713,7 +732,7 @@ public class FieldTable
public boolean itemExists(String string)
{
- return itemExists(new AMQShortString(string));
+ return itemExists(AMQShortString.valueOf(string));
}
public String toString()
@@ -769,7 +788,7 @@ public class FieldTable
// ************************* Byte Buffer Processing
- public void writeToBuffer(DataOutputStream buffer) throws IOException
+ public void writeToBuffer(DataOutput buffer) throws IOException
{
final boolean trace = _logger.isDebugEnabled();
@@ -919,7 +938,7 @@ public class FieldTable
public boolean containsKey(String key)
{
- return containsKey(new AMQShortString(key));
+ return containsKey(AMQShortString.valueOf(key));
}
public Set<String> keys()
@@ -942,7 +961,7 @@ public class FieldTable
public Object get(String key)
{
- return get(new AMQShortString(key));
+ return get(AMQShortString.valueOf(key));
}
public Object get(AMQShortString key)
@@ -958,7 +977,7 @@ public class FieldTable
public Object remove(String key)
{
- return remove(new AMQShortString(key));
+ return remove(AMQShortString.valueOf(key));
}
@@ -1005,12 +1024,12 @@ public class FieldTable
return _properties.keySet();
}
- private void putDataInBuffer(DataOutputStream buffer) throws IOException
+ private void putDataInBuffer(DataOutput buffer) throws IOException
{
if (_encodedForm != null)
{
- buffer.write(_encodedForm);
+ buffer.write(_encodedForm,_encodedFormOffset,(int)_encodedSize);
}
else if (_properties != null)
{
@@ -1039,9 +1058,8 @@ public class FieldTable
private void setFromBuffer() throws AMQFrameDecodingException, IOException
{
- final ByteArrayInputStream in = new ByteArrayInputStream(_encodedForm);
- DataInputStream buffer = new DataInputStream(in);
- final boolean trace = _logger.isDebugEnabled();
+ ByteArrayDataInput baid = new ByteArrayDataInput(_encodedForm, _encodedFormOffset, (int)_encodedSize);
+
if (_encodedSize > 0)
{
@@ -1051,12 +1069,12 @@ public class FieldTable
do
{
- final AMQShortString key = EncodingUtils.readAMQShortString(buffer);
- AMQTypedValue value = AMQTypedValue.readFromBuffer(buffer);
+ final AMQShortString key = baid.readAMQShortString();
+ AMQTypedValue value = AMQTypedValue.readFromBuffer(baid);
_properties.put(key, value);
}
- while (in.available() > 0);
+ while (baid.available() > 0);
}
@@ -1101,7 +1119,7 @@ public class FieldTable
FieldTable table = new FieldTable();
for(Map.Entry<String,Object> entry : map.entrySet())
{
- table.put(new AMQShortString(entry.getKey()), entry.getValue());
+ table.put(AMQShortString.valueOf(entry.getKey()), entry.getValue());
}
return table;
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTableFactory.java Thu Mar 1 15:42:44 2012
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.framing;
+import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
@@ -30,7 +31,7 @@ public class FieldTableFactory
return new FieldTable();
}
- public static FieldTable newFieldTable(DataInputStream byteBuffer, long length) throws AMQFrameDecodingException, IOException
+ public static FieldTable newFieldTable(DataInput byteBuffer, long length) throws AMQFrameDecodingException, IOException
{
return new FieldTable(byteBuffer, length);
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBody.java Thu Mar 1 15:42:44 2012
@@ -21,7 +21,7 @@
package org.apache.qpid.framing;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
import org.apache.qpid.protocol.AMQVersionAwareProtocolSession;
@@ -56,7 +56,7 @@ public class HeartbeatBody implements AM
return 0;//heartbeats we generate have no payload
}
- public void writePayload(DataOutputStream buffer)
+ public void writePayload(DataOutput buffer)
{
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/HeartbeatBodyFactory.java Thu Mar 1 15:42:44 2012
@@ -20,12 +20,13 @@
*/
package org.apache.qpid.framing;
-import java.io.DataInputStream;
+import org.apache.qpid.codec.MarkableDataInput;
public class HeartbeatBodyFactory implements BodyFactory
{
- public AMQBody createBody(DataInputStream in, long bodySize) throws AMQFrameDecodingException
+ public AMQBody createBody(MarkableDataInput in, long bodySize) throws AMQFrameDecodingException
{
return new HeartbeatBody();
}
+
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/ProtocolInitiation.java Thu Mar 1 15:42:44 2012
@@ -21,13 +21,10 @@
package org.apache.qpid.framing;
import org.apache.qpid.AMQException;
+import org.apache.qpid.codec.MarkableDataInput;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
+import java.io.*;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
import java.util.Arrays;
public class ProtocolInitiation extends AMQDataBlock implements EncodableAMQDataBlock
@@ -66,7 +63,7 @@ public class ProtocolInitiation extends
pv.equals(ProtocolVersion.v0_91) ? 1 : pv.getMinorVersion());
}
- public ProtocolInitiation(DataInputStream in) throws IOException
+ public ProtocolInitiation(MarkableDataInput in) throws IOException
{
_protocolHeader = new byte[4];
in.read(_protocolHeader);
@@ -82,7 +79,7 @@ public class ProtocolInitiation extends
return 4 + 1 + 1 + 1 + 1;
}
- public void writePayload(DataOutputStream buffer) throws IOException
+ public void writePayload(DataOutput buffer) throws IOException
{
buffer.write(_protocolHeader);
@@ -143,7 +140,7 @@ public class ProtocolInitiation extends
* @return true if we have enough data to decode the PI frame fully, false if more
* data is required
*/
- public boolean decodable(DataInputStream in) throws IOException
+ public boolean decodable(MarkableDataInput in) throws IOException
{
return (in.available() >= 8);
}
Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/SmallCompositeAMQDataBlock.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/SmallCompositeAMQDataBlock.java?rev=1295627&r1=1295626&r2=1295627&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/SmallCompositeAMQDataBlock.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/common/src/main/java/org/apache/qpid/framing/SmallCompositeAMQDataBlock.java Thu Mar 1 15:42:44 2012
@@ -21,7 +21,7 @@
package org.apache.qpid.framing;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
public class SmallCompositeAMQDataBlock extends AMQDataBlock implements EncodableAMQDataBlock
@@ -69,7 +69,7 @@ public class SmallCompositeAMQDataBlock
return frameSize;
}
- public void writePayload(DataOutputStream buffer) throws IOException
+ public void writePayload(DataOutput buffer) throws IOException
{
if (_firstFrame != null)
{
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org