public static void validateCopyArguments(
      String srcBucketName,
      List<String> srcObjectNames,
      String dstBucketName,
      List<String> dstObjectNames,
      GoogleCloudStorage gcsImpl)
      throws IOException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(srcBucketName),
        "srcBucketName must not be null or empty");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(dstBucketName),
        "dstBucketName must not be null or empty");
    Preconditions.checkArgument(srcObjectNames != null,
        "srcObjectNames must not be null");
    Preconditions.checkArgument(dstObjectNames != null,
        "dstObjectNames must not be null");
    Preconditions.checkArgument(srcObjectNames.size() == dstObjectNames.size(),
        "Must supply same number of elements in srcObjectNames and dstObjectNames");

    // Avoid copy across locations or storage classes.
    if (!srcBucketName.equals(dstBucketName)) {
      GoogleCloudStorageItemInfo srcBucketInfo =
          gcsImpl.getItemInfo(new StorageResourceId(srcBucketName));
      if (!srcBucketInfo.exists()) {
        throw new FileNotFoundException("Bucket not found: " + srcBucketName);
      }

      GoogleCloudStorageItemInfo dstBucketInfo =
          gcsImpl.getItemInfo(new StorageResourceId(dstBucketName));
      if (!dstBucketInfo.exists()) {
        throw new FileNotFoundException("Bucket not found: " + dstBucketName);
      }

      if (!gcsImpl.getOptions().isCopyWithRewriteEnabled()) {
        if (!srcBucketInfo.getLocation().equals(dstBucketInfo.getLocation())) {
          throw new UnsupportedOperationException(
              "This operation is not supported across two different storage locations.");
        }

        if (!srcBucketInfo.getStorageClass().equals(dstBucketInfo.getStorageClass())) {
          throw new UnsupportedOperationException(
              "This operation is not supported across two different storage classes.");
        }
      }
    }
    for (int i = 0; i < srcObjectNames.size(); i++) {
      Preconditions.checkArgument(!Strings.isNullOrEmpty(srcObjectNames.get(i)),
          "srcObjectName must not be null or empty");
      Preconditions.checkArgument(!Strings.isNullOrEmpty(dstObjectNames.get(i)),
          "dstObjectName must not be null or empty");
      if (srcBucketName.equals(dstBucketName)
          && srcObjectNames.get(i).equals(dstObjectNames.get(i))) {
        throw new IllegalArgumentException(String.format(
            "Copy destination must be different from source for %s.",
            StorageResourceId.createReadableString(srcBucketName, srcObjectNames.get(i))));
      }
    }
  }
public static void validateCopyArguments ( String srcBucketName , List < String > srcObjectNames , String dstBucketName , List < String > dstObjectNames , GoogleCloudStorage gcsImpl ) throws IOException { Preconditions . checkArgument ( ! Strings . isNullOrEmpty ( srcBucketName ) , "srcBucketName must not be null or empty" ) ; Preconditions . checkArgument ( ! Strings . isNullOrEmpty ( dstBucketName ) , "dstBucketName must not be null or empty" ) ; Preconditions . checkArgument ( srcObjectNames != null , "srcObjectNames must not be null" ) ; Preconditions . checkArgument ( dstObjectNames != null , "dstObjectNames must not be null" ) ; Preconditions . checkArgument ( srcObjectNames . size ( ) == dstObjectNames . size ( ) , "Must supply same number of elements in srcObjectNames and dstObjectNames" ) ; if ( ! srcBucketName . equals ( dstBucketName ) ) { GoogleCloudStorageItemInfo srcBucketInfo = gcsImpl . getItemInfo ( new StorageResourceId ( srcBucketName ) ) ; if ( ! srcBucketInfo . exists ( ) ) { throw new FileNotFoundException ( "Bucket not found: " + srcBucketName ) ; } GoogleCloudStorageItemInfo dstBucketInfo = gcsImpl . getItemInfo ( new StorageResourceId ( dstBucketName ) ) ; if ( ! dstBucketInfo . exists ( ) ) { throw new FileNotFoundException ( "Bucket not found: " + dstBucketName ) ; } if ( ! gcsImpl . getOptions ( ) . isCopyWithRewriteEnabled ( ) ) { if ( ! srcBucketInfo . getLocation ( ) . equals ( dstBucketInfo . getLocation ( ) ) ) { throw new UnsupportedOperationException ( "This operation is not supported across two different storage locations." ) ; } if ( ! srcBucketInfo . getStorageClass ( ) . equals ( dstBucketInfo . getStorageClass ( ) ) ) { throw new UnsupportedOperationException ( "This operation is not supported across two different storage classes." ) ; } } } for ( int i = 0 ; i < srcObjectNames . size ( ) ; i ++ ) { Preconditions . checkArgument ( ! Strings . isNullOrEmpty ( srcObjectNames . get ( i ) ) , "srcObjectName must not be null or empty" ) ; Preconditions . checkArgument ( ! Strings . isNullOrEmpty ( dstObjectNames . get ( i ) ) , "dstObjectName must not be null or empty" ) ; if ( srcBucketName . equals ( dstBucketName ) && srcObjectNames . get ( i ) . equals ( dstObjectNames . get ( i ) ) ) { throw new IllegalArgumentException ( String . format ( "Copy destination must be different from source for %s." , StorageResourceId . createReadableString ( srcBucketName , srcObjectNames . get ( i ) ) ) ) ; } } }
@VisibleForTesting