当前位置: 首页>>代码示例>>Java>>正文


Java Scanner类代码示例

本文整理汇总了Java中org.apache.accumulo.core.client.Scanner的典型用法代码示例。如果您正苦于以下问题:Java Scanner类的具体用法?Java Scanner怎么用?Java Scanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Scanner类属于org.apache.accumulo.core.client包,在下文中一共展示了Scanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runTest

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
/**
 * Run a specific test for a given version and configuration.
 *
 * @param dataScanner
 *          Scanner for the unsigned data.
 * @param signedScanner
 *          Scanner for the signed data.
 * @param verifier
 *          Verifier for the signed data.
 * @param signatureConfig
 *          Configuration for the verifier.
 */
private void runTest(Scanner dataScanner, Scanner signedScanner, EntrySigner verifier, SignatureConfig signatureConfig) {
  Iterator<Entry<Key,Value>> iterator = signedScanner.iterator();
  for (Entry<Key,Value> entry : dataScanner) {
    assertThat("should have more entries", iterator.hasNext(), is(true));
    Entry<Key,Value> signedEntry = iterator.next();

    Entry<Key,Value> verifiedEntry;
    if (signatureConfig.isSignatureInSeparateTable()) {
      assertThat("keys should match", signedEntry.getKey(), equalTo(entry.getKey()));
      assertThat("values should not match", signedEntry.getValue().get(), not(equalTo(entry.getValue().get())));
      verifiedEntry = verifier.verify(entry, signedEntry);
    } else {
      verifiedEntry = verifier.verify(signedEntry);
    }

    assertThat("entries should match", verifiedEntry, Matchers.equalTo(entry));
  }

  assertThat("should have no more entries", iterator.hasNext(), is(false));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:33,代码来源:VersioningIT.java

示例2: check

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
public void check(SignatureConfig config) throws Exception {
  Scanner scanner = AccumuloInstance.getConnector(USER).createScanner(UNSIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations);
  Scanner signedScanner;

  if (!config.isSignatureInSeparateTable()) {
    signedScanner = new SignedScanner(AccumuloInstance.getConnector(USER), SIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations, config,
        AccumuloInstance.getUser(USER).signatureKeys.get(config.getAlgorithm()));
  } else {
    signedScanner = new SignedScanner(AccumuloInstance.getConnector(USER), UNSIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations, config,
        AccumuloInstance.getUser(USER).signatureKeys.get(config.getAlgorithm()));
  }

  Iterator<Entry<Key,Value>> iterator = signedScanner.iterator();
  for (Entry<Key,Value> entry : scanner) {
    assertThat("should have an entry that matches", iterator.hasNext(), is(true));
    assertThat("entries match", iterator.next(), equalTo(entry));
  }

  assertThat("should have no more entries", iterator.hasNext(), is(false));
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:21,代码来源:BatchWriteReadIT.java

示例3: main

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        try (ConfigurableApplicationContext ctx = new SpringApplicationBuilder(SpringBootstrap.class)
                .bannerMode(Mode.OFF).web(false).run(args)) {
            Configuration conf = ctx.getBean(Configuration.class);

            final BaseConfiguration apacheConf = new BaseConfiguration();
            Configuration.Accumulo accumuloConf = conf.getAccumulo();
            apacheConf.setProperty("instance.name", accumuloConf.getInstanceName());
            apacheConf.setProperty("instance.zookeeper.host", accumuloConf.getZookeepers());
            final ClientConfiguration aconf = new ClientConfiguration(Collections.singletonList(apacheConf));
            final Instance instance = new ZooKeeperInstance(aconf);
            Connector con = instance.getConnector(accumuloConf.getUsername(),
                    new PasswordToken(accumuloConf.getPassword()));
            Scanner s = con.createScanner(conf.getMetaTable(),
                    con.securityOperations().getUserAuthorizations(con.whoami()));
            try {
                s.setRange(new Range(Meta.METRIC_PREFIX, true, Meta.TAG_PREFIX, false));
                for (Entry<Key, Value> e : s) {
                    System.out.println(e.getKey().getRow().toString().substring(Meta.METRIC_PREFIX.length()));
                }
            } finally {
                s.close();
            }
        }
    }
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:27,代码来源:GetMetricTableSplitPoints.java

示例4: createScanner

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
private Scanner createScanner(Query<K,T> query) throws TableNotFoundException {
  // TODO make isolated scanner optional?
  Scanner scanner = new IsolatedScanner(conn.createScanner(mapping.tableName, Constants.NO_AUTHS));
  setFetchColumns(scanner, query.getFields());

  scanner.setRange(createRange(query));

  if (query.getStartTime() != -1 || query.getEndTime() != -1) {
    IteratorSetting is = new IteratorSetting(30, TimestampFilter.class);
    if (query.getStartTime() != -1)
      TimestampFilter.setStart(is, query.getStartTime(), true);
    if (query.getEndTime() != -1)
      TimestampFilter.setEnd(is, query.getEndTime(), true);

    scanner.addScanIterator(is);
  }

  return scanner;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:20,代码来源:AccumuloStore.java

示例5: findMaxDepth

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
private int findMaxDepth(Scanner scanner, int min, int mid, int max) {
  // check to see if the mid point exist
  if (max < min)
    return -1;

  scanner.setRange(new Range(String.format("%03d", mid), true, String.format("%03d", mid + 1), false));

  if (scanner.iterator().hasNext()) {
    // this depth exist, check to see if a larger depth exist
    int ret = findMaxDepth(scanner, mid + 1, max);
    if (ret == -1)
      return mid; // this must the max
    else
      return ret;
  } else {
    // this depth does not exist, look lower
    return findMaxDepth(scanner, min, mid - 1);
  }

}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:21,代码来源:FileCount.java

示例6: getDirList

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
/**
 * Uses the directory table to list the contents of a directory.
 *
 * @param path
 *          the full path of a directory
 */
public Map<String,Map<String,String>> getDirList(String path) throws TableNotFoundException {
  if (!path.endsWith("/"))
    path = path + "/";
  Map<String,Map<String,String>> fim = new TreeMap<>();
  Scanner scanner = conn.createScanner(tableName, auths);
  scanner.setRange(Range.prefix(getRow(path)));
  for (Entry<Key,Value> e : scanner) {
    String name = e.getKey().getRow().toString();
    name = name.substring(name.lastIndexOf("/") + 1);
    String type = getType(e.getKey().getColumnFamily());
    if (!fim.containsKey(name)) {
      fim.put(name, new TreeMap<String,String>());
      fim.get(name).put("fullname", e.getKey().getRow().toString().substring(3));
    }
    fim.get(name).put(type + e.getKey().getColumnQualifier().toString() + ":" + e.getKey().getColumnVisibility().toString(), new String(e.getValue().get()));
  }
  return fim;
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:25,代码来源:QueryUtil.java

示例7: singleRestrictedWildCardSearch

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
/**
 * Scans over the index table for files or directories with a given name, prefix, or suffix (indicated by a wildcard '*' at the beginning or end of the term.
 *
 * @param exp
 *          the name a file or directory to search for with an optional wildcard '*' at the beginning or end
 */
public Iterable<Entry<Key,Value>> singleRestrictedWildCardSearch(String exp) throws Exception {
  if (exp.indexOf("/") >= 0)
    throw new Exception("this method only works with unqualified names");

  Scanner scanner = conn.createScanner(tableName, auths);
  if (exp.startsWith("*")) {
    System.out.println("executing beginning wildcard search for " + exp);
    exp = exp.substring(1);
    scanner.setRange(Range.prefix(getReverseIndex(exp)));
  } else if (exp.endsWith("*")) {
    System.out.println("executing ending wildcard search for " + exp);
    exp = exp.substring(0, exp.length() - 1);
    scanner.setRange(Range.prefix(getForwardIndex(exp)));
  } else if (exp.indexOf("*") >= 0) {
    throw new Exception("this method only works for beginning or ending wild cards");
  } else {
    return exactTermSearch(exp);
  }
  return scanner;
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:27,代码来源:QueryUtil.java

示例8: readEntries

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
private void readEntries(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {

    Scanner scanner = opts.getConnector().createScanner(opts.getTableName(), opts.auths);

    // Trace the read operation.
    TraceScope readScope = Trace.startSpan("Client Read", Sampler.ALWAYS);
    System.out.println("TraceID: " + Long.toHexString(readScope.getSpan().getTraceId()));

    int numberOfEntriesRead = 0;
    for (Entry<Key,Value> entry : scanner) {
      System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString());
      ++numberOfEntriesRead;
    }
    // You can add additional metadata (key, values) to Spans which will be able to be viewed in the Monitor
    readScope.getSpan().addKVAnnotation("Number of Entries Read".getBytes(UTF_8), String.valueOf(numberOfEntriesRead).getBytes(UTF_8));

    readScope.close();
  }
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:19,代码来源:TracingExample.java

示例9: main

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  Opts opts = new Opts();
  ScannerOpts scanOpts = new ScannerOpts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  opts.parseArgs(Reverse.class.getName(), args, scanOpts, bwOpts);

  Connector conn = opts.getConnector();

  Scanner scanner = conn.createScanner(opts.shardTable, opts.auths);
  scanner.setBatchSize(scanOpts.scanBatchSize);
  BatchWriter bw = conn.createBatchWriter(opts.doc2TermTable, bwOpts.getBatchWriterConfig());

  for (Entry<Key,Value> entry : scanner) {
    Key key = entry.getKey();
    Mutation m = new Mutation(key.getColumnQualifier());
    m.put(key.getColumnFamily(), new Text(), new Value(new byte[0]));
    bw.addMutation(m);
  }

  bw.close();

}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:23,代码来源:Reverse.java

示例10: list

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
public List<String> list(String what, String when) throws Exception {
  String row = what + ":" + when;

  // its important to use an isolated scanner so that only whole mutations are seen
  try (Scanner scanner = new IsolatedScanner(conn.createScanner(rTable, Authorizations.EMPTY))) {
    scanner.setRange(new Range(row));
    scanner.fetchColumnFamily(new Text("res"));

    List<String> reservations = new ArrayList<>();

    for (Entry<Key,Value> entry : scanner) {
      String val = entry.getValue().toString();
      reservations.add(val);
    }

    return reservations;
  }
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:19,代码来源:ARS.java

示例11: test

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
@Test
public void test() throws Exception {
  Scanner scanner = conn.createScanner(tableName, new Authorizations());
  scanner.fetchColumn(new Text("dir"), new Text("counts"));
  assertFalse(scanner.iterator().hasNext());

  ScannerOpts scanOpts = new ScannerOpts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
  fc.run();

  ArrayList<Pair<String,String>> expected = new ArrayList<>();
  expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));

  int i = 0;
  for (Entry<Key,Value> e : scanner) {
    assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
    assertEquals(e.getValue().toString(), expected.get(i).getSecond());
    i++;
  }
  assertEquals(i, expected.size());
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:26,代码来源:CountIT.java

示例12: printAccumuloTable

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
/**
 * Prints specified Accumulo table (accessible using Accumulo connector parameter)
 *
 * @param conn Accumulo connector of to instance with table to print
 * @param accumuloTable Accumulo table to print
 */
public static void printAccumuloTable(Connector conn, String accumuloTable) {
  Scanner scanner = null;
  try {
    scanner = conn.createScanner(accumuloTable, Authorizations.EMPTY);
  } catch (TableNotFoundException e) {
    throw new IllegalStateException(e);
  }
  Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator();

  System.out.println("== accumulo start ==");
  while (iterator.hasNext()) {
    Map.Entry<Key, Value> entry = iterator.next();
    System.out.println(entry.getKey() + " " + entry.getValue());
  }
  System.out.println("== accumulo end ==");
}
 
开发者ID:apache,项目名称:fluo-recipes,代码行数:23,代码来源:FluoITHelper.java

示例13: getCommittedWindowId

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
@Override
public long getCommittedWindowId(String appId, int operatorId)
{
  byte[] value = null;
  Authorizations auths = new Authorizations();
  Scanner scan = null;
  String columnKey = appId + "_" + operatorId + "_" + lastWindowColumnName;
  lastWindowColumnBytes = columnKey.getBytes();
  try {
    scan = connector.createScanner(tableName, auths);
  } catch (TableNotFoundException e) {
    logger.error("error getting committed window id", e);
    DTThrowable.rethrow(e);
  }
  scan.setRange(new Range(new Text(rowBytes)));
  scan.fetchColumn(new Text(columnFamilyBytes), new Text(lastWindowColumnBytes));
  for (Entry<Key, Value> entry : scan) {
    value = entry.getValue().get();
  }
  if (value != null) {
    long longval = toLong(value);
    return longval;
  }
  return -1;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:26,代码来源:AccumuloWindowStore.java

示例14: getScanner

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
@Override
public Scanner getScanner(Connector conn)
{
  Authorizations auths = new Authorizations();
  Scanner scan = null;
  try {
    scan = conn.createScanner(getStore().getTableName(), auths);
  } catch (TableNotFoundException e) {
    logger.error("table not found ");
    DTThrowable.rethrow(e);
  }
  scan.setRange(new Range());
  // scan.fetchColumnFamily("attributes");

  return scan;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:17,代码来源:AccumuloInputOperatorTest.java

示例15: getAccumuloTuple

import org.apache.accumulo.core.client.Scanner; //导入依赖的package包/类
public static AccumuloTuple getAccumuloTuple(String row, String colFam,
    String colName)
{
  Authorizations auths = new Authorizations();

  Scanner scan = null;
  try {
    scan = con.createScanner("tab1", auths);
  } catch (TableNotFoundException e) {
    logger.error("error in test helper");
    DTThrowable.rethrow(e);
  }

  scan.setRange(new Range(new Text(row)));
  scan.fetchColumn(new Text(colFam), new Text(colName));
  // assuming only one row
  for (Entry<Key, Value> entry : scan) {
    AccumuloTuple tuple = new AccumuloTuple();
    tuple.setRow(entry.getKey().getRow().toString());
    tuple.setColFamily(entry.getKey().getColumnFamily().toString());
    tuple.setColName(entry.getKey().getColumnQualifier().toString());
    tuple.setColValue(entry.getValue().toString());
    return tuple;
  }
  return null;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:27,代码来源:AccumuloTestHelper.java


注:本文中的org.apache.accumulo.core.client.Scanner类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。