下面列出了java.io.DataInput#readUTF ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Decodes a built DateTimeZone from the given stream, as encoded by
* writeTo.
*
* @param in input stream to read encoded DateTimeZone from.
* @param id time zone id to assign
*/
public static DateTimeZone readFrom(DataInput in, String id) throws IOException {
switch (in.readUnsignedByte()) {
case 'F':
DateTimeZone fixed = new FixedDateTimeZone
(id, in.readUTF(), (int)readMillis(in), (int)readMillis(in));
if (fixed.equals(DateTimeZone.UTC)) {
fixed = DateTimeZone.UTC;
}
return fixed;
case 'C':
return CachedDateTimeZone.forZone(PrecalculatedZone.readFrom(in, id));
case 'P':
return PrecalculatedZone.readFrom(in, id);
default:
throw new IOException("Invalid encoding");
}
}
/**
* Decodes a built DateTimeZone from the given stream, as encoded by
* writeTo.
*
* @param in input stream to read encoded DateTimeZone from.
* @param id time zone id to assign
*/
public static DateTimeZone readFrom(DataInput in, String id) throws IOException {
switch (in.readUnsignedByte()) {
case 'F':
DateTimeZone fixed = new FixedDateTimeZone
(id, in.readUTF(), (int)readMillis(in), (int)readMillis(in));
if (fixed.equals(DateTimeZone.UTC)) {
fixed = DateTimeZone.UTC;
}
return fixed;
case 'C':
return CachedDateTimeZone.forZone(PrecalculatedZone.readFrom(in, id));
case 'P':
return PrecalculatedZone.readFrom(in, id);
default:
throw new IOException("Invalid encoding");
}
}
public void read(DataInput in) throws IOException {
int version = in.readInt();
if (version != SERIALIZED_VERSION) {
throw new IOException(String.format("Invalid version, expected %d, got %d",
SERIALIZED_VERSION, version));
}
int numEntries = in.readInt();
_secondaryIndexUrls = new String[numEntries];
_secondaryIndex = new SecondaryIndex[numEntries];
for (int i = 0; i < numEntries; i++) {
_secondaryIndexUrls[i] = in.readUTF();
}
for (int i = 0; i < numEntries; i++) {
SecondaryIndex si = new SecondaryIndex();
si.read(in);
_secondaryIndex[i] = si;
}
}
public void readFields(DataInput in) throws IOException {
try {
namespace = in.readUTF();
setName = in.readUTF();
int digestLen = in.readInt();
digest = new byte[digestLen];
in.readFully(digest);
if (in.readBoolean()) {
int buflen = in.readInt();
byte[] buff = new byte[buflen];
in.readFully(buff);
ObjectUnpacker unpack = new ObjectUnpacker(buff, 0, buff.length);
userKey = Value.get(unpack.unpackObject());
}
}
catch (Exception ex) {
throw new IOException(ex);
}
}
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
// Read string pool.
int poolSize = in.readUnsignedShort();
String[] pool = new String[poolSize];
for (int i=0; i<poolSize; i++) {
pool[i] = in.readUTF();
}
int size = in.readInt();
long[] transitions = new long[size];
int[] wallOffsets = new int[size];
int[] standardOffsets = new int[size];
String[] nameKeys = new String[size];
for (int i=0; i<size; i++) {
transitions[i] = readMillis(in);
wallOffsets[i] = (int)readMillis(in);
standardOffsets[i] = (int)readMillis(in);
try {
int index;
if (poolSize < 256) {
index = in.readUnsignedByte();
} else {
index = in.readUnsignedShort();
}
nameKeys[i] = pool[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Invalid encoding");
}
}
DSTZone tailZone = null;
if (in.readBoolean()) {
tailZone = DSTZone.readFrom(in, id);
}
return new PrecalculatedZone
(id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
private void read(DataInput input) throws IOException {
String foo = input.readUTF();
if (!foo.equals(MAGIC_STRING))
throw new Error(
"Error reading word embedding. Magic string not found.");
int entries = input.readInt();
for (int i = 0; i < entries; ++i) {
String str = input.readUTF();
double[] entry = new double[DEF_DIMENSIONALITY];
for (int j = 0; j < entry.length; j++)
entry[j] = input.readDouble();
map.put(str, new EmbeddingEntry(entry));
}
}
@Override
public void readFields(DataInput in) throws IOException {
oid=in.readInt();
cid= in.readInt();
sid = in.readInt();
tid=in.readInt();
qty=in.readInt();
type=in.readUTF();
price=new BigDecimal(in.readUTF());
orderTime=new Timestamp(in.readLong());
type=type.equals(" ")?null:type;
orderTime=orderTime.equals(new Timestamp(1000))?null:orderTime;
}
@Override
public void readFields(DataInput in) throws IOException {
file = new Path(in.readUTF());
start = in.readLong();
length = in.readLong();
int size = in.readInt();
hosts = new String[size];
for (int i = 0; i < size; i++) {
hosts[i] = in.readUTF();
}
}
public static void myFromData(BaseValueHolder vh, DataInput in) throws IOException {
vh.myVersion = in.readUTF();
vh.myValue = readObject(in);
vh.extraObject = readObject(in);
// read modVal
String aStr = in.readUTF();
if (aStr.equals("null")) {
vh.modVal = null;
} else {
vh.modVal = Integer.valueOf(aStr);
}
}
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
// Read string pool.
int poolSize = in.readUnsignedShort();
String[] pool = new String[poolSize];
for (int i=0; i<poolSize; i++) {
pool[i] = in.readUTF();
}
int size = in.readInt();
long[] transitions = new long[size];
int[] wallOffsets = new int[size];
int[] standardOffsets = new int[size];
String[] nameKeys = new String[size];
for (int i=0; i<size; i++) {
transitions[i] = readMillis(in);
wallOffsets[i] = (int)readMillis(in);
standardOffsets[i] = (int)readMillis(in);
try {
int index;
if (poolSize < 256) {
index = in.readUnsignedByte();
} else {
index = in.readUnsignedShort();
}
nameKeys[i] = pool[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Invalid encoding");
}
}
DSTZone tailZone = null;
if (in.readBoolean()) {
tailZone = DSTZone.readFrom(in, id);
}
return new PrecalculatedZone
(id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
// Read string pool.
int poolSize = in.readUnsignedShort();
String[] pool = new String[poolSize];
for (int i=0; i<poolSize; i++) {
pool[i] = in.readUTF();
}
int size = in.readInt();
long[] transitions = new long[size];
int[] wallOffsets = new int[size];
int[] standardOffsets = new int[size];
String[] nameKeys = new String[size];
for (int i=0; i<size; i++) {
transitions[i] = readMillis(in);
wallOffsets[i] = (int)readMillis(in);
standardOffsets[i] = (int)readMillis(in);
try {
int index;
if (poolSize < 256) {
index = in.readUnsignedByte();
} else {
index = in.readUnsignedShort();
}
nameKeys[i] = pool[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Invalid encoding");
}
}
DSTZone tailZone = null;
if (in.readBoolean()) {
tailZone = DSTZone.readFrom(in, id);
}
return new PrecalculatedZone
(id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
public void readFields(DataInput in) throws IOException {
contentType=in.readUTF();
UUID=in.readUTF();
dateString=in.readUTF();
recordType=in.readUTF();
metadata.clear();
int numMetaItems=in.readInt();
for (int i=0; i < numMetaItems; i++) {
String thisKey=in.readUTF();
String thisValue=in.readUTF();
metadata.put(thisKey, thisValue);
}
contentLength=in.readInt();
}
@Override
public void readFields(DataInput in) throws IOException {
cid = in.readInt();
tid=in.readInt();
cash=new BigDecimal(in.readUTF());
securities=new BigDecimal(in.readUTF());
loanLimit=in.readInt();
availLoan=new BigDecimal(in.readUTF());
}
TVEditorial(DataInput in, byte ver, Map<Integer, Integer> idMap) throws IOException
{
super(in, ver, idMap);
showID = readID(in, idMap);
title = Wizard.getInstance().getTitleForID(readID(in, idMap));
network = Wizard.getInstance().getNetworkForID(readID(in, idMap));
airdate = in.readUTF();
description = in.readUTF();
imageURL = in.readUTF();
setMediaMask(MEDIA_MASK_TV);
}
/**
* Reads replica Id metadata via the {@link DataInput} provided.
* @param in The interface that reads bytes from a binary stream and converts it
* to the data of required type.
* @return Returns the {@code ReplicaId}.
* @throws IOException thrown if the read fails.
*/
public static ReplicaId readFrom(DataInput in) throws IOException {
byte version = in.readByte();
if (version != VERSION) {
throw new IOException("unsupported version");
}
int partitionId = in.readInt();
String storageNodeConnectString = in.readUTF();
return new ReplicaId(partitionId, storageNodeConnectString);
}
static PrecalculatedZone readFrom(DataInput in, String id) throws IOException {
// Read string pool.
int poolSize = in.readUnsignedShort();
String[] pool = new String[poolSize];
for (int i=0; i<poolSize; i++) {
pool[i] = in.readUTF();
}
int size = in.readInt();
long[] transitions = new long[size];
int[] wallOffsets = new int[size];
int[] standardOffsets = new int[size];
String[] nameKeys = new String[size];
for (int i=0; i<size; i++) {
transitions[i] = readMillis(in);
wallOffsets[i] = (int)readMillis(in);
standardOffsets[i] = (int)readMillis(in);
try {
int index;
if (poolSize < 256) {
index = in.readUnsignedByte();
} else {
index = in.readUnsignedShort();
}
nameKeys[i] = pool[index];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IOException("Invalid encoding");
}
}
DSTZone tailZone = null;
if (in.readBoolean()) {
tailZone = DSTZone.readFrom(in, id);
}
return new PrecalculatedZone
(id, transitions, wallOffsets, standardOffsets, nameKeys, tailZone);
}
static ConstantUtf8 getInstance(DataInput input) throws IOException {
return new ConstantUtf8(input.readUTF());
}
public static WireCommand readFrom(DataInput in, int length) throws IOException {
long requestId = in.readLong();
String segment = in.readUTF();
return new SegmentDeleted(requestId, segment);
}
public void readFields(DataInput dataInput) throws IOException {
routingKey = dataInput.readUTF();
payload = new byte[dataInput.readInt()];
dataInput.readFully(payload);
}
static Recurrence readFrom(DataInput in) throws IOException {
return new Recurrence(OfYear.readFrom(in), in.readUTF(), (int)readMillis(in));
}