java.io.DataOutputStream.writeByte()方法的使用及代码示例

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

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

DataOutputStream.writeByte介绍

[英]Writes an 8-bit byte to the target stream. Only the least significant byte of the integer val is written.
[中]将8位字节写入目标流。只写入整数val的最低有效字节。

代码示例

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

public void write(DataOutputStream out) throws IOException {
  out.writeByte(tag);
  out.writeByte(refKind);
  out.writeShort(refIndex);
}

代码示例来源:origin: skylot/jadx

private void writeString(DataOutputStream out, String name) throws IOException {
  byte[] bytes = name.getBytes(STRING_CHARSET);
  out.writeByte(bytes.length);
  out.write(bytes);
}

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

public void write(DataOutputStream out) throws IOException {
  out.writeByte(tag);
  out.writeLong(value);
}

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

private static void initialize() {
  try {
   ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
   DataOutputStream dout = new DataOutputStream(byteOut);
   dout.writeShort(ObjectStreamConstants.STREAM_MAGIC);
   dout.writeShort(ObjectStreamConstants.STREAM_VERSION);
   HEADER = byteOut.toByteArray();
   byteOut = new ByteArrayOutputStream();
   dout = new DataOutputStream(byteOut);
   dout.writeByte(ObjectStreamConstants.TC_OBJECT);
   dout.writeByte(ObjectStreamConstants.TC_REFERENCE);
   dout.writeInt(ObjectStreamConstants.baseWireHandle);
   REPEATING_DATA = byteOut.toByteArray();
  }
  catch(IOException e) {
   throw new Error("IOException: " + e.getMessage());
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
DataOutputStream out = new DataOutputStream(baos);
out.writeLong(l);
out.writeShort(count);
  out.writeByte(tag);
  switch(tag) {
  case 0:
    out.writeInt(in.readInt());
    break;
  case 6: // CONSTANT_Double
    out.writeLong(in.readLong());
    break;
    out.writeShort(in.readShort());
    break;
int len;
while((len=in.read(buf))>0)
  out.write(buf,0,len);
return baos.toByteArray();

代码示例来源:origin: org.easymock/easymock

private static byte[] getSerializedBytes(Class<?> clazz) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (DataOutputStream data = new DataOutputStream(baos)) {
    data.writeShort(ObjectStreamConstants.STREAM_MAGIC);
    data.writeShort(ObjectStreamConstants.STREAM_VERSION);
    data.writeByte(ObjectStreamConstants.TC_OBJECT);
    data.writeByte(ObjectStreamConstants.TC_CLASSDESC);
    data.writeUTF(clazz.getName());
    Long suid = getSerializableUID(clazz);
    data.writeLong(suid);
    data.writeByte(2); // classDescFlags (2 = Serializable)
    data.writeShort(0); // field count
    data.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
    data.writeByte(ObjectStreamConstants.TC_NULL);
  }
  return baos.toByteArray();
}

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

public byte[] getBytes() {
  try {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    DataOutputStream output = new DataOutputStream(byteOutput);
    output.writeByte(opCode);
    if(opCode != VoldemortOpCode.GET_OP_CODE)
      output.write(version.toBytes());
    output.writeUTF(key);
    if(opCode == VoldemortOpCode.PUT_OP_CODE) {
      output.writeInt(value.length);
      output.write(value);
    }
    return byteOutput.toByteArray();
  } catch(IOException e) {
    throw new SerializationException(e);
  }
}

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

public GFSnapshotExporter(File out, String region, InternalCache cache) throws IOException {
 this.cache = cache;
 FileOutputStream fos = new FileOutputStream(out);
 fc = fos.getChannel();
 dos = new DataOutputStream(new BufferedOutputStream(fos));
 // write snapshot version
 dos.writeByte(SNAP_VER_2);
 // write format type
 dos.write(SNAP_FMT);
 // write temporary pdx location in bytes 4-11
 dos.writeLong(-1);
 // write region name
 dos.writeUTF(region);
}

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

private void initializeData(DataOutputStream out) throws IOException {
 /* Write out various test values NORMALLY */
 out.write(new byte[] {-100, 100});
 out.writeBoolean(true);
 out.writeBoolean(false);
 out.writeByte(100);
 out.writeByte(-100);
 out.writeByte((byte) 200);
 out.writeChar('a');
 out.writeShort((short) -30000);
 out.writeShort((short) 50000);
 out.writeInt(0xCAFEBABE);
 out.writeLong(0xDEADBEEFCAFEBABEL);
 out.writeUTF("Herby Derby");
 out.writeFloat(Float.intBitsToFloat(0xCAFEBABE));
 out.writeDouble(Double.longBitsToDouble(0xDEADBEEFCAFEBABEL));
}

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

/**
 * Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
 * serialization). This has been measured to save at least 400 bytes compared to regular
 * serialization.
 *
 * <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
 */
public void writeTo(OutputStream out) throws IOException {
 // Serial form:
 // 1 signed byte for the strategy
 // 1 unsigned byte for the number of hash functions
 // 1 big endian int, the number of longs in our bitset
 // N big endian longs of our bitset
 DataOutputStream dout = new DataOutputStream(out);
 dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
 dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
 dout.writeInt(bits.data.length());
 for (int i = 0; i < bits.data.length(); i++) {
  dout.writeLong(bits.data.get(i));
 }
}

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

public void writeGetVersionRequest(DataOutputStream output,
                  String storeName,
                  ByteArray key,
                  RequestRoutingType routingType) throws IOException {
  StoreUtils.assertValidKey(key);
  output.writeByte(VoldemortOpCode.GET_VERSION_OP_CODE);
  output.writeUTF(storeName);
  output.writeBoolean(routingType.equals(RequestRoutingType.ROUTED));
  if(protocolVersion > 1) {
    output.writeByte(routingType.getRoutingTypeCode());
  }
  output.writeInt(key.length());
  output.write(key.get());
}

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

/** Appends a name for the next object, array, or value.
 * @return this writer, for chaining */
public UBJsonWriter name (String name) throws IOException {
  if (current == null || current.array) throw new IllegalStateException("Current item must be an object.");
  byte[] bytes = name.getBytes("UTF-8");
  if (bytes.length <= Byte.MAX_VALUE) {
    out.writeByte('i');
    out.writeByte(bytes.length);
  } else if (bytes.length <= Short.MAX_VALUE) {
    out.writeByte('I');
    out.writeShort(bytes.length);
  } else {
    out.writeByte('l');
    out.writeInt(bytes.length);
  }
  out.write(bytes);
  named = true;
  return this;
}

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

PrimitiveObjectInspector oi) throws IOException {
DataOutputStream dos = new DataOutputStream(out);
  dos.writeByte(bt);
  break;
  dos.writeShort(s);
  break;
  dos.writeInt(i);
  break;
  dos.writeLong(l);
  break;

代码示例来源:origin: skylot/jadx

public void save(OutputStream output) throws IOException {
  try (DataOutputStream out = new DataOutputStream(output)) {
    out.writeBytes(JADX_CLS_SET_HEADER);
    out.writeByte(VERSION);
    LOG.info("Classes count: {}", classes.length);
    out.writeInt(classes.length);
    for (NClass cls : classes) {
      writeString(out, cls.getName());
    }
    for (NClass cls : classes) {
      NClass[] parents = cls.getParents();
      out.writeByte(parents.length);
      for (NClass parent : parents) {
        out.writeInt(parent.getId());
      }
    }
  }
}

代码示例来源:origin: HotswapProjects/HotswapAgent

public void write(DataOutputStream out) throws IOException {
    if (value instanceof String) {
      out.writeByte(CONSTANT_UTF8);
      out.writeUTF((String) value);
    } else if (value instanceof Integer) {
      out.writeByte(CONSTANT_INTEGER);
      out.writeInt(((Integer) value).intValue());
    } else if (value instanceof Float) {
      out.writeByte(CONSTANT_FLOAT);
      out.writeFloat(((Float) value).floatValue());
    } else if (value instanceof Long) {
      out.writeByte(CONSTANT_LONG);
      out.writeLong(((Long) value).longValue());
    } else if (value instanceof Double) {
      out.writeDouble(CONSTANT_DOUBLE);
      out.writeDouble(((Double) value).doubleValue());
    } else {
      throw new InternalError("bogus value entry: " + value);
    }
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

os.writeByte((byte) tag.getValue());
break;
os.writeShort((short) tag.getValue());
break;
os.writeInt((int) tag.getValue());
break;
os.writeLong((long) tag.getValue());
break;
os.writeInt(bytes.length);
os.write(bytes);
break;
List<Tag> tags = listTag.getValue();
os.writeByte(listTag.getChildType().getId());
os.writeInt(tags.size());
for (Tag child : tags) {
  writeTagPayload(child);
  writeTag(entry.getKey(), entry.getValue());
os.writeByte((byte) 0); // end tag
break;

代码示例来源:origin: skylot/jadx

public void test(OutputStream output) throws IOException {
  DataOutputStream out = new DataOutputStream(output);
  try {
    out.writeByte(1);
    out.writeInt(classes.length);
    for (NClass cls : classes) {
      writeString(out, cls.getName());
    }
    for (NClass cls : classes) {
      NClass[] parents = cls.getParents();
      out.writeByte(parents.length);
      for (NClass parent : parents) {
        out.writeInt(parent.getId());
      }
    }
  } finally {
    out.close();
  }
}

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

public void write(DataOutputStream out) throws IOException {
  out.writeByte(tag);
  out.writeInt(value);
}

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

public static void marshalByteArray(DataOutputStream out, byte[] value, int offset, int length) throws IOException {
  out.writeByte(BYTE_ARRAY_TYPE);
  out.writeInt(length);
  out.write(value, offset, length);
}

代码示例来源:origin: EngineHub/WorldEdit

/**
 * Writes a tag.
 * 
 * @param tag
 *            The tag to write.
 * @throws IOException
 *             if an I/O error occurs.
 */
public void writeNamedTag(String name, Tag tag) throws IOException {
  checkNotNull(name);
  checkNotNull(tag);
  int type = NBTUtils.getTypeCode(tag.getClass());
  byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
  os.writeByte(type);
  os.writeShort(nameBytes.length);
  os.write(nameBytes);
  if (type == NBTConstants.TYPE_END) {
    throw new IOException("Named TAG_End not permitted.");
  }
  writeTagPayload(tag);
}

相关文章