public synchronized Object [ ] nextNElements ( int n ) throws RemoteException , EnumeratorException { if ( ! hasMoreElementsR ( ) ) { throw new NoMoreElementsException ( ) ; } EJBObject [ ] remainder = null ; final int numCached = elements . length - index ; if ( ! exhausted && numCached < n ) { // We must fetch more elements from the remote result set // to satisfy the request try { remainder = fetchElements ( n - numCached ) ; } catch ( NoMoreElementsException ex ) { // FFDCFilter.processException(ex, CLASS_NAME + ".nextNElements", // "220", this); } } final int numRemaining = remainder != null ? remainder . length : 0 ; final int totalAvail = numCached + numRemaining ; final int numToReturn = Math . min ( n , totalAvail ) ; final EJBObject [ ] result = new EJBObject [ numToReturn ] ; final int numFromCache = Math . min ( numToReturn , numCached ) ; System . arraycopy ( elements , index , result , 0 , numFromCache ) ; index += numFromCache ; if ( remainder != null ) { System . arraycopy ( remainder , 0 , result , numFromCache , numRemaining ) ; } return result ; }
Obtain the next n elements from the enumeration ; the array may contain fewer than n elements if the enumeration is exhausted .