@Override public void write(byte[] buffer,int offset,int count) throws IOException {
synchronized (intThread) {
    int avail=(wroteIndex - dataEndIndex + data.length) % data.length;
    if (avail == 0)     avail=data.length;
    if (avail < count) {
      throw new IOException("Buffer overrun, have " + avail + " bytes available and want to write "+ count);
    }
    if (count > data.length - dataEndIndex) {
      int firstPart=data.length - dataEndIndex;
      int secondPart=count - firstPart;
      System.arraycopy(buffer,offset,data,dataEndIndex,firstPart);
      System.arraycopy(buffer,offset + firstPart,data,0,secondPart);
      dataEndIndex=secondPart;
    }
 else {
      System.arraycopy(buffer,offset,data,dataEndIndex,count);
      dataEndIndex+=count;
    }
    intThread.notify();
  }
}

@ Override public void write ( byte [ ] buffer , int offset , int count ) throws IOException { synchronized ( intThread ) { int avail = ( wroteIndex - dataEndIndex + data . length ) % data . length ; if ( avail == 0 ) avail = data . length ; if ( avail < count ) { throw new IOException ( "Buffer overrun, have " + avail + " bytes available and want to write " + count ) ; } if ( count > data . length - dataEndIndex ) { int firstPart = data . length - dataEndIndex ; int secondPart = count - firstPart ; System . arraycopy ( buffer , offset , data , dataEndIndex , firstPart ) ; System . arraycopy ( buffer , offset + firstPart , data , 0 , secondPart ) ; dataEndIndex = secondPart ; } else { System . arraycopy ( buffer , offset , data , dataEndIndex , count ) ; dataEndIndex += count ; } intThread . notify ( ) ; } }
will never block . always write to memory
