本文整理了Java中java.io.DataOutputStream.writeShort()
方法的一些代码示例,展示了DataOutputStream.writeShort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataOutputStream.writeShort()
方法的具体详情如下:
包路径:java.io.DataOutputStream
类名称:DataOutputStream
方法名:writeShort
[英]Writes a short
to the underlying output stream as two bytes, high byte first. If no exception is thrown, the counter written
is incremented by 2
.
[中]将short
作为两个字节写入基础输出流,首先是高字节。如果未引发异常,计数器written
将递增2
。
代码示例来源:origin: redisson/redisson
public void write(DataOutputStream out) throws IOException {
out.writeByte(tag);
out.writeShort(memberName);
out.writeShort(typeDescriptor);
}
代码示例来源:origin: redisson/redisson
void write(DataOutputStream out) throws IOException {
out.writeShort(name);
out.writeInt(info.length);
if (info.length > 0)
out.write(info);
}
代码示例来源: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: 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: 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: apache/flume
@Deprecated
static ByteBuffer toByteBufferV2(TransactionEventRecord record) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(512);
DataOutputStream dataOutput = new DataOutputStream(byteOutput);
try {
dataOutput.writeInt(MAGIC_HEADER);
dataOutput.writeShort(record.getRecordType());
dataOutput.writeLong(record.getTransactionID());
dataOutput.writeLong(record.getLogWriteOrderID());
record.write(dataOutput);
dataOutput.flush();
// TODO toByteArray does an unneeded copy
return ByteBuffer.wrap(byteOutput.toByteArray());
} catch (IOException e) {
// near impossible
throw Throwables.propagate(e);
} finally {
if (dataOutput != null) {
try {
dataOutput.close();
} catch (IOException e) {
LOG.warn("Error closing byte array output stream", e);
}
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testReads() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream(100);
DataOutputStream dos = new DataOutputStream(bos);
String s = "test";
int i = 128;
dos.write(1);
dos.writeInt(i);
dos.writeBytes(s);
dos.writeLong(12345L);
dos.writeShort(2);
dos.flush();
ByteBuffer bb = ByteBuffer.wrap(bos.toByteArray());
bbis.close();
bb = ByteBuffer.wrap(bos.toByteArray());
bbis = new ByteBuffInputStream(new MultiByteBuff(bb));
DataInputStream dis = new DataInputStream(bbis);
代码示例来源:origin: cmusphinx/sphinx4
baos = new ByteArrayOutputStream();
dos = new DataOutputStream(baos);
dos.writeShort(new Short((short) value));
} catch (IOException e) {
e.printStackTrace();
代码示例来源:origin: libgdx/libgdx
public void writeUTF (String s) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c > 0 && c < 80) {
baos.write(c);
} else if (c < '\u0800') {
baos.write(0xc0 | (0x1f & (c >> 6)));
baos.write(0x80 | (0x3f & c));
} else {
baos.write(0xe0 | (0x0f & (c >> 12)));
baos.write(0x80 | (0x3f & (c >> 6)));
baos.write(0x80 | (0x3f & c));
}
}
writeShort(baos.count);
os.write(baos.buf, 0, baos.count);
}
}
代码示例来源: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: HotswapProjects/HotswapAgent
private MethodInfo generateStaticInitializerCaller() throws IOException {
MethodInfo minfo = new MethodInfo("<clinit>", "()V", ACC_STATIC);
DataOutputStream out = new DataOutputStream(minfo.code);
out.writeByte(opc_invokestatic);
out.writeShort(cp.getMethodRef(dotToSlash(className), initMethodName, "()V"));
out.writeByte(opc_return);
minfo.declaredExceptions = new short[0];
return minfo;
}
代码示例来源:origin: voldemort/voldemort
public void writeDeleteRequest(DataOutputStream outputStream,
String storeName,
ByteArray key,
VectorClock version,
RequestRoutingType routingType) throws IOException {
StoreUtils.assertValidKey(key);
outputStream.writeByte(VoldemortOpCode.DELETE_OP_CODE);
outputStream.writeUTF(storeName);
outputStream.writeBoolean(routingType.equals(RequestRoutingType.ROUTED));
if(protocolVersion > 1) {
outputStream.writeByte(routingType.getRoutingTypeCode());
}
outputStream.writeInt(key.length());
outputStream.write(key.get());
VectorClock clock = version;
outputStream.writeShort(clock.sizeInBytes());
outputStream.write(clock.toBytes());
}
代码示例来源:origin: btraceio/btrace
private static void writeLdc(LdcInsnNode lin, DataOutputStream dos) throws IOException {
Object o = lin.cst;
if (o instanceof Integer) {
dos.writeShort(1);
dos.writeInt((Integer)o);
} else if (o instanceof Float) {
dos.writeShort(2);
dos.writeFloat((Float)o);
} else if (o instanceof Long) {
dos.writeShort(3);
dos.writeLong((Long)o);
} else if (o instanceof Double) {
dos.writeShort(4);
dos.writeDouble((Double)o);
} else if (o instanceof String) {
dos.writeShort(5);
dos.writeUTF((String)o);
} else if (o instanceof Type) {
dos.writeShort(6);
dos.writeUTF(((Type)o).getDescriptor());
} else {
dos.writeShort(0);
}
}
代码示例来源:origin: oracle/opengrok
public void write(String outPath) throws FileNotFoundException, IOException {
offset = RECORD_LENGTH;
traverse(root);
try (DataOutputStream out = new DataOutputStream(
new BufferedOutputStream(new FileOutputStream(outPath)))) {
out.writeLong(0x5e33);
out.writeShort(RECORD_LENGTH);
out.writeShort(root.children.size());
out.writeShort(0);
offset = RECORD_LENGTH;
write(root, out);
}
}
代码示例来源:origin: HotswapProjects/HotswapAgent
/**
* Write this constant pool to a stream as part of the class file format.
*
* This consists of writing the "constant_pool_count" and "constant_pool[]" items of the "ClassFile" structure,
* as described in JVMS section 4.1.
*/
public void write(OutputStream out) throws IOException {
DataOutputStream dataOut = new DataOutputStream(out);
// constant_pool_count: number of entries plus one
dataOut.writeShort(pool.size() + 1);
for (Entry e : pool) {
e.write(dataOut);
}
}
代码示例来源:origin: Sable/soot
/** For writing out the byte stream for this utf8 properly (incl size). */
public void writeBytes(DataOutputStream dd) throws IOException {
int len;
len = bytes.length;
dd.writeShort(len - 2);
dd.write(bytes, 2, len - 2);
}
代码示例来源: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);
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Write an integer of this type to the given output stream
*/
public void write(DataOutputStream out, int value) throws IOException {
switch (this) {
case INT8:
out.writeByte(value);
break;
case INT16:
out.writeShort(value);
break;
case INT32:
out.writeInt(value);
break;
default:
throw new RuntimeException("Unknown itype: " + this);
}
}
代码示例来源:origin: apache/geode
void writeMemberToStream(GMSMember gmbr, DataOutputStream out) throws IOException {
out.writeShort(Version.CURRENT_ORDINAL);
out.writeInt(gmbr.getVmViewId());
out.writeLong(gmbr.getUuidLSBs());
out.writeLong(gmbr.getUuidMSBs());
out.flush();
}
代码示例来源:origin: redisson/redisson
int i, n;
out.writeInt(0xCAFEBABE); // magic
out.writeShort(minor); // minor version
out.writeShort(major); // major version
out.writeShort(accessFlags);
out.writeShort(thisClass);
out.writeShort(superClass);
n = interfaces.length;
out.writeShort(n);
for (i = 0; i < n; ++i)
out.writeShort(interfaces[i]);
out.writeShort(n);
for (i = 0; i < n; ++i) {
FieldInfo finfo = (FieldInfo)list.get(i);
out.writeShort(n);
for (i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo)list.get(i);
out.writeShort(attributes.size());
AttributeInfo.writeAll(attributes, out);
内容来源于网络,如有侵权,请联系作者删除!