Esempio n. 1
0
  /**
   * Get all stocks in the same exchanger
   *
   * @param type
   */
  public static void GetStocksSymbol(String type) {
    Scan scan = new Scan();
    Filter ColumnFilter =
        new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("20150806195250")));
    scan.setFilter(ColumnFilter);
    Hbase.setStrings("Stocks", "list");
    ResultScanner results = Hbase.getAllData(scan);
    BufferedWriter out = null;
    File LogFile = new File(type + "Stocks");
    try {
      out = new BufferedWriter(new FileWriter(LogFile, false));
    } catch (IOException e) {
      e.printStackTrace();
    }

    for (Result result : results) {
      for (Cell cell : result.rawCells()) {
        try {
          JSONObject info = new JSONObject(new String(CellUtil.cloneValue(cell)));
          if (info.getString("exchange").equals(type)) {
            out.write(new String(CellUtil.cloneRow(cell)) + "\r\n");
          }
        } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    try {
      out.flush(); // 把缓存区内容压入文件
      out.close();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 2
0
 static {
   Hbase.setStrings(tablename, "all");
   Hbase.createTable(true);
 }