示例#1
0
 /** Copy the src into this MessageBytes, allocating more space if needed */
 public void duplicate(MessageBytes src) throws IOException {
   switch (src.getType()) {
     case MessageBytes.T_BYTES:
       type = T_BYTES;
       ByteChunk bc = src.getByteChunk();
       byteC.allocate(2 * bc.getLength(), -1);
       byteC.append(bc);
       break;
     case MessageBytes.T_CHARS:
       type = T_CHARS;
       CharChunk cc = src.getCharChunk();
       charC.allocate(2 * cc.getLength(), -1);
       charC.append(cc);
       break;
     case MessageBytes.T_STR:
       type = T_STR;
       String sc = src.getString();
       this.setString(sc);
       break;
   }
 }
示例#2
0
 /** Set the buffer to the representation of an long */
 public void setLong(long l) {
   byteC.allocate(32, 64);
   long current = l;
   byte[] buf = byteC.getBuffer();
   int start = 0;
   int end = 0;
   if (l == 0) {
     buf[end++] = (byte) '0';
   }
   if (l < 0) {
     current = -l;
     buf[end++] = (byte) '-';
   }
   while (current > 0) {
     int digit = (int) (current % 10);
     current = current / 10;
     buf[end++] = HexUtils.HEX[digit];
   }
   byteC.setOffset(0);
   byteC.setEnd(end);
   // Inverting buffer
   end--;
   if (l < 0) {
     start++;
   }
   while (end > start) {
     byte temp = buf[start];
     buf[start] = buf[end];
     buf[end] = temp;
     start++;
     end--;
   }
   longValue = l;
   hasStrValue = false;
   hasHashCode = false;
   hasIntValue = false;
   hasLongValue = true;
   hasDateValue = false;
   type = T_BYTES;
 }