下面列出了com.google.common.io.ByteArrayDataOutput#writeInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void requestMissingData() throws IOException {
synchronized (this) {
if (requestAll) {
Server connection = getConnection();
if (connection != null) {
List<DataKey<?>> keys = new ArrayList<>(getActiveKeys());
ByteArrayDataOutput data = ByteStreams.newDataOutput();
data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER);
data.writeInt(connectionId);
data.writeInt(nextOutgoingMessageId++);
data.writeInt(keys.size());
for (DataKey<?> key : keys) {
DataStreamUtils.writeDataKey(data, key);
data.writeInt(idMap.getNetId(key));
}
byte[] message = data.toByteArray();
messagesPendingConfirmation.add(message);
lastMessageSent = System.currentTimeMillis();
connection.sendData(BridgeProtocolConstants.CHANNEL, message);
}
requestAll = false;
}
}
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeInt(world.provider.dimensionId);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeUTF(playername);
}
private static byte[] finishClass(
ConstantPool pool, ByteArrayDataOutput body, ClassFile classfile) {
ByteArrayDataOutput result = ByteStreams.newDataOutput();
result.writeInt(MAGIC);
result.writeShort(MINOR_VERSION);
result.writeShort(classfile.module() != null ? MODULE_MAJOR_VERSION : MAJOR_VERSION);
writeConstantPool(pool, result);
result.write(body.toByteArray());
return result.toByteArray();
}
public static byte[] createWDLPacket1() {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeInt(1);
output.writeBoolean(false);
output.writeInt(0);
output.writeBoolean(false);
output.writeBoolean(false);
output.writeBoolean(false);
output.writeBoolean(false);
return output.toByteArray();
}
@Override
public void writeTo(ByteArrayDataOutput output) {
output.writeInt(type.ordinal());
//Data is sent through a random player. We have to tell the Bukkit version of this plugin the target
output.writeUTF(playerName);
//proxy identifier to check if it's a acceptable proxy
output.writeLong(proxyId.getMostSignificantBits());
output.writeLong(proxyId.getLeastSignificantBits());
}
@Override
public void writeTo(ByteArrayDataOutput out) {
out.writeInt(targetSkin.getRowId());
out.writeUTF(targetSkin.getEncodedValue());
out.writeUTF(targetSkin.getSignature());
out.writeUTF(receiverUUD.toString());
out.writeBoolean(skinPerm);
out.writeBoolean(isOp);
}
@Override
public void writeTo(ByteArrayDataOutput out) {
out.writeBoolean(allowed);
out.writeInt(skin.getRowId());
out.writeUTF(skin.getEncodedValue());
out.writeUTF(skin.getSignature());
out.writeUTF(receiverUUID.toString());
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeByte(type);
out.writeInt(world.provider.dimensionId);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeInt(fluidID);
out.writeInt(amount);
}
@Override
protected void write(ByteArrayDataOutput out) {
out.writeLong(id.getMostSignificantBits());
out.writeLong(id.getLeastSignificantBits());
out.writeUTF(group);
out.writeInt(buf.length);
out.write(buf);
}
@Override
protected <T> void addActiveKey(DataKey<T> key) {
super.addActiveKey(key);
try {
synchronized (this) {
Server connection = getConnection();
if (connection != null) {
ByteArrayDataOutput data = ByteStreams.newDataOutput();
data.writeByte(this instanceof PlayerBridgeDataCache ? BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA : BridgeProtocolConstants.MESSAGE_ID_REQUEST_DATA_SERVER);
data.writeInt(connectionId);
data.writeInt(nextOutgoingMessageId++);
data.writeInt(1);
DataStreamUtils.writeDataKey(data, key);
data.writeInt(idMap.getNetId(key));
byte[] message = data.toByteArray();
messagesPendingConfirmation.add(message);
lastMessageSent = System.currentTimeMillis();
connection.sendData(BridgeProtocolConstants.CHANNEL, message);
} else {
requestAll = true;
}
}
} catch (Throwable th) {
rlExecutor.execute(() -> {
logger.log(Level.SEVERE, "Unexpected exception", th);
});
requestAll = true;
}
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeInt(world.provider.dimensionId);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeUTF(playername);
out.writeInt(action);
}
private void serializeMultiset(Multiset<String> collection, ByteArrayDataOutput output) {
output.writeInt(collection.elementSet().size());
for (Multiset.Entry<String> entry : collection.entrySet()) {
output.writeUTF(entry.getElement());
output.writeInt(entry.getCount());
}
}
private void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) {
output.writeInt(collection.keySet().size());
for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) {
output.writeUTF(entry.getKey());
if (includeNames) {
serializeCollection(entry.getValue(), output);
} else {
output.writeInt(entry.getValue().size());
}
}
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeInt(world.provider.dimensionId);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeLong(filterAmount);
out.writeInt(type);
}
@Override
public byte[] serialize(I object) throws IOException {
byte[] serializedObject = delegate.serialize(object);
if(serializedObject.length > compressionThreshold) {
byte[] compressedBytes = lz4Compressor.compress(serializedObject);
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(compressedBytes.length+8);
dataOutput.write(MAGIC_HEADER);
dataOutput.writeInt(serializedObject.length);
dataOutput.write(compressedBytes);
return dataOutput.toByteArray();
} else {
return serializedObject;
}
}
@Override
public ByteBuffer serialize(I object) throws IOException {
byte[] serializedObject = delegate.serialize(object);
if(serializedObject.length > compressionThreshold) {
byte[] compressedBytes = lz4Compressor.compress(serializedObject);
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(compressedBytes.length+8);
dataOutput.write(MAGIC_HEADER);
dataOutput.writeInt(serializedObject.length);
dataOutput.write(compressedBytes);
return ByteBuffer.wrap(dataOutput.toByteArray());
} else {
return ByteBuffer.wrap(serializedObject);
}
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeUTF(playerName);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeInt(deltaSize);
out.writeInt(deltaTypes);
out.writeInt(slotID);
}
public static byte[] createWDLPacket0() {
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeInt(0);
output.writeBoolean(false);
return output.toByteArray();
}
public void testInt(int i) throws IOException {
final VarULongSerializer serializer = new VarULongSerializer();
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeInt(i);
assertEquals(i, serializer.read(ByteStreams.newDataInput(out.toByteArray())).longValue());
}
private void serializeCollection(Collection<?> collection, ByteArrayDataOutput output) {
output.writeInt(collection.size());
for (Object o : collection) {
output.writeUTF(o.toString());
}
}