public void writeArray(double[] ref, int off, int len) throws IOException {
   if (TIME_DATA_SERIALIZATION) {
     timer.start();
   }
   writeArrayDouble(ref, off, len);
   if (TIME_DATA_SERIALIZATION) {
     timer.stop();
   }
 }
 public void writeByteBuffer(ByteBuffer value) throws IOException {
   if (TIME_DATA_SERIALIZATION) {
     timer.start();
   }
   internalWriteByteBuffer(value);
   if (TIME_DATA_SERIALIZATION) {
     timer.stop();
   }
 }
 /**
  * Writes a double value to the accumulator.
  *
  * @param value The double value to write.
  * @exception IOException on IO error.
  */
 public void writeDouble(double value) throws IOException {
   if (TIME_DATA_SERIALIZATION) {
     timer.start();
   }
   if (NO_ARRAY_BUFFERS) {
     out.writeDouble(value);
   } else {
     if (double_index == double_buffer.length) {
       internalFlush();
     }
     double_buffer[double_index++] = value;
   }
   if (DEBUG && logger.isDebugEnabled()) {
     logger.debug("wrote double " + value);
   }
   if (TIME_DATA_SERIALIZATION) {
     timer.stop();
   }
 }
 /**
  * Writes a int value to the accumulator.
  *
  * @param value The int value to write.
  * @exception IOException on IO error.
  */
 public void writeInt(int value) throws IOException {
   if (TIME_DATA_SERIALIZATION) {
     timer.start();
   }
   if (NO_ARRAY_BUFFERS) {
     out.writeInt(value);
   } else {
     if (int_index == int_buffer.length) {
       internalFlush();
     }
     int_buffer[int_index++] = value;
   }
   if (DEBUG && logger.isDebugEnabled()) {
     logger.debug("wrote int[HEX] " + value + "[0x" + Integer.toHexString(value) + "]");
   }
   if (TIME_DATA_SERIALIZATION) {
     timer.stop();
   }
 }
 /**
  * Writes a boolean value to the accumulator.
  *
  * @param value The boolean value to write.
  * @exception IOException on IO error.
  */
 public void writeBoolean(boolean value) throws IOException {
   if (TIME_DATA_SERIALIZATION) {
     timer.start();
   }
   if (NO_ARRAY_BUFFERS) {
     out.writeBoolean(value);
   } else {
     if (byte_index == byte_buffer.length) {
       internalFlush();
     }
     byte_buffer[byte_index++] = (byte) (value ? 1 : 0);
   }
   if (DEBUG && logger.isDebugEnabled()) {
     logger.debug("wrote boolean " + value);
   }
   if (TIME_DATA_SERIALIZATION) {
     timer.stop();
   }
 }
  public void writeUTF(String str) throws IOException {
    if (TIME_DATA_SERIALIZATION) {
      timer.start();
    }
    if (str == null) {
      writeInt(-1);
      if (TIME_DATA_SERIALIZATION) {
        timer.stop();
      }
      return;
    }

    if (DEBUG && logger.isDebugEnabled()) {
      logger.debug("write UTF " + str);
    }
    int len = str.length();

    // writeInt(len);
    // writeArray(str.toCharArray(), 0, len);

    int bn = 0;

    for (int i = 0; i < len; i++) {
      int c = str.charAt(i); // widening char to int zero-extends
      if (c > 0x0000 && c <= 0x007f) {
        bn++;
      } else if (c <= 0x07ff) {
        bn += 2;
      } else {
        bn += 3;
      }
    }

    byte[] b = new byte[bn];
    bn = 0;

    for (int i = 0; i < len; i++) {
      int c = str.charAt(i); // widening char to int zero-extends
      if (c > 0x0000 && c <= 0x007f) {
        b[bn++] = (byte) c;
      } else if (c <= 0x07ff) {
        b[bn++] = (byte) (0xc0 | (0x1f & (c >> 6)));
        b[bn++] = (byte) (0x80 | (0x3f & c));
      } else {
        b[bn++] = (byte) (0xe0 | (0x0f & (c >> 12)));
        b[bn++] = (byte) (0x80 | (0x3f & (c >> 6)));
        b[bn++] = (byte) (0x80 | (0x3f & c));
      }
    }
    if (DEBUG && logger.isDebugEnabled()) {
      logger.debug("writeUTF: len = " + bn);
      for (int i = 0; i < bn; i++) {
        logger.debug("writeUTF: b[" + i + "] = " + (b[i] & 0xff));
      }
    }

    writeInt(bn);
    writeArrayByte(b, 0, bn);
    if (TIME_DATA_SERIALIZATION) {
      timer.stop();
    }
  }