下面列出了java.io.DataInput#readLong ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void read(final DataInput in) throws IOException {
// read partition number
this.partitionNumber = in.readInt();
// read file path
boolean isNotNull = in.readBoolean();
if (isNotNull) {
this.file = new Path();
this.file.read(in);
}
this.start = in.readLong();
this.length = in.readLong();
isNotNull = in.readBoolean();
if (isNotNull) {
final int numHosts = in.readInt();
this.hosts = new String[numHosts];
for (int i = 0; i < numHosts; i++) {
this.hosts[i] = StringRecord.readString(in);
}
} else {
this.hosts = null;
}
}
public void fromData(DataInput in) throws IOException,
ClassNotFoundException {
this.entryBits = in.readByte();
byte flags = in.readByte();
this.key = DataSerializer.readObject(in);
if (EntryBits.isTombstone(this.entryBits)) {
this.value = Token.TOMBSTONE;
}
else {
if (!isEagerDeserialize()) {
this.value = DataSerializer.readByteArray(in);
}
else {
this.value = DataSerializer.readObject(in);
}
}
this.lastModified = in.readLong();
if ((flags & HAS_VERSION) != 0) {
// note that null IDs must be later replaced with the image provider's ID
this.versionTag = VersionTag.create((flags & PERSISTENT_VERSION) != 0, in);
}
}
public INodeReference.WithCount loadINodeReferenceWithCount(
boolean isSnapshotINode, DataInput in, FSImageFormat.Loader loader
) throws IOException {
final boolean firstReferred = in.readBoolean();
final INodeReference.WithCount withCount;
if (firstReferred) {
final INode referred = loader.loadINodeWithLocalName(isSnapshotINode,
in, true);
withCount = new INodeReference.WithCount(null, referred);
referenceMap.put(withCount.getId(), withCount);
} else {
final long id = in.readLong();
withCount = referenceMap.get(id);
}
return withCount;
}
public void readFields(DataInput in) throws IOException {
totLength = in.readLong();
int arrLength = in.readInt();
lengths = new long[arrLength];
for(int i=0; i<arrLength;i++) {
lengths[i] = in.readLong();
}
int filesLength = in.readInt();
paths = new Path[filesLength];
for(int i=0; i<filesLength;i++) {
paths[i] = new Path(Text.readString(in));
}
arrLength = in.readInt();
startoffset = new long[arrLength];
for(int i=0; i<arrLength;i++) {
startoffset[i] = in.readLong();
}
}
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
super.fromData(in);
if (hasVersionTag()) {
this.versionTag = (VersionTag)DataSerializer.readObject(in);
} else {
this.timestamp = in.readLong();
}
}
/** read a set of Long objects */
public static List<Long> readListOfLongs(DataInput in) throws IOException {
int size = in.readInt();
if (size < 0) {
return null;
} else {
List result = new LinkedList();
boolean longIDs = in.readBoolean();
for (int i=0; i<size; i++) {
long l = longIDs? in.readLong() : in.readInt();
result.add(Long.valueOf(l));
}
return result;
}
}
private static FileDiff loadFileDiff(FileDiff posterior, DataInput in,
FSImageFormat.Loader loader) throws IOException {
// 1. Read the id of the Snapshot root to identify the Snapshot
final Snapshot snapshot = loader.getSnapshot(in);
// 2. Load file size
final long fileSize = in.readLong();
// 3. Load snapshotINode
final INodeFileAttributes snapshotINode = in.readBoolean()?
loader.loadINodeFileAttributes(in): null;
return new FileDiff(snapshot.getId(), snapshotINode, posterior, fileSize);
}
/**
* Reads encoding generated by writeMillis.
*/
static long readMillis(DataInput in) throws IOException {
int v = in.readUnsignedByte();
switch (v >> 6) {
case 0: default:
// Form 00 (6 bits effective precision)
v = (v << (32 - 6)) >> (32 - 6);
return v * (30 * 60000L);
case 1:
// Form 01 (30 bits effective precision)
v = (v << (32 - 6)) >> (32 - 30);
v |= (in.readUnsignedByte()) << 16;
v |= (in.readUnsignedByte()) << 8;
v |= (in.readUnsignedByte());
return v * 60000L;
case 2:
// Form 10 (38 bits effective precision)
long w = (((long)v) << (64 - 6)) >> (64 - 38);
w |= (in.readUnsignedByte()) << 24;
w |= (in.readUnsignedByte()) << 16;
w |= (in.readUnsignedByte()) << 8;
w |= (in.readUnsignedByte());
return w * 1000L;
case 3:
// Form 11 (64 bits effective precision)
return in.readLong();
}
}
/**
* Reads encoding generated by writeMillis.
*/
static long readMillis(DataInput in) throws IOException {
int v = in.readUnsignedByte();
switch (v >> 6) {
case 0: default:
// Form 00 (6 bits effective precision)
v = (v << (32 - 6)) >> (32 - 6);
return v * (30 * 60000L);
case 1:
// Form 01 (30 bits effective precision)
v = (v << (32 - 6)) >> (32 - 30);
v |= (in.readUnsignedByte()) << 16;
v |= (in.readUnsignedByte()) << 8;
v |= (in.readUnsignedByte());
return v * 60000L;
case 2:
// Form 10 (38 bits effective precision)
long w = (((long)v) << (64 - 6)) >> (64 - 38);
w |= (in.readUnsignedByte()) << 24;
w |= (in.readUnsignedByte()) << 16;
w |= (in.readUnsignedByte()) << 8;
w |= (in.readUnsignedByte());
return w * 1000L;
case 3:
// Form 11 (64 bits effective precision)
return in.readLong();
}
}
static long readEpochSec(DataInput in) throws IOException {
int hiByte = in.readByte() & 255;
if (hiByte == 255) {
return in.readLong();
} else {
int midByte = in.readByte() & 255;
int loByte = in.readByte() & 255;
long tot = ((hiByte << 16) + (midByte << 8) + loByte);
return (tot * 900) - 4575744000L;
}
}
public static WireCommand readFrom(DataInput in, int length) throws IOException {
long requestId = in.readLong();
int numberOfEntries = in.readInt();
List<Long> updatedVersions = new ArrayList<>(numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
updatedVersions.add(in.readLong());
}
return new TableEntriesUpdated(requestId, updatedVersions);
}
@Override
public void readFields(DataInput in)
throws IOException {
_ix = new long[in.readInt()];
for (int i = 0; i < _ix.length; i++) {
_ix[i] = in.readLong();
}
}
static long readEpochSec(DataInput in) throws IOException {
int hiByte = in.readByte() & 255;
if (hiByte == 255) {
return in.readLong();
} else {
int midByte = in.readByte() & 255;
int loByte = in.readByte() & 255;
long tot = ((hiByte << 16) + (midByte << 8) + loByte);
return (tot * 900) - 4575744000L;
}
}
public static WireCommand readFrom(DataInput in, int length) throws IOException {
long requestId = in.readLong();
String segment = in.readUTF();
UUID attributeId = new UUID(in.readLong(), in.readLong());
long newValue = in.readLong();
long excpecteValue = in.readLong();
String delegationToken = in.readUTF();
return new UpdateSegmentAttribute(requestId, segment, attributeId, newValue, excpecteValue, delegationToken);
}
/**
* Reads encoding generated by writeMillis.
*/
static long readMillis(DataInput in) throws IOException {
int v = in.readUnsignedByte();
switch (v >> 6) {
case 0: default:
// Form 00 (6 bits effective precision)
v = (v << (32 - 6)) >> (32 - 6);
return v * (30 * 60000L);
case 1:
// Form 01 (30 bits effective precision)
v = (v << (32 - 6)) >> (32 - 30);
v |= (in.readUnsignedByte()) << 16;
v |= (in.readUnsignedByte()) << 8;
v |= (in.readUnsignedByte());
return v * 60000L;
case 2:
// Form 10 (38 bits effective precision)
long w = (((long)v) << (64 - 6)) >> (64 - 38);
w |= (in.readUnsignedByte()) << 24;
w |= (in.readUnsignedByte()) << 16;
w |= (in.readUnsignedByte()) << 8;
w |= (in.readUnsignedByte());
return w * 1000L;
case 3:
// Form 11 (64 bits effective precision)
return in.readLong();
}
}
@Override
public void readFields(DataInput in) throws IOException {
fragmentOrdinal = in.readLong();
collections = WritableUtils.readStringArray(in);
int numMetadata = in.readInt();
if (numMetadata > 0) {
String[] metaStrings = WritableUtils.readStringArray(in);
metadata = new HashMap<String, String>(numMetadata);
for (int i = 0; i < metaStrings.length - 1; i++) {
metadata.put(metaStrings[i], metaStrings[i + 1]);
}
}
quality = in.readInt();
}
public void readFields(DataInput in) throws IOException {
userid = in.readLong();
age = in.readInt();
isMale = in.readInt();
}
public UUID deserialize(DataInput in, int version) throws IOException
{
return new UUID(in.readLong(), in.readLong());
}
public void readFields(DataInput in) throws IOException {
value = in.readLong();
}
/**
* Constructs and returns a new <code>UID</code> instance by
* unmarshalling a binary representation from an
* <code>DataInput</code> instance.
*
* <p>Specifically, this method first invokes the given stream's
* {@link DataInput#readInt()} method to read a <code>unique</code> value,
* then it invoke's the stream's
* {@link DataInput#readLong()} method to read a <code>time</code> value,
* then it invoke's the stream's
* {@link DataInput#readShort()} method to read a <code>count</code> value,
* and then it creates and returns a new <code>UID</code> instance
* that contains the <code>unique</code>, <code>time</code>, and
* <code>count</code> values that were read from the stream.
*
* @param in the <code>DataInput</code> instance to read
* <code>UID</code> from
*
* @return unmarshalled <code>UID</code> instance
*
* @throws IOException if an I/O error occurs while performing
* this operation
*/
public static UID read(DataInput in) throws IOException {
int unique = in.readInt();
long time = in.readLong();
short count = in.readShort();
return new UID(unique, time, count);
}