// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java
// public class BigQueryHelper {
//   private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class);
//   private static String keySource;
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @param key The google credentials JSON key that can be used to provide
//    *                    credentials to BigQuery, or null if no authentication should be performed.
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName, String key) {
//     if (key == null) {
//       return connect(projectName);
//     }
//     logger.debug("Attempting to open file {} for service account json key", key);
//     InputStream credentialsStream;
//     try {
//       if (keySource != null && keySource.equals("JSON")) {
//         credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8));
//       } else {
//         credentialsStream = new FileInputStream(key);
//       }
//       return new
//           BigQueryOptions.DefaultBigQueryFactory().create(
//               BigQueryOptions.newBuilder()
//                   .setProjectId(projectName)
//                   .setCredentials(GoogleCredentials.fromStream(credentialsStream))
//                   .build()
//       );
//     } catch (IOException err) {
//       throw new BigQueryConnectException("Failed to access json key file", err);
//     }
//   }
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param keySource The type of key config we can expect. This is either a String
//    *                        representation of the Google credentials file, or the path to the Google credentials file.
//    * @return The resulting BigQuery object.
//    */
//   public BigQueryHelper setKeySource(String keySource) {
//     this.keySource = keySource;
//     return this;
//   }
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with no authentication
//    * credentials, which can then be used for creating, updating, and inserting into tables from
//    * specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName) {
//     logger.debug("Attempting to access BigQuery without authentication");
//     return new BigQueryOptions.DefaultBigQueryFactory().create(
//             BigQueryOptions.newBuilder()
//                 .setProjectId(projectName)
//                 .build()
//     );
//   }
// }


import com.google.api.gax.paging.Page;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.Table;
import com.wepay.kafka.connect.bigquery.BigQueryHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.wepay.kafka.connect.bigquery.it.utils;

/*
 * Copyright 2016 WePay, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */





public class TableClearer {
  private static final Logger logger = LoggerFactory.getLogger(TableClearer.class);
  private static String keySource;


  /**
   * Clears tables in the given project and dataset, using a provided JSON service account key.
   */
  public static void main(String[] args) {
    if (args.length < 5) {
      usage();
    }
    if (args.length == 5) {
      keySource = args[3];
    }
// Path: kcbq-connector/src/main/java/com/wepay/kafka/connect/bigquery/BigQueryHelper.java
// public class BigQueryHelper {
//   private static final Logger logger = LoggerFactory.getLogger(BigQueryHelper.class);
//   private static String keySource;
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @param key The google credentials JSON key that can be used to provide
//    *                    credentials to BigQuery, or null if no authentication should be performed.
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName, String key) {
//     if (key == null) {
//       return connect(projectName);
//     }
//     logger.debug("Attempting to open file {} for service account json key", key);
//     InputStream credentialsStream;
//     try {
//       if (keySource != null && keySource.equals("JSON")) {
//         credentialsStream = new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8));
//       } else {
//         credentialsStream = new FileInputStream(key);
//       }
//       return new
//           BigQueryOptions.DefaultBigQueryFactory().create(
//               BigQueryOptions.newBuilder()
//                   .setProjectId(projectName)
//                   .setCredentials(GoogleCredentials.fromStream(credentialsStream))
//                   .build()
//       );
//     } catch (IOException err) {
//       throw new BigQueryConnectException("Failed to access json key file", err);
//     }
//   }
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with credentials provided
//    * in the specified file, which can then be used for creating, updating, and inserting into tables
//    * from specific datasets.
//    *
//    * @param keySource The type of key config we can expect. This is either a String
//    *                        representation of the Google credentials file, or the path to the Google credentials file.
//    * @return The resulting BigQuery object.
//    */
//   public BigQueryHelper setKeySource(String keySource) {
//     this.keySource = keySource;
//     return this;
//   }
// 
//   /**
//    * Returns a default {@link BigQuery} instance for the specified project with no authentication
//    * credentials, which can then be used for creating, updating, and inserting into tables from
//    * specific datasets.
//    *
//    * @param projectName The name of the BigQuery project to work with
//    * @return The resulting BigQuery object.
//    */
//   public BigQuery connect(String projectName) {
//     logger.debug("Attempting to access BigQuery without authentication");
//     return new BigQueryOptions.DefaultBigQueryFactory().create(
//             BigQueryOptions.newBuilder()
//                 .setProjectId(projectName)
//                 .build()
//     );
//   }
// }


// Path: kcbq-connector/src/integration-test/java/com/wepay/kafka/connect/bigquery/it/utils/TableClearer.java
import com.google.api.gax.paging.Page;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.Table;
import com.wepay.kafka.connect.bigquery.BigQueryHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package com.wepay.kafka.connect.bigquery.it.utils;

/*
 * Copyright 2016 WePay, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */





public class TableClearer {
  private static final Logger logger = LoggerFactory.getLogger(TableClearer.class);
  private static String keySource;


  /**
   * Clears tables in the given project and dataset, using a provided JSON service account key.
   */
  public static void main(String[] args) {
    if (args.length < 5) {
      usage();
    }
    if (args.length == 5) {
      keySource = args[3];
    }
    BigQuery bigQuery = new BigQueryHelper().setKeySource(keySource).connect(args[1], args[0]);