java.io.DataInputStream.readByte()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中java.io.DataInputStream.readByte()方法的一些代码示例,展示了DataInputStream.readByte()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.readByte()方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:readByte

DataInputStream.readByte介绍

[英]See the general contract of the readByte method of DataInput.

Bytes for this operation are read from the contained input stream.
[中]参见readByte方法DataInput的总合同。
此操作的字节从包含的输入流中读取。

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Read an integer of this type from the given input stream
 */
public int read(DataInputStream in) throws IOException {
 switch (this) {
  case INT8:
   return in.readByte();
  case INT16:
   return in.readShort();
  case INT32:
   return in.readInt();
  default:
   throw new RuntimeException("Unknown itype: " + this);
 }
}

代码示例来源:origin: stackoverflow.com

byte[] test = new byte[] {0, 0, 1, 0, 0, 0, 1, 1, 8, 9};
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(test));
int value0 = stream.readInt();
int value1 = stream.readInt();
byte value2 = stream.readByte();
byte value3 = stream.readByte();
stream.close();
System.out.println(value0 + " " + value1 + " " + value2 + " " + value3);

代码示例来源:origin: libgdx/libgdx

protected long parseSize (final DataInputStream din, final byte type, final boolean useIntOnError, final long defaultValue)
  throws IOException {
  if (type == 'i') return (long)readUChar(din);
  if (type == 'I') return (long)readUShort(din);
  if (type == 'l') return (long)readUInt(din);
  if (type == 'L') return din.readLong();
  if (useIntOnError) {
    long result = (long)((short)type & 0xFF) << 24;
    result |= (long)((short)din.readByte() & 0xFF) << 16;
    result |= (long)((short)din.readByte() & 0xFF) << 8;
    result |= (long)((short)din.readByte() & 0xFF);
    return result;
  }
  return defaultValue;
}

代码示例来源:origin: apache/incubator-druid

/**
 * Deserialize a bloom filter
 * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)}
 * into a {@code BloomKFilter}
 *
 * @param in input bytestream
 *
 * @return deserialized BloomKFilter
 */
public static BloomKFilter deserialize(InputStream in) throws IOException
{
 if (in == null) {
  throw new IOException("Input stream is null");
 }
 try {
  DataInputStream dataInputStream = new DataInputStream(in);
  int numHashFunc = dataInputStream.readByte();
  int bitsetArrayLen = dataInputStream.readInt();
  long[] data = new long[bitsetArrayLen];
  for (int i = 0; i < bitsetArrayLen; i++) {
   data[i] = dataInputStream.readLong();
  }
  return new BloomKFilter(data, numHashFunc);
 }
 catch (RuntimeException e) {
  IOException io = new IOException("Unable to deserialize BloomKFilter");
  io.initCause(e);
  throw io;
 }
}

代码示例来源:origin: stackoverflow.com

music=new byte[(int) file.length()];//size & length of the file
 InputStream             is  = new FileInputStream       (file);
 BufferedInputStream     bis = new BufferedInputStream   (is, 8000);
 DataInputStream         dis = new DataInputStream       (bis);      //  Create a DataInputStream to read the audio data from the saved file
 int i = 0;                                                          //  Read the file into the "music" array
 while (dis.available() > 0)
 {
   music[i] = dis.readByte();                                      //  This assignment does not reverse the order
   i++;
 }
 dis.close();                                                        //  Close the input stream

代码示例来源:origin: apache/geode

