diff options
| author | Kim van der Riet <kpvdr@apache.org> | 2007-01-18 21:39:29 +0000 |
|---|---|---|
| committer | Kim van der Riet <kpvdr@apache.org> | 2007-01-18 21:39:29 +0000 |
| commit | 8a5d46b686eebfc0caf2f1e92eae3dea7b868ebd (patch) | |
| tree | 281f62cc2fe708a5d76d1986fc65e6a491ef2e56 /java/common | |
| parent | 93bddfd4c9260f958eab861a8a43db55bb836690 (diff) | |
| download | qpid-python-8a5d46b686eebfc0caf2f1e92eae3dea7b868ebd.tar.gz | |
Changed Content to use ByteBuffer, added Message.Transfer and Message.Cancel handlers
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@497585 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
| -rw-r--r-- | java/common/src/main/java/org/apache/qpid/framing/Content.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/framing/Content.java b/java/common/src/main/java/org/apache/qpid/framing/Content.java index d1d8c66995..4008ead21f 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/Content.java +++ b/java/common/src/main/java/org/apache/qpid/framing/Content.java @@ -43,7 +43,7 @@ public class Content } public ContentTypeEnum contentType; - public byte[] content; + public ByteBuffer content; // Constructors @@ -63,20 +63,13 @@ public class Content throw new IllegalArgumentException("Content cannot be empty for a ref type."); } this.contentType = contentType; - this.content = content; + this.content = ByteBuffer.allocate(content.length); + this.content.put(content); } - public Content(ContentTypeEnum contentType, String content) + public Content(ContentTypeEnum contentType, String contentStr) { - if (contentType == ContentTypeEnum.CONTENT_TYPE_REFERENCE) - { - if (content == null) - throw new IllegalArgumentException("Content cannot be null for a ref type."); - if (content.length() == 0) - throw new IllegalArgumentException("Content cannot be empty for a ref type."); - } - this.contentType = contentType; - this.content = content.getBytes(); + this(contentType, contentStr.getBytes()); } public Content(ContentTypeEnum contentType, ByteBuffer content) @@ -89,18 +82,26 @@ public class Content throw new IllegalArgumentException("Content cannot be empty for a ref type."); } this.contentType = contentType; - this.content = content.array(); + this.content = content; } // Get functions public ContentTypeEnum getContentType() { return contentType; } - public byte[] getContent() { return content; } + public ByteBuffer getContent() { return content; } + + public byte[] getContentAsByteArray() + { + byte[] ba = new byte[content.remaining()]; + content.get(ba); + return ba; + } + public String getContentAsString() { if (content == null) return null; - return new String(content); + return new String(getContentAsByteArray()); } // Wire functions @@ -109,18 +110,22 @@ public class Content { if (content == null) return 1 + 4; - return 1 + 4 + content.length; + return 1 + 4 + content.remaining(); } public void writePayload(ByteBuffer buffer) { EncodingUtils.writeUnsignedByte(buffer, contentType.toByte()); - EncodingUtils.writeLongStringBytes(buffer, content); + EncodingUtils.writeUnsignedInteger(buffer, content.remaining()); + buffer.put(content); } public void populateFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException { contentType = ContentTypeEnum.toContentEnum(buffer.get()); - content = EncodingUtils.readLongstr(buffer); + int length = buffer.getInt(); + content = buffer.slice(); + buffer.skip(length); + content.limit(length); } } |
