1 25 26 package org.objectweb.easybeans.component.smartclient.message; 27 28 import java.nio.ByteBuffer ; 29 30 34 public abstract class AbsNameBytesMessage extends AbsMessage { 35 36 39 private String name = null; 40 41 44 private byte[] bytes = null; 45 46 51 public AbsNameBytesMessage(final String name, final byte[] bytes) { 52 super(); 53 this.name = name; 54 this.bytes = bytes; 55 } 56 57 61 public AbsNameBytesMessage(final ByteBuffer dataBuffer) { 62 super(); 63 int lengthName = dataBuffer.getInt(); 65 66 67 ByteBuffer nameBuffer = ByteBuffer.allocate(lengthName); 69 for (int l = 0; l < lengthName; l++) { 70 byte b = dataBuffer.get(); 71 nameBuffer.put(b); 72 } 73 nameBuffer.position(0); 75 this.name = decode(nameBuffer); 77 78 this.bytes = new byte[dataBuffer.limit() - dataBuffer.position()]; 80 int k = 0; 81 for (int i = dataBuffer.position(); i < dataBuffer.limit(); i++) { 82 this.bytes[k++] = dataBuffer.get(i); 83 } 84 85 } 86 87 91 @Override 92 public abstract byte getOpCode(); 93 94 98 @Override 99 public ByteBuffer getSubMessage() { 100 ByteBuffer nameBuffer = encode(name); 102 nameBuffer.position(0); 103 104 ByteBuffer messageBuffer = ByteBuffer.allocate(INT_BYTE_SIZE + nameBuffer.capacity() + bytes.length); 106 107 messageBuffer.putInt(nameBuffer.capacity()); 109 110 messageBuffer.put(nameBuffer); 112 113 messageBuffer.put(bytes); 115 116 return messageBuffer; 117 } 118 119 123 public String getName() { 124 return name; 125 } 126 127 131 public byte[] getBytes() { 132 return bytes; 133 } 134 } 135 | Popular Tags |