private void readResourceTypeToken() throws IOException {
 int resourceTypeId = dataIn.readInt();
 String resourceTypeName = dataIn.readUTF();
 String resourceTypeDesc = dataIn.readUTF();
 int statCount = dataIn.readUnsignedShort();
 while (resourceTypeId >= resourceTypeTable.length) {
  String statName = dataIn.readUTF();
  byte typeCode = dataIn.readByte();
  boolean isCounter = dataIn.readBoolean();
  boolean largerBetter = isCounter; // default

代码示例来源:origin: aNNiMON/Lightweight-Stream-API

@Test
public void testSafeWithOnFailedConsumer() throws IOException {
  final ByteArrayOutputStream baos = new ByteArrayOutputStream(30);
  final DataOutputStream dos = new DataOutputStream(baos);
  LongConsumer consumer = LongConsumer.Util.safe(new UnsafeConsumer(dos), new LongConsumer() {
    @Override
    public void accept(long value) {
      baos.write(0);
    }
  });
  consumer.accept(10L);
  consumer.accept(20L);
  consumer.accept(-5L);
  consumer.accept(-8L);
  consumer.accept(500L);
  final byte[] result = baos.toByteArray();
  DataInputStream dis = new DataInputStream(new ByteArrayInputStream(result));
  assertThat(dis.readLong(), is(10L));
  assertThat(dis.readLong(), is(20L));
  assertThat(dis.readByte(), is((byte) 0));
  assertThat(dis.readByte(), is((byte) 0));
  assertThat(dis.readLong(), is(500L));
}

代码示例来源:origin: voldemort/voldemort

DataInputStream inputStream = new DataInputStream(new ByteBufferBackedInputStream(buffer));
  byte opCode = inputStream.readByte();
  inputStream.readUTF();

代码示例来源:origin: wildfly/wildfly

DataInputStream dis=null;
try {
  dis=new DataInputStream(input);
      version=dis.readShort();
    byte flags=dis.readByte();

代码示例来源:origin: apache/hbase

/** Now parse the old Writable format.  It was a list of Map entries.  Each map entry was a key and a value of
 * a byte [].  The old map format had a byte before each entry that held a code which was short for the key or
 * value type.  We know it was a byte [] so in below we just read and dump it.
 * @throws IOException
 */
void parseWritable(final DataInputStream in) throws IOException {
 // First clear the map.  Otherwise we will just accumulate entries every time this method is called.
 this.map.clear();
 // Read the number of entries in the map
 int entries = in.readInt();
 // Then read each key/value pair
 for (int i = 0; i < entries; i++) {
  byte [] key = Bytes.readByteArray(in);
  // We used to read a byte that encoded the class type.  Read and ignore it because it is always byte [] in hfile
  in.readByte();
  byte [] value = Bytes.readByteArray(in);
  this.map.put(key, value);
 }
}

代码示例来源:origin: apache/geode

private boolean readHandshakeForReceiver(DataInputStream dis) {
 try {
  byte b = dis.readByte();
  if (b != 0) {
   throw new IllegalStateException(
       b));
  byte handshakeByte = dis.readByte();
  if (handshakeByte != HANDSHAKE_VERSION) {
   throw new IllegalStateException(
  this.sharedResource = dis.readBoolean();
  this.preserveOrder = dis.readBoolean();
  this.uniqueId = dis.readLong();
  if (this.remoteVersion == null
    || (this.remoteVersion.compareTo(Version.GFE_80) >= 0)) {
   dominoNumber = dis.readInt();
   if (this.sharedResource) {
    dominoNumber = 0;

代码示例来源:origin: robovm/robovm

/**
 * Reads a class descriptor from the source stream.
 *
 * @return the class descriptor read from the source stream.
 * @throws ClassNotFoundException
 *             if a class for one of the objects cannot be found.
 * @throws IOException
 *             if an error occurs while reading from the source stream.
 */
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
  ObjectStreamClass newClassDesc = new ObjectStreamClass();
  String name = input.readUTF();
  if (name.length() == 0) {
    throw new IOException("The stream is corrupted");
  }
  newClassDesc.setName(name);
  newClassDesc.setSerialVersionUID(input.readLong());
  newClassDesc.setFlags(input.readByte());
  /*
   * We must register the class descriptor before reading field
   * descriptors. If called outside of readObject, the descriptorHandle
   * might be unset.
   */
  if (descriptorHandle == -1) {
    descriptorHandle = nextHandle();
  }
  registerObjectRead(newClassDesc, descriptorHandle, false);
  readFieldDescriptors(newClassDesc);
  return newClassDesc;
}

代码示例来源:origin: robovm/robovm

short numFields = input.readShort();
ObjectStreamField[] fields = new ObjectStreamField[numFields];
  char typecode = (char) input.readByte();
  String fieldName = input.readUTF();
  boolean isPrimType = ObjectStreamClass.isPrimitiveType(typecode);
  String classSig;

代码示例来源:origin: voldemort/voldemort

byte opCode = inputStream.readByte();
String storeName = inputStream.readUTF();
RequestRoutingType routingType = getRoutingType(inputStream);

代码示例来源:origin: apache/geode

private long readCompactValue() throws IOException {
 long v = dataIn.readByte();
 if (v < MIN_1BYTE_COMPACT_VALUE) {
  if (v == COMPACT_VALUE_2_TOKEN) {
   v = dataIn.readShort();
  } else {
   int bytesToRead = ((byte) v - COMPACT_VALUE_2_TOKEN) + 2;
   v = dataIn.readByte(); // note the first byte will be a signed byte.
   bytesToRead--;
   while (bytesToRead > 0) {
    v <<= 8;
    v |= dataIn.readUnsignedByte();
    bytesToRead--;
   }
  }
 }
 return v;
}

代码示例来源:origin: google/guava

int dataLength = -1;
try {
 DataInputStream din = new DataInputStream(in);
 strategyOrdinal = din.readByte();
 numHashFunctions = UnsignedBytes.toInt(din.readByte());
 dataLength = din.readInt();
  data[i] = din.readLong();

代码示例来源:origin: apache/flink

@Override
public Schema readSchema(InputStream in) throws IOException {
  DataInputStream dataInputStream = new DataInputStream(in);
  if (dataInputStream.readByte() != 0) {
    throw new IOException("Unknown data format. Magic number does not match");
  } else {
    int schemaId = dataInputStream.readInt();
    try {
      return schemaRegistryClient.getById(schemaId);
    } catch (RestClientException e) {
      throw new IOException(format("Could not find schema with id %s in registry", schemaId), e);
    }
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  FileHandle handle = Gdx.files.internal("data/arial.ttf");
  bytes = new byte[(int)handle.length()];
  DataInputStream in = new DataInputStream(handle.read());
  for (int i = 0; i < 100; i++) {
    try {
      bytes[i] = in.readByte();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: jsettlers/settlers-remake

@Override
protected void deserializeTask(DataInputStream dis) throws IOException {
  testString = dis.readUTF();
  testInt = dis.readInt();
  testByte = dis.readByte();
}

代码示例来源:origin: apache/incubator-gobblin

DataInputStream dis = new DataInputStream(new FileInputStream(outputFile));
for (int i = 0; i < 3; i++) {
 long size = dis.readLong();
 Assert.assertEquals(size, records[i].length + 1);
 for (int j = 0; j < size - 1; j++) {
  Assert.assertEquals(dis.readByte(), records[i][j]);
 Assert.assertEquals(dis.readByte(), '\n');

相关文章