List of usage examples for java.io DataInput readInt
int readInt() throws IOException;
From source file:com.willetinc.hadoop.mapreduce.dynamodb.AttributeValueIOUtils.java
public static Collection<AttributeValue> readCollection(Types type, DataInput in) throws IOException { int size = in.readInt(); List<AttributeValue> list = new ArrayList<AttributeValue>(size); for (int i = 0; i < size; i++) { list.add(read(type, in));/*from w w w. j a v a2 s. c o m*/ } return list; }
From source file:org.lilyproject.repository.impl.id.AbsoluteRecordIdImpl.java
public static AbsoluteRecordId fromBytes(byte[] bytes, IdGenerator idGenerator) { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); DataInput dataInput = new DataInputStream(byteArrayInputStream); byte[] tableBytes; byte[] recordIdBytes; try {//w w w . java2 s . co m tableBytes = new byte[dataInput.readInt()]; dataInput.readFully(tableBytes, 0, tableBytes.length); recordIdBytes = new byte[dataInput.readInt()]; dataInput.readFully(recordIdBytes, 0, recordIdBytes.length); } catch (IOException ioe) { throw new RuntimeException("Error while deserializing AbsoluteRecordId", ioe); } return new AbsoluteRecordIdImpl(new String(tableBytes), idGenerator.fromBytes(recordIdBytes)); }
From source file:org.apache.hadoop.hbase.util.BloomFilterFactory.java
/** * Instantiates the correct Bloom filter class based on the version provided * in the meta block data./* www. j a va2s . c om*/ * * @param meta the byte array holding the Bloom filter's metadata, including * version information * @param reader the {@link HFile} reader to use to lazily load Bloom filter * blocks * @return an instance of the correct type of Bloom filter * @throws IllegalArgumentException */ public static BloomFilter createFromMeta(DataInput meta, HFile.Reader reader) throws IllegalArgumentException, IOException { int version = meta.readInt(); switch (version) { case ByteBloomFilter.VERSION: // This is only possible in a version 1 HFile. We are ignoring the // passed comparator because raw byte comparators are always used // in version 1 Bloom filters. return new ByteBloomFilter(meta); case CompoundBloomFilterBase.VERSION: return new CompoundBloomFilter(meta, reader); default: throw new IllegalArgumentException("Bad bloom filter format version " + version); } }
From source file:org.apache.pig.data.DataReaderWriter.java
public static String bytesToBigCharArray(DataInput in) throws IOException { int size = in.readInt(); byte[] ba = new byte[size]; in.readFully(ba);/* w ww . j a va2 s . c om*/ return new String(ba, DataReaderWriter.UTF8); }
From source file:org.apache.pig.data.DataReaderWriter.java
public static Map<String, Object> bytesToMap(DataInput in) throws IOException { int size = in.readInt(); Map<String, Object> m = new HashMap<String, Object>(size); for (int i = 0; i < size; i++) { String key = (String) readDatum(in); m.put(key, readDatum(in));/*from w w w . j a v a 2 s.c o m*/ } return m; }
From source file:org.apache.pig.data.DataReaderWriter.java
public static InternalMap bytesToInternalMap(DataInput in) throws IOException { int size = in.readInt(); InternalMap m = new InternalMap(size); for (int i = 0; i < size; i++) { Object key = readDatum(in); m.put(key, readDatum(in));/*from w ww . ja v a2 s. c om*/ } return m; }
From source file:com.bah.culvert.util.Bytes.java
/** * Read a a byte [] written with {@link #writeByteArray(DataOutput, byte[])} * @param input to read from/*from w w w . j a v a2s. c om*/ * @return the first element in the input stream as a byte[] * @throws IOException on failure to read */ public static byte[] readByteArray(DataInput input) throws IOException { byte[] bytes = new byte[input.readInt()]; input.readFully(bytes); return bytes; }
From source file:com.icloud.framework.core.util.FBUtilities.java
public static ByteBuffer readByteArray(DataInput in) throws IOException { int length = in.readInt(); if (length < 0) { throw new IOException("Corrupt (negative) value length encountered"); }//from ww w.j a v a 2 s. co m ByteBuffer bb = ByteBuffer.allocate(length); if (length > 0) { in.readFully(bb.array(), bb.position(), bb.remaining()); } return bb; }
From source file:com.wsc.myexample.decisionForest.MyDataset.java
public static String[] readStringArray(DataInput in) throws IOException { int len = in.readInt(); if (len == -1) return null; String[] s = new String[len]; for (int i = 0; i < len; i++) { s[i] = readString(in);/*from w ww . j ava2s . c o m*/ } return s; }
From source file:com.wsc.myexample.decisionForest.MyDataset.java
public static String readString(DataInput in) throws IOException { int length = in.readInt(); if (length == -1) return null; byte[] buffer = new byte[length]; in.readFully(buffer); // could/should use readFully(buffer,0,length)? return new String(buffer, "UTF-8"); }