本文整理匯總了Java中com.google.common.io.ByteArrayDataOutput.writeShort方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayDataOutput.writeShort方法的具體用法?Java ByteArrayDataOutput.writeShort怎麽用?Java ByteArrayDataOutput.writeShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.ByteArrayDataOutput
的用法示例。
在下文中一共展示了ByteArrayDataOutput.writeShort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encodeString
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
* Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
* Strings are prefixed by 2 values. The first is the number of characters in the string.
* The second is the encoding length (number of bytes in the string).
*
* <p>Here's an example UTF-8-encoded string of ab©:
* <pre>03 04 61 62 C2 A9 00</pre>
*
* @param str The string to be encoded.
* @param type The encoding type that the {@link ResourceString} should be encoded in.
* @return The encoded string.
*/
public static byte[] encodeString(String str, Type type) {
byte[] bytes = str.getBytes(type.charset());
// The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
encodeLength(output, str.length(), type);
if (type == Type.UTF8) { // Only UTF-8 strings have the encoding length.
encodeLength(output, bytes.length, type);
}
output.write(bytes);
// NULL-terminate the string
if (type == Type.UTF8) {
output.write(0);
} else {
output.writeShort(0);
}
return output.toByteArray();
}
示例2: encodeString
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
* Encodes a string in either UTF-8 or UTF-16 and returns the bytes of the encoded string.
* Strings are prefixed by 2 values. The first is the number of characters in the string.
* The second is the encoding length (number of bytes in the string).
*
* <p>Here's an example UTF-8-encoded string of ab©:
* <pre>03 04 61 62 C2 A9 00</pre>
*
* @param str The string to be encoded.
* @param type The encoding type that the {@link ResourceString} should be encoded in.
* @return The encoded string.
*/
public static byte[] encodeString(String str, Type type) {
byte[] bytes = str.getBytes(type.charset());
// The extra 5 bytes is for metadata (character count + byte count) and the NULL terminator.
ByteArrayDataOutput output = ByteStreams.newDataOutput(bytes.length + 5);
encodeLength(output, str.length(), type);
if (type == Type.UTF8) { // Only UTF-8 strings have the encoding length.
encodeLength(output, bytes.length, type);
}
output.write(bytes);
// NULL-terminate the string
if (type == Type.UTF8) {
output.write(0);
} else {
output.writeShort(0);
}
return output.toByteArray();
}
示例3: sendSignUpdateRequest
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static void sendSignUpdateRequest(Game game) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
String name = SkyWarsReloaded.getCfg().getBungeeServer();
try {
out.writeUTF("Forward");
out.writeUTF("ALL");
out.writeUTF("SkyWarsReloaded");
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
DataOutputStream msgout = new DataOutputStream(msgbytes);
msgout.writeUTF(name + ":" + game.getState().toString() + ":" + Integer.toString(game.getPlayers().size()) + ":" + Integer.toString(game.getNumberOfSpawns()) + ":" + game.getMapName());
out.writeShort(msgbytes.toByteArray().length);
out.write(msgbytes.toByteArray());
Bukkit.getServer().sendPluginMessage(SkyWarsReloaded.get(), "BungeeCord", out.toByteArray());
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: writeClass
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/** Writes a {@link ClassFile} to bytecode. */
public static byte[] writeClass(ClassFile classfile) {
ConstantPool pool = new ConstantPool();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeShort(classfile.access());
output.writeShort(pool.classInfo(classfile.name()));
output.writeShort(classfile.superName() != null ? pool.classInfo(classfile.superName()) : 0);
output.writeShort(classfile.interfaces().size());
for (String i : classfile.interfaces()) {
output.writeShort(pool.classInfo(i));
}
output.writeShort(classfile.fields().size());
for (ClassFile.FieldInfo f : classfile.fields()) {
writeField(pool, output, f);
}
output.writeShort(classfile.methods().size());
for (ClassFile.MethodInfo m : classfile.methods()) {
writeMethod(pool, output, m);
}
writeAttributes(pool, output, LowerAttributes.classAttributes(classfile));
return finishClass(pool, output);
}
示例5: writeItemStack
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static void writeItemStack(ByteArrayDataOutput par1DataOutputStream, ItemStack par0ItemStack) throws IOException {
if (par0ItemStack == null) {
par1DataOutputStream.writeShort(-1);
} else {
par1DataOutputStream.writeShort(par0ItemStack.itemID);
par1DataOutputStream.writeByte(par0ItemStack.stackSize);
par1DataOutputStream.writeShort(par0ItemStack.getItemDamage());
NBTTagCompound nbttagcompound = null;
if (par0ItemStack.getItem().isDamageable() || par0ItemStack.getItem().getShareTag()) {
nbttagcompound = par0ItemStack.stackTagCompound;
}
writeNBTTagCompound(nbttagcompound, par1DataOutputStream);
}
}
示例6: appendPayload
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public void appendPayload(ByteArrayDataOutput out) {
out.writeUTF(serverName);
out.writeUTF(channelName);
out.writeShort(data.length);
out.write(data);
}
示例7: writeMethod
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static void writeMethod(
ConstantPool pool, ByteArrayDataOutput output, ClassFile.MethodInfo method) {
output.writeShort(method.access());
output.writeShort(pool.utf8(method.name()));
output.writeShort(pool.utf8(method.descriptor()));
writeAttributes(pool, output, LowerAttributes.methodAttributes(method));
}
示例8: writeField
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static void writeField(
ConstantPool pool, ByteArrayDataOutput output, ClassFile.FieldInfo field) {
output.writeShort(field.access());
output.writeShort(pool.utf8(field.name()));
output.writeShort(pool.utf8(field.descriptor()));
writeAttributes(pool, output, LowerAttributes.fieldAttributes(field));
}
示例9: writeAttributes
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static void writeAttributes(
ConstantPool pool, ByteArrayDataOutput body, List<Attribute> attributes) {
body.writeShort(attributes.size());
for (Attribute attribute : attributes) {
new AttributeWriter(pool, body).write(attribute);
}
}
示例10: writeConstantPool
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
static void writeConstantPool(ConstantPool constantPool, ByteArrayDataOutput output) {
output.writeShort(constantPool.nextEntry);
for (ConstantPool.Entry e : constantPool.constants()) {
output.writeByte(e.kind().tag());
Value value = e.value();
switch (e.kind()) {
case CLASS_INFO:
case STRING:
output.writeShort(((IntValue) value).value());
break;
case INTEGER:
output.writeInt(((IntValue) value).value());
break;
case DOUBLE:
output.writeDouble(((DoubleValue) value).value());
break;
case FLOAT:
output.writeFloat(((FloatValue) value).value());
break;
case LONG:
output.writeLong(((LongValue) value).value());
break;
case UTF8:
output.writeUTF(((StringValue) value).value());
break;
default:
throw new AssertionError(e.kind());
}
}
}
示例11: finishClass
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private static byte[] finishClass(ConstantPool pool, ByteArrayDataOutput body) {
ByteArrayDataOutput result = ByteStreams.newDataOutput();
result.writeInt(MAGIC);
result.writeShort(MINOR_VERSION);
result.writeShort(MAJOR_VERSION);
writeConstantPool(pool, result);
result.write(body.toByteArray());
return result.toByteArray();
}
示例12: writeAnnotation
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public void writeAnnotation(Annotations attribute) {
output.writeShort(pool.utf8(attribute.kind().signature()));
ByteArrayDataOutput tmp = ByteStreams.newDataOutput();
tmp.writeShort(attribute.annotations().size());
for (AnnotationInfo annotation : attribute.annotations()) {
new AnnotationWriter(pool, tmp).writeAnnotation(annotation);
}
byte[] data = tmp.toByteArray();
output.writeInt(data.length);
output.write(data);
}
示例13: writeParameterAnnotations
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public void writeParameterAnnotations(Attribute.ParameterAnnotations attribute) {
output.writeShort(pool.utf8(attribute.kind().signature()));
ByteArrayDataOutput tmp = ByteStreams.newDataOutput();
tmp.writeByte(attribute.annotations().size());
for (List<AnnotationInfo> parameterAnnotations : attribute.annotations()) {
tmp.writeShort(parameterAnnotations.size());
for (AnnotationInfo annotation : parameterAnnotations) {
new AnnotationWriter(pool, tmp).writeAnnotation(annotation);
}
}
byte[] data = tmp.toByteArray();
output.writeInt(data.length);
output.write(data);
}
示例14: writeTypeAnnotation
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private void writeTypeAnnotation(TypeAnnotations attribute) {
output.writeShort(pool.utf8(attribute.kind().signature()));
ByteArrayDataOutput tmp = ByteStreams.newDataOutput();
tmp.writeShort(attribute.annotations().size());
for (TypeAnnotationInfo annotation : attribute.annotations()) {
new AnnotationWriter(pool, tmp).writeTypeAnnotation(annotation);
}
byte[] data = tmp.toByteArray();
output.writeInt(data.length);
output.write(data);
}
示例15: writeNBTTagCompound
import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
protected static void writeNBTTagCompound(NBTTagCompound par0NBTTagCompound, ByteArrayDataOutput par1DataOutputStream) throws IOException {
if (par0NBTTagCompound == null) {
par1DataOutputStream.writeShort(-1);
} else {
byte[] abyte = CompressedStreamTools.compress(par0NBTTagCompound);
par1DataOutputStream.writeShort((short) abyte.length);
par1DataOutputStream.write(abyte);
}
}