本文整理汇总了Java中java.io.DataInput.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java DataInput.readFully方法的具体用法?Java DataInput.readFully怎么用?Java DataInput.readFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataInput
的用法示例。
在下文中一共展示了DataInput.readFully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import java.io.DataInput; //导入方法依赖的package包/类
public Token deserialize(DataInput in, IPartitioner p, int version) throws IOException
{
int size = in.readInt();
byte[] bytes = new byte[size];
in.readFully(bytes);
return p.getTokenFactory().fromByteArray(ByteBuffer.wrap(bytes));
}
示例2: readBigInteger
import java.io.DataInput; //导入方法依赖的package包/类
/**
* Reads {@link BigInteger} value that was written via {@link #writeBigInteger(BigInteger, DataOutput)}.
*
* @param in Data input.
*
* @return Value.
*
* @throws IOException if failed to read value.
*/
public static BigInteger readBigInteger(DataInput in) throws IOException {
byte hint = in.readByte();
switch (hint) {
case DECIMAL_ZERO: {
return BigInteger.ZERO;
}
case DECIMAL_ONE: {
return BigInteger.ONE;
}
case DECIMAL_TEN: {
return BigInteger.TEN;
}
case DECIMAL_SMALL_UNSCALED: {
long val = readVarLong(in);
return BigInteger.valueOf(val);
}
case DECIMAL_BIG: {
int bytesLen = readVarIntUnsigned(in);
byte[] bytes = new byte[bytesLen];
in.readFully(bytes);
return new BigInteger(bytes);
}
default: {
throw new StreamCorruptedException("Unexpected hint for " + BigInteger.class.getName() + " value [hint=" + hint + ']');
}
}
}
示例3: decrypt
import java.io.DataInput; //导入方法依赖的package包/类
@Override
byte[] decrypt(byte[] key, byte[] data) {
try {
// Sun's impelemntation of GCM uses a custom algorithm name. We handle this odd (potentially incorrect) behavior here.
AlgorithmParameters params = AlgorithmParameters.getInstance(isInstanceOfSunProvidedGCM ? "GCM" : "AES");
// Read the metadata.
ByteArrayInputStream stream = new ByteArrayInputStream(data);
DataInput in = new DataInputStream(stream);
int metadataLength = WritableUtils.readVInt(in);
byte[] metadata = new byte[metadataLength];
in.readFully(metadata);
params.init(metadata);
// Decrypt the remaining data.
SecretKeySpec keySpec = new SecretKeySpec(key, AES);
cipher.init(Cipher.DECRYPT_MODE, keySpec, params);
byte[] ciphertext = new byte[stream.available()];
in.readFully(ciphertext);
cipher.init(Cipher.DECRYPT_MODE, keySpec, params);
return cipher.doFinal(ciphertext);
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException
| IOException e) {
throw new EncryptionException(e);
}
}
示例4: readFields
import java.io.DataInput; //导入方法依赖的package包/类
/**
*/
@Override
public void readFields(DataInput in) throws IOException {
keyId = WritableUtils.readVInt(in);
expiryDate = WritableUtils.readVLong(in);
int len = WritableUtils.readVIntInRange(in, -1, MAX_KEY_LEN);
if (len == -1) {
keyBytes = null;
} else {
keyBytes = new byte[len];
in.readFully(keyBytes);
}
}
示例5: readString
import java.io.DataInput; //导入方法依赖的package包/类
protected String readString(final DataInput in) throws IOException {
final String string = in.readUTF();
if (!ID_SPLITTED.equals(string)) {
return string;
}
final int size = in.readInt();
final byte[] bytes = new byte[size];
in.readFully(bytes);
return new String(bytes, "utf-8");
}
示例6: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
length = in.readInt();
if (data == null || length > data.length)
data = new byte[length];
in.readFully(data, 0, length);
}
示例7: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
id = WritableUtils.readVInt(in);
expirationDate = WritableUtils.readVLong(in);
int keyLength = WritableUtils.readVInt(in);
if (keyLength < 0) {
secret = null;
} else {
byte[] keyBytes = new byte[keyLength];
in.readFully(keyBytes);
secret = AuthenticationTokenSecretManager.createSecretKey(keyBytes);
}
}
示例8: Synthetic
import java.io.DataInput; //导入方法依赖的package包/类
/**
* Construct object from input stream.
*
* @param name_index Index in constant pool to CONSTANT_Utf8
* @param length Content length in bytes
* @param input Input stream
* @param constant_pool Array of constants
* @throws IOException
*/
Synthetic(final int name_index, final int length, final DataInput input, final ConstantPool constant_pool)
throws IOException {
this(name_index, length, (byte[]) null, constant_pool);
if (length > 0) {
bytes = new byte[length];
input.readFully(bytes);
System.err.println("Synthetic attribute with length > 0");
}
}
示例9: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
int tableNameLen = in.readInt();
byte[] name = new byte[tableNameLen];
in.readFully(name);
this.tableName = TableName.valueOf(name);
this.startRow = in.readInt();
this.rows = in.readInt();
this.totalRows = in.readInt();
this.clients = in.readInt();
this.flushCommits = in.readBoolean();
this.writeToWAL = in.readBoolean();
this.useTags = in.readBoolean();
this.noOfTags = in.readInt();
}
示例10: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
length = in.readUnsignedShort();
if (bytes == null || bytes.length < length)
bytes = new byte[length];
in.readFully(bytes, 0, length);
}
示例11: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
super.readFields(in);
byte aclEntriesSize = in.readByte();
if (aclEntriesSize != NO_ACL_ENTRIES) {
aclEntries = Lists.newArrayListWithCapacity(aclEntriesSize);
for (int i = 0; i < aclEntriesSize; ++i) {
aclEntries.add(new AclEntry.Builder()
.setScope(ACL_ENTRY_SCOPES[in.readByte()])
.setType(ACL_ENTRY_TYPES[in.readByte()])
.setName(WritableUtils.readString(in))
.setPermission(FS_ACTIONS[in.readByte()])
.build());
}
} else {
aclEntries = null;
}
int xAttrsSize = in.readInt();
if (xAttrsSize != NO_XATTRS) {
xAttrs = Maps.newHashMap();
for (int i = 0; i < xAttrsSize; ++i) {
final String name = WritableUtils.readString(in);
final int valueLen = in.readInt();
byte[] value = null;
if (valueLen > -1) {
value = new byte[valueLen];
if (valueLen > 0) {
in.readFully(value);
}
}
xAttrs.put(name, value);
}
} else {
xAttrs = null;
}
}
示例12: fromData
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
long l;
if (in == null) {
throw new NullPointerException("Null DataInput");
}
this.hasKeys = in.readBoolean();
this.index = in.readInt();
this.typeArray = new byte[index];
this.keyArray = new Object[index];
this.objectArray = new Object[index];
byte objectType;
Object value;
int length;
byte[] bytes;
for (int i = 0; i < this.index; i++) {
if (this.hasKeys) {
length = in.readByte();
bytes = new byte[length];
in.readFully(bytes, 0, length);
this.keyArray[i] = bytes;
}
objectType = in.readByte();
if (objectType == BYTES) {
length = in.readShort();
if (length >= 0) {
bytes = new byte[length];
in.readFully(bytes, 0, length);
} else {
bytes = null;
}
value = bytes;
} else if (objectType == OBJECT) {
value = DataSerializer.readObject(in);
} else if (objectType == EXCEPTION) {
byte[] exBytes = DataSerializer.readByteArray(in);
value = CacheServerHelper.deserialize(exBytes);
// ignore the exception string meant for native clients
DataSerializer.readString(in);
} else {
value = null;
}
this.objectArray[i] = value;
}
}
示例13: readVarintBytes
import java.io.DataInput; //导入方法依赖的package包/类
private static byte[] readVarintBytes(DataInput in) throws IOException {
final int length = ProtoUtil.readRawVarint32(in);
final byte[] bytes = new byte[length];
in.readFully(bytes);
return bytes;
}
示例14: readFields
import java.io.DataInput; //导入方法依赖的package包/类
public void readFields(final DataInput in) throws IOException {
this.length = in.readInt();
this.bytes = new byte[this.length];
in.readFully(this.bytes, 0, this.length);
this.offset = 0;
}
示例15: readFields
import java.io.DataInput; //导入方法依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
this.bytes = new byte[in.readInt()];
in.readFully(this.bytes);
weight = in.readDouble();
}