/**
   * Put a value into the buffer. If buffer is full older values are overwritten.
   *
   * @param value the value
   */
  public void put(byte value) {
    lock.lock(); // lock this object
    // while no empty locations, place thread in waiting state
    try {
      while (size == buffer.length) {
        if (writeBlocking) {
          // System.out.println("wait write");
          notFull.await(); // await until a buffer element is free
        } else {
          lock.unlock();
          return;
        }
      } // end while
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    buffer[putIndex] = value; // set new buffer value

    putByte(value);

    notEmpty.signal(); // signal threads waiting to read from buffer
    lock.unlock(); // unlock this object
  } // end method put
 /**
  * Write.
  *
  * @param cbuf the cbuf
  * @param off the off
  * @param len the len
  */
 public void write(char[] cbuf, int off, int len) {
   lock.lock(); // lock this object
   for (int i = off; i < off + len - 1; i++) putByte((byte) cbuf[i]);
   notEmpty.signal(); // signal threads waiting to read from buffer
   lock.unlock(); // unlock this object
 }