List of usage examples for java.io DataInput readFully
void readFully(byte b[]) throws IOException;
From source file:edu.umn.cs.spatialHadoop.core.OGCShape.java
@Override public void readFields(DataInput in) throws IOException { int size = in.readInt(); byte[] bytes = new byte[size]; in.readFully(bytes); geom = OGCGeometry.fromBinary(ByteBuffer.wrap(bytes)); size = in.readInt();/*w ww.java 2s . com*/ if (size == -1) { extra = null; } else { bytes = new byte[size]; in.readFully(bytes); extra = new String(bytes); } }
From source file:com.nearinfinity.blur.mapreduce.BlurTask.java
private String readString(DataInput input) throws IOException { int length = input.readInt(); byte[] buf = new byte[length]; input.readFully(buf); return new String(buf); }
From source file:com.ning.metrics.action.hdfs.data.RowSmile.java
/** * Replace the current row content with a specified DataInput * * @param in DataInput to read/*from w ww . j a va 2 s. co m*/ * @throws java.io.IOException generic serialization error */ @Override public void readFields(DataInput in) throws IOException { schema.readFields(in); int numberOfItems = WritableUtils.readVInt(in); int smilePayloadSize = WritableUtils.readVInt(in); int itemsRead = 0; byte[] smilePayload = new byte[smilePayloadSize]; in.readFully(smilePayload); JsonParser jp = objectMapper.getJsonFactory().createJsonParser(smilePayload); while (jp.nextToken() != null && itemsRead < numberOfItems) { objectMapper.readValue(jp, JsonNodeComparable.class); itemsRead++; } jp.close(); }
From source file:cosmos.records.impl.MultimapRecord.java
@Override public void readFields(DataInput in) throws IOException { this.docId = Text.readString(in); final int cvLength = WritableUtils.readVInt(in); final byte[] cvBytes = new byte[cvLength]; in.readFully(cvBytes); this.docVisibility = new ColumnVisibility(cvBytes); final int entryCount = WritableUtils.readVInt(in); this.document = HashMultimap.create(); for (int i = 0; i < entryCount; i++) { this.document.put(Column.recreate(in), RecordValue.recreate(in)); }//from w w w . java 2 s . co m }
From source file:com.chinamobile.bcbsp.client.BSPJobClient.java
/** * Read a splits file into a list of raw splits. * @param in/*from ww w. j ava 2 s.co m*/ * the stream to read from * @return the complete list of splits * @throws IOException * NEU change in version-0.2.3 add new function */ public static RawSplit[] readSplitFile(DataInput in) throws IOException { byte[] header = new byte[SPLIT_FILE_HEADER.length]; in.readFully(header); if (!Arrays.equals(SPLIT_FILE_HEADER, header)) { throw new IOException("Invalid header on split file"); } int vers = WritableUtils.readVInt(in); if (vers != CURRENT_SPLIT_FILE_VERSION) { throw new IOException("Unsupported split version " + vers); } int len = WritableUtils.readVInt(in); RawSplit[] result = new RawSplit[len]; for (int i = 0; i < len; ++i) { result[i] = new RawSplit(); result[i].readFields(in); } return result; }
From source file:com.sequoiadb.hadoop.io.BSONWritable.java
public void readFields(DataInput in) throws IOException { BSONDecoder dec = new BasicBSONDecoder(); BSONCallback cb = new BasicBSONCallback(); byte[] l = new byte[4]; try {//from w ww. j a v a2 s . c o m in.readFully(l); int dataLen = Bits.readInt(l); log.debug("*** Expected DataLen: " + dataLen); byte[] data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); bson = (BSONObject) cb.get(); log.trace("Decoded a BSON Object: " + bson); } catch (Exception e) { log.info("No Length Header available." + e); bson = new BasicBSONObject(); } }
From source file:com.liveramp.cascading_ext.bloom.BloomFilter.java
@Override public void readFields(DataInput in) throws IOException { numHashes = in.readInt();// w ww . ja va 2 s . c o m vectorSize = in.readLong(); numElems = in.readLong(); byte[] bytes = new byte[FixedSizeBitSet.getNumBytesToStore(vectorSize)]; in.readFully(bytes); bits = new FixedSizeBitSet(vectorSize, bytes); byte[] serializedHashFunction = new byte[in.readInt()]; in.readFully(serializedHashFunction); hashFunction = (HashFunction) SerializationUtils.deserialize(serializedHashFunction); }
From source file:com.mongodb.hadoop.io.MongoUpdateWritable.java
/** * {@inheritDoc}//from www .ja v a 2 s. c o m * * @see Writable#readFields(DataInput) */ public void readFields(DataInput in) throws IOException { BSONDecoder dec = new BasicBSONDecoder(); BSONCallback cb = new BasicBSONCallback(); // Read the BSON length from the start of the record byte[] l = new byte[4]; try { in.readFully(l); int dataLen = Bits.readInt(l); byte[] data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); this.query = (BasicBSONObject) cb.get(); in.readFully(l); dataLen = Bits.readInt(l); data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); this.modifiers = (BasicBSONObject) cb.get(); this.upsert = in.readBoolean(); this.multiUpdate = in.readBoolean(); } catch (Exception e) { /* If we can't read another length it's not an error, just return quietly. */ // TODO - Figure out how to gracefully mark this as an empty log.info("No Length Header available." + e); this.query = new BasicDBObject(); this.modifiers = new BasicDBObject(); } }
From source file:org.glukit.dexcom.sync.responses.ManufacturingDataDatabasePagesResponse.java
public List<ManufacturingParameters> getManufacturingParameters() { List<ManufacturingParameters> manufacturingParameters = newArrayList(); try {//w w w . ja v a2 s . c o m for (DatabasePage page : getPages()) { ByteArrayInputStream inputStream = new ByteArrayInputStream(page.getPageData()); DataInput input = this.dataInputFactory.create(inputStream); // TODO: something better than ignoring the data? long systemSeconds = UnsignedInts.toLong(input.readInt()); long displaySeconds = UnsignedInts.toLong(input.readInt()); byte[] xmlBytes = new byte[inputStream.available() - 2]; input.readFully(xmlBytes); validateCrc(input.readUnsignedShort(), page.getPageData()); XmlMapper xmlMapper = new XmlMapper(); ManufacturingParameters parameterPage = xmlMapper.readValue(new String(xmlBytes, "UTF-8"), ManufacturingParameters.class); manufacturingParameters.add(parameterPage); } return manufacturingParameters; } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.zjy.mongo.io.MongoUpdateWritable.java
/** * {@inheritDoc}/*w w w . j a va 2 s. com*/ * * @see Writable#readFields(DataInput) */ public void readFields(final DataInput in) throws IOException { BSONDecoder dec = new BasicBSONDecoder(); BSONCallback cb = new BasicBSONCallback(); // Read the BSON length from the start of the record byte[] l = new byte[4]; try { in.readFully(l); int dataLen = Bits.readInt(l); byte[] data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); query = (BasicBSONObject) cb.get(); in.readFully(l); dataLen = Bits.readInt(l); data = new byte[dataLen + 4]; System.arraycopy(l, 0, data, 0, 4); in.readFully(data, 4, dataLen - 4); dec.decode(data, cb); modifiers = (BasicBSONObject) cb.get(); upsert = in.readBoolean(); multiUpdate = in.readBoolean(); } catch (Exception e) { /* If we can't read another length it's not an error, just return quietly. */ // TODO - Figure out how to gracefully mark this as an empty LOG.info("No Length Header available." + e); query = new BasicDBObject(); modifiers = new BasicDBObject(); } }