01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 package org.apache.qpid.framing;
23
24 import org.apache.mina.common.ByteBuffer;
25
26 public class SmallCompositeAMQDataBlock extends AMQDataBlock implements EncodableAMQDataBlock
27 {
28 private AMQDataBlock _firstFrame;
29
30 private AMQDataBlock _block;
31
32 public SmallCompositeAMQDataBlock(AMQDataBlock block)
33 {
34 _block = block;
35 }
36
37 /**
38 * The encoded block will be logically first before the AMQDataBlocks which are encoded
39 * into the buffer afterwards.
40 * @param encodedBlock already-encoded data
41 * @param block a block to be encoded.
42 */
43 public SmallCompositeAMQDataBlock(AMQDataBlock encodedBlock, AMQDataBlock block)
44 {
45 this(block);
46 _firstFrame = encodedBlock;
47 }
48
49 public AMQDataBlock getBlock()
50 {
51 return _block;
52 }
53
54 public AMQDataBlock getFirstFrame()
55 {
56 return _firstFrame;
57 }
58
59 public long getSize()
60 {
61 long frameSize = _block.getSize();
62
63 if (_firstFrame != null)
64 {
65
66 frameSize += _firstFrame.getSize();
67 }
68 return frameSize;
69 }
70
71 public void writePayload(ByteBuffer buffer)
72 {
73 if (_firstFrame != null)
74 {
75 _firstFrame.writePayload(buffer);
76 }
77 _block.writePayload(buffer);
78
79 }
80
81 public String toString()
82 {
83 if (_block == null)
84 {
85 return "No blocks contained in composite frame";
86 }
87 else
88 {
89 StringBuilder buf = new StringBuilder(this.getClass().getName());
90 buf.append("{encodedBlock=").append(_firstFrame);
91
92 buf.append(" _block=[").append(_block.toString()).append("]");
93
94 buf.append("}");
95 return buf.toString();
96 }
97 }
98 }
|