code: public static <T, U extends T> int safeWrite(ArrayWritable<U> aw, T[] array) {
          int num = aw.size();
          if (num <= 0) {
              return 0;
          }
          if (num > array.length) {
              num = array.length;
          }
          aw.writeToArray(0, array, 0, num);
          return num;
      }
docs: Writes the complete container data to an array. This method ensures that the array's capacity is not exceeded.
  
  @param aw
  the container.
  @param array
  the array
  
  @return the number of elements copied