本文整理汇总了Java中java.io.DataInput类的典型用法代码示例。如果您正苦于以下问题:Java DataInput类的具体用法?Java DataInput怎么用?Java DataInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataInput类属于java.io包,在下文中一共展示了DataInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testStringArrayObject
import java.io.DataInput; //导入依赖的package包/类
/**
* Tests data serializing a <code>String</code> array using {@link DataSerializer#writeObject}.
*/
@Test
public void testStringArrayObject() throws Exception {
Random random = getRandom();
String[] array = new String[] {String.valueOf(random.nextLong()),
String.valueOf(random.nextLong()), String.valueOf(random.nextLong())};
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(array, out);
out.flush();
DataInput in = getDataInput();
String[] array2 = (String[]) DataSerializer.readObject(in);
assertEquals(array.length, array2.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], array2[i]);
}
}
示例2: fromDataInputV2
import java.io.DataInput; //导入依赖的package包/类
@Deprecated
static TransactionEventRecord fromDataInputV2(DataInput in)
throws IOException {
int header = in.readInt();
if (header != MAGIC_HEADER) {
throw new IOException("Header " + Integer.toHexString(header) +
" is not the required value: " + Integer.toHexString(MAGIC_HEADER));
}
short type = in.readShort();
long transactionID = in.readLong();
long writeOrderID = in.readLong();
TransactionEventRecord entry = newRecordForType(type, transactionID,
writeOrderID);
entry.readFields(in);
return entry;
}
示例3: readOplogMagicSeqRecord
import java.io.DataInput; //导入依赖的package包/类
private void readOplogMagicSeqRecord(DataInput dis, OPLOG_TYPE type) throws IOException {
byte[] seq = new byte[OPLOG_TYPE.getLen()];
dis.readFully(seq);
for (int i = 0; i < OPLOG_TYPE.getLen(); i++) {
if (seq[i] != type.getBytes()[i]) {
if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
logger.trace(LogMarker.PERSIST_RECOVERY,
"oplog magic code mismatched at byte:{}, value:{}", (i + 1), seq[i]);
}
throw new DiskAccessException("Invalid oplog (" + type.name() + ") file provided.",
interpreter.getNameForError());
}
}
if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < OPLOG_TYPE.getLen(); i++) {
sb.append(" " + seq[i]);
}
logger.trace(LogMarker.PERSIST_RECOVERY, "oplog magic code: {}", sb);
}
readEndOfRecord(dis);
}
示例4: readIdentityHashMap
import java.io.DataInput; //导入依赖的package包/类
/**
* Reads a <code>IdentityHashMap</code> from a <code>DataInput</code>. Note that key identity is
* not preserved unless the keys belong to a class whose serialization preserves identity.
*
* @throws IOException A problem occurs while reading from <code>in</code>
* @throws ClassNotFoundException The class of one of the <Code>IdentityHashMap</code>'s elements
* cannot be found.
*
* @see #writeIdentityHashMap
*/
public static <K, V> IdentityHashMap<K, V> readIdentityHashMap(DataInput in)
throws IOException, ClassNotFoundException {
InternalDataSerializer.checkIn(in);
int size = InternalDataSerializer.readArrayLength(in);
if (size == -1) {
return null;
} else {
IdentityHashMap<K, V> map = new IdentityHashMap<K, V>(size);
for (int i = 0; i < size; i++) {
K key = DataSerializer.<K>readObject(in);
V value = DataSerializer.<V>readObject(in);
map.put(key, value);
}
if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
logger.trace(LogMarker.SERIALIZER, "Read IdentityHashMap with {} elements: {}", size, map);
}
return map;
}
}
示例5: unpackUnsignedLong
import java.io.DataInput; //导入依赖的package包/类
public static long unpackUnsignedLong(DataInput buffer) throws IOException
{
int shift = 0;
long result = 0;
while (shift < 64)
{
final byte b = buffer.readByte();
result |= (long)(b & 0x7F) << shift;
if ((b & 0x80) == 0)
{
return result;
}
shift += 7;
}
throw new IllegalArgumentException("Variable length quantity is too long");
}
示例6: readRootIndex
import java.io.DataInput; //导入依赖的package包/类
/**
* Read in the root-level index from the given input stream. Must match
* what was written into the root level by
* {@link BlockIndexWriter#writeIndexBlocks(FSDataOutputStream)} at the
* offset that function returned.
*
* @param in the buffered input stream or wrapped byte input stream
* @param numEntries the number of root-level index entries
* @throws IOException
*/
public void readRootIndex(DataInput in, final int numEntries)
throws IOException {
blockOffsets = new long[numEntries];
blockKeys = new byte[numEntries][];
blockDataSizes = new int[numEntries];
// If index size is zero, no index was written.
if (numEntries > 0) {
for (int i = 0; i < numEntries; ++i) {
long offset = in.readLong();
int dataSize = in.readInt();
byte[] key = Bytes.readByteArray(in);
add(key, offset, dataSize);
}
}
}
示例7: loadSnapshotList
import java.io.DataInput; //导入依赖的package包/类
/**
* Load snapshots and snapshotQuota for a Snapshottable directory.
*
* @param snapshottableParent
* The snapshottable directory for loading.
* @param numSnapshots
* The number of snapshots that the directory has.
* @param loader
* The loader
*/
public static void loadSnapshotList(INodeDirectory snapshottableParent,
int numSnapshots, DataInput in, FSImageFormat.Loader loader)
throws IOException {
DirectorySnapshottableFeature sf = snapshottableParent
.getDirectorySnapshottableFeature();
Preconditions.checkArgument(sf != null);
for (int i = 0; i < numSnapshots; i++) {
// read snapshots
final Snapshot s = loader.getSnapshot(in);
s.getRoot().setParent(snapshottableParent);
sf.addSnapshot(s);
}
int snapshotQuota = in.readInt();
snapshottableParent.setSnapshotQuota(snapshotQuota);
}
示例8: readFields
import java.io.DataInput; //导入依赖的package包/类
@Override
public void readFields(DataInput in) throws IOException {
// Get the number of "unknown" classes
newClasses = in.readByte();
// Then read in the class names and add them to our tables
for (int i = 0; i < newClasses; i++) {
byte id = in.readByte();
String className = in.readUTF();
try {
addToMap(Class.forName(className), id);
} catch (ClassNotFoundException e) {
throw new IOException("can't find class: " + className + " because "+
e.getMessage());
}
}
}
示例9: fromData
import java.io.DataInput; //导入依赖的package包/类
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
this.className = DataSerializer.readString(in);
swizzleGemFireClassNames();
{
byte bits = in.readByte();
this.noDomainClass = (bits & NO_DOMAIN_CLASS_BIT) != 0;
this.hasDeletedField = (bits & HAS_DELETED_FIELD_BIT) != 0;
}
this.typeId = in.readInt();
this.vlfCount = in.readInt();
int arrayLen = InternalDataSerializer.readArrayLength(in);
for (int i = 0; i < arrayLen; i++) {
PdxField vft = new PdxField();
vft.fromData(in);
addField(vft);
}
}
示例10: doStart
import java.io.DataInput; //导入依赖的package包/类
private final void doStart() throws IOException {
ReadUtil.readCheckType(m_stream, AXML_CHUNK_TYPE);
/*chunk size*/
ReadUtil.readInt(m_stream);
m_strings = StringBlock.read(new ExtDataInput((DataInput) new LittleEndianDataInputStream(m_stream)));
ReadUtil.readCheckType(m_stream, RESOURCEIDS_CHUNK_TYPE);
int chunkSize = ReadUtil.readInt(m_stream);
if (chunkSize < 8 || (chunkSize % 4) != 0) {
throw new IOException("Invalid resource ids size (" + chunkSize + ").");
}
m_resourceIDs = ReadUtil.readIntArray(m_stream, chunkSize / 4 - 2);
resetState();
}
示例11: testStack
import java.io.DataInput; //导入依赖的package包/类
/**
* Tests data serializing an {@link Stack}
*/
@Test
public void testStack() throws Exception {
Random random = getRandom();
Stack list = new Stack();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
list.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeStack(list, out);
out.flush();
DataInput in = getDataInput();
Stack list2 = DataSerializer.readStack(in);
assertEquals(list, list2);
}
示例12: testTreeMapObject
import java.io.DataInput; //导入依赖的package包/类
/**
* Tests data serializing an {@link TreeMap} using {@link DataSerializer#writeObject}.
*/
@Test
public void testTreeMapObject() throws Exception {
Random random = getRandom();
TreeMap map = new TreeMap();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
Object key = new Long(random.nextLong());
Object value = String.valueOf(random.nextLong());
map.put(key, value);
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(map, out);
out.flush();
DataInput in = getDataInput();
TreeMap map2 = (TreeMap) DataSerializer.readObject(in);
assertEquals(map, map2);
}
示例13: deserializeFromWritable
import java.io.DataInput; //导入依赖的package包/类
/**
* Deserialize the file trailer as writable data
* @param input
* @throws IOException
*/
void deserializeFromWritable(DataInput input) throws IOException {
fileInfoOffset = input.readLong();
loadOnOpenDataOffset = input.readLong();
dataIndexCount = input.readInt();
uncompressedDataIndexSize = input.readLong();
metaIndexCount = input.readInt();
totalUncompressedBytes = input.readLong();
entryCount = input.readLong();
compressionCodec = Compression.Algorithm.values()[input.readInt()];
numDataIndexLevels = input.readInt();
firstDataBlockOffset = input.readLong();
lastDataBlockOffset = input.readLong();
// TODO this is a classname encoded into an HFile's trailer. We are going to need to have
// some compat code here.
setComparatorClass(getComparatorClass(Bytes.readStringFixedSize(input,
MAX_COMPARATOR_NAME_LENGTH)));
}
示例14: fromData
import java.io.DataInput; //导入依赖的package包/类
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
this.hasKeys = in.readBoolean();
if (this.hasKeys) {
this.keys = new ArrayList();
}
int numObjects = in.readInt();
if (numObjects > 0) {
for (int index = 0; index < numObjects; ++index) {
if (this.hasKeys) {
Object key = DataSerializer.readObject(in);
this.keys.add(key);
}
boolean isException = in.readBoolean();
Object value;
if (isException) {
byte[] exBytes = DataSerializer.readByteArray(in);
value = CacheServerHelper.deserialize(exBytes);
// ignore the exception string meant for native clients
DataSerializer.readString(in);
} else {
value = DataSerializer.readObject(in);
}
this.objects.add(value);
}
}
}
示例15: readFields
import java.io.DataInput; //导入依赖的package包/类
@Override public void readFields(DataInput in) throws IOException {
int size = in.readInt();
ranges = new MDRange[size];
for (int i = 0; i < size; i++) {
int min = in.readInt();
int max = in.readInt();
ranges[i] = new MDRange(min, max);
}
}