private < T > Iterator < Iterator < T > > safePartition ( final Iterator < T > input , int chunkSize ) { // Cloud Datastore library errors if you try to fetch more than 1000 keys at a time if ( chunkSize > 1000 ) { chunkSize = 1000 ; } return Iterators . transform ( Iterators . partition ( input , chunkSize ) , IterateFunction . instance ( ) ) ; }
Detects Integer . MAX_VALUE and prevents OOM exceptions