public synchronized void add ( byte [ ] data , int offset , int count ) throws IOException { if ( data == null ) { throw new NullPointerException ( "data == null" ) ; } if ( ( offset | count ) < 0 || count > data . length - offset ) { throw new IndexOutOfBoundsException ( ) ; } expandIfNecessary ( count ) ; // Insert a new element after the current last element. boolean wasEmpty = isEmpty ( ) ; int position = wasEmpty ? HEADER_LENGTH : wrapPosition ( last . position + Element . HEADER_LENGTH + last . length ) ; Element newLast = new Element ( position , count ) ; // Write length. writeInt ( buffer , 0 , count ) ; ringWrite ( newLast . position , buffer , 0 , Element . HEADER_LENGTH ) ; // Write data. ringWrite ( newLast . position + Element . HEADER_LENGTH , data , offset , count ) ; // Commit the addition. If wasEmpty, first == last. int firstPosition = wasEmpty ? newLast . position : first . position ; writeHeader ( fileLength , elementCount + 1 , firstPosition , newLast . position ) ; last = newLast ; elementCount ++ ; if ( wasEmpty ) first = last ; // first element }
Adds an element to the end of the queue .