List of usage examples for org.apache.hadoop.io WritableUtils readVInt
public static int readVInt(DataInput stream) throws IOException
From source file:org.apache.accumulo.core.summary.SummaryReader.java
License:Apache License
private static List<SummarySerializer> load(BlockReader bcReader, Predicate<SummarizerConfiguration> summarySelector) throws IOException { try (DataInputStream in = bcReader.getMetaBlock(SummaryWriter.METASTORE_INDEX)) { List<SummarySerializer> stores = new ArrayList<>(); readHeader(in);/*from www .j ava 2 s .co m*/ int numSummaries = WritableUtils.readVInt(in); for (int i = 0; i < numSummaries; i++) { SummarizerConfiguration conf = readConfig(in); boolean inline = in.readBoolean(); if (inline) { if (summarySelector.test(conf)) { stores.add(SummarySerializer.load(conf, in)); } else { SummarySerializer.skip(in); } } else { int block = WritableUtils.readVInt(in); int offset = WritableUtils.readVInt(in); if (summarySelector.test(conf)) { try (DataInputStream summaryIn = bcReader .getMetaBlock(SummaryWriter.METASTORE_PREFIX + "." + block)) { long skipped = in.skip(offset); while (skipped < offset) { skipped += in.skip(offset - skipped); } stores.add(SummarySerializer.load(conf, summaryIn)); } catch (MetaBlockDoesNotExist e) { // this is unexpected throw new IOException(e); } } } } return stores; } catch (MetaBlockDoesNotExist e) { return Collections.emptyList(); } }
From source file:org.apache.accumulo.core.summary.SummaryReader.java
License:Apache License
private static SummarizerConfiguration readConfig(DataInputStream in) throws IOException { // read summarizer configuration String summarizerClazz = in.readUTF(); String configId = in.readUTF(); org.apache.accumulo.core.client.summary.SummarizerConfiguration.Builder scb = SummarizerConfiguration .builder(summarizerClazz).setPropertyId(configId); int numOpts = WritableUtils.readVInt(in); for (int i = 0; i < numOpts; i++) { String k = in.readUTF();/* w ww.j av a2 s . c o m*/ String v = in.readUTF(); scb.addOption(k, v); } return scb.build(); }
From source file:org.apache.accumulo.core.summary.SummarySerializer.java
License:Apache License
static void skip(DataInputStream in) throws IOException { boolean exceededMaxSize = in.readBoolean(); if (!exceededMaxSize) { long len = WritableUtils.readVInt(in); long skipped = in.skip(len); while (skipped < len) { skipped += in.skip(len - skipped); }/*from ww w . jav a 2s. c om*/ } }
From source file:org.apache.accumulo.core.summary.SummarySerializer.java
License:Apache License
static SummarySerializer load(SummarizerConfiguration sconf, DataInputStream in) throws IOException { boolean exceededMaxSize = in.readBoolean(); if (!exceededMaxSize) { WritableUtils.readVInt(in); // load symbol table int numSymbols = WritableUtils.readVInt(in); String[] symbols = new String[numSymbols]; for (int i = 0; i < numSymbols; i++) { symbols[i] = in.readUTF();/* w ww . j a v a 2s. c o m*/ } int numLGroups = WritableUtils.readVInt(in); LgSummaries[] allSummaries = new LgSummaries[numLGroups]; for (int i = 0; i < numLGroups; i++) { allSummaries[i] = readLGroup(in, symbols); } return new SummarySerializer(sconf, allSummaries); } else { return new SummarySerializer(sconf); } }
From source file:org.apache.accumulo.core.summary.SummarySerializer.java
License:Apache License
private static LgSummaries readLGroup(DataInputStream in, String[] symbols) throws IOException { String lgroupName = in.readUTF(); // read first row Text firstRow = new Text(); firstRow.readFields(in);//from w w w .j a v a 2 s.c o m // read summaries int numSummaries = WritableUtils.readVInt(in); SummaryInfo[] summaries = new SummaryInfo[numSummaries]; for (int i = 0; i < numSummaries; i++) { int rowLen = WritableUtils.readVInt(in); byte[] row = new byte[rowLen]; in.readFully(row); int count = WritableUtils.readVInt(in); Map<String, Long> summary = readSummary(in, symbols); summaries[i] = new SummaryInfo(row, summary, count); } return new LgSummaries(firstRow, summaries, lgroupName); }
From source file:org.apache.accumulo.core.summary.SummarySerializer.java
License:Apache License
private static Map<String, Long> readSummary(DataInputStream in, String[] symbols) throws IOException { com.google.common.collect.ImmutableMap.Builder<String, Long> imb = ImmutableMap.builder(); int numEntries = WritableUtils.readVInt(in); for (int i = 0; i < numEntries; i++) { String symbol = symbols[WritableUtils.readVInt(in)]; imb.put(symbol, WritableUtils.readVLong(in)); }// w w w .ja v a 2 s . c om return imb.build(); }
From source file:org.apache.accumulo.server.security.delegation.AuthenticationKey.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { int length = WritableUtils.readVInt(in); if (0 == length) { return;/*from w w w . j a v a 2s .c o m*/ } ThriftMessageUtil util = new ThriftMessageUtil(); byte[] bytes = new byte[length]; in.readFully(bytes); authKey = util.deserialize(bytes, new TAuthenticationKey()); secret = AuthenticationTokenSecretManager.createSecretKey(authKey.getSecret()); }
From source file:org.apache.blur.mapreduce.lib.v2.DocumentWritable.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { _document.clear();// w w w .j a v a 2 s .co m int numberOfFields = WritableUtils.readVInt(in); for (int i = 0; i < numberOfFields; i++) { IndexableField field = readField(in); _document.add(field); } }
From source file:org.apache.blur.mapreduce.lib.v2.DocumentWritable.java
License:Apache License
private String readString(DataInput in) throws IOException { int length = WritableUtils.readVInt(in); byte[] buf = new byte[length]; in.readFully(buf);/*from w w w.j a va2 s . c o m*/ return new String(buf, UTF_8); }
From source file:org.apache.crunch.types.writable.GenericArrayWritable.java
License:Apache License
public void readFields(DataInput in) throws IOException { values = new Writable[WritableUtils.readVInt(in)]; // construct values if (values.length > 0) { int nulls = WritableUtils.readVInt(in); if (nulls == values.length) { return; }//from w w w . j a va2 s . c om String valueType = Text.readString(in); setValueType(valueType); for (int i = 0; i < values.length - nulls; i++) { Writable value = WritableFactories.newInstance(valueClass); value.readFields(in); // read a value values[i] = value; // store it in values } } }