/*
 * Copyright (C) 2013  Ohm Data
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  This file incorporates work covered by the following copyright and
 *  permission notice:
 */
package ohmdb.client;

import com.google.protobuf.ByteString;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.ArrayList;

public class Populator {
  static ByteString tableName = ByteString.copyFrom(Bytes.toBytes("tableName"));

  public Populator() throws IOException, InterruptedException {
  }

  public static void main(String[] args)
      throws IOException, InterruptedException {
    OhmTable table = new OhmTable(tableName);
    long start = System.currentTimeMillis();

    int numberOfBatches = 30;
    int batchSize = 1024 * 81;
    if (args.length == 2) {
      numberOfBatches = Integer.parseInt(args[0]);
      batchSize = Integer.parseInt(args[1]);

    }
    compareToHBasePut(table,
        Bytes.toBytes("cf"),
        Bytes.toBytes("cq"),
        Bytes.toBytes("value"),
        numberOfBatches,
        batchSize);
    long end = System.currentTimeMillis();
    System.out.println("time:" + (end - start));
  }

  public static void compareToHBasePut(final TableInterface table,
                                       final byte[] cf,
                                       final byte[] cq,
                                       final byte[] value,
                                       final int numberOfBatches,
                                       final int batchSize)
      throws IOException {
    ArrayList<Put> puts = new ArrayList<>();

    for (int j = 1; j != numberOfBatches + 1; j++) {
      puts.clear();
      for (int i = 1; i != batchSize + 1; i++) {
        puts.add(new Put(Bytes.vintToBytes(i * j)).add(cf, cq, value));
      }

      int i = 0;
      for (Put put : puts) {
        i++;
        if (i % 1024 == 0) {
          System.out.print("#");
          System.out.flush();
        }
        if (i % (1024 * 80) == 0) {
          System.out.println("");
        }
        table.put(put);
      }

      puts.clear();
    }
  }
}

@@ -1285,16 +1285,21 @@
 n %7B%0A    
+try (
 OhmTable
@@ -1330,18 +1330,23 @@
 bleName)
-;%0A
+) %7B%0A%0A  
     long
@@ -1383,24 +1383,26 @@
 lis();%0A%0A    
+  
 int numberOf
@@ -1415,24 +1415,26 @@
 s = 30;%0A    
+ 
+ 
 int batchSiz
@@ -1448,16 +1448,18 @@
 4 * 81;%0A
+  
     if (
@@ -1480,24 +1480,26 @@
  2) %7B%0A      
+  
 numberOfBatc
@@ -1533,24 +1533,26 @@
 %5B0%5D);%0A      
+  
 batchSize = 
@@ -1579,26 +1579,30 @@
 s%5B1%5D);%0A%0A    
+ 
+ 
 %7D%0A
+  
     compareT
@@ -1618,32 +1618,34 @@
 (table,%0A        
+  
 Bytes.toBytes(%22c
@@ -1649,32 +1649,34 @@
 (%22cf%22),%0A        
+ 
+ 
 Bytes.toBytes(%22c
@@ -1676,24 +1676,26 @@
 ytes(%22cq%22),%0A
+  
         Byte
@@ -1714,32 +1714,34 @@
 alue%22),%0A        
+  
 numberOfBatches,
@@ -1741,32 +1741,34 @@
 atches,%0A        
+ 
+ 
 batchSize);%0A    
@@ -1763,16 +1763,18 @@
 hSize);%0A
+  
     long
@@ -1808,24 +1808,26 @@
 llis();%0A    
+  
 System.out.p
@@ -1859,16 +1859,22 @@
 tart));%0A
+    %7D%0A
   %7D%0A%0A  p

Reformat and moved to using autoclosable