當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteArrayDataOutput.writeByte方法代碼示例

本文整理匯總了Java中com.google.common.io.ByteArrayDataOutput.writeByte方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteArrayDataOutput.writeByte方法的具體用法?Java ByteArrayDataOutput.writeByte怎麽用?Java ByteArrayDataOutput.writeByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.io.ByteArrayDataOutput的用法示例。


在下文中一共展示了ByteArrayDataOutput.writeByte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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);
        }

    }
 
開發者ID:TheAwesomeGem,項目名稱:MineFantasy,代碼行數:19,代碼來源:BattlegearUtils.java

示例2: requestMissingData

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
void requestMissingData() throws IOException {
    synchronized (this) {
        if (requestAll) {
            Server connection = getConnection();
            if (connection != null) {
                List<DataKey<?>> keys = new ArrayList<>(getQueriedKeys());

                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;
        }
    }
}
 
開發者ID:CodeCrafter47,項目名稱:BungeeTabListPlus,代碼行數:26,代碼來源:BukkitBridge.java

示例3: 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());
    }
  }
}
 
開發者ID:google,項目名稱:turbine,代碼行數:31,代碼來源:ClassWriter.java

示例4: 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);
}
 
開發者ID:google,項目名稱:turbine,代碼行數:15,代碼來源:AttributeWriter.java

示例5: readFile

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static String readFile(URL url) throws IOException {
    InputStream in = url.openStream();
    ByteArrayDataOutput bout = ByteStreams.newDataOutput();
    int b;
    while ((b = in.read()) != -1) {
        bout.writeByte(b);
    }
    in.close();
    return new String(bout.toByteArray());
}
 
開發者ID:zxl0714,項目名稱:leveldb-sstable,代碼行數:11,代碼來源:Utils.java

示例6: makePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public static FMLProxyPacket makePacket(byte type, Object... items) {
    ByteArrayDataOutput dos = ByteStreams.newDataOutput();
    dos.writeByte(type);
    for (int i = 0; i < items.length; i++) {
        Object obj = items[i];
        if (obj instanceof Quaternion) {
            ((Quaternion) obj).write(dos);
        } else if (obj instanceof Integer) {
            dos.writeInt((Integer) obj);
        } else if (obj instanceof Byte) {
            dos.writeByte((Byte) obj);
        } else if (obj instanceof Float) {
            dos.writeFloat((Float) obj);
        } else if (obj instanceof Double) {
            dos.writeDouble((Double) obj);
        } else if (obj instanceof MovingObjectPosition) { 
            MovingObjectPosition mop = (MovingObjectPosition) obj;
            writePos(dos, mop.getBlockPos());
            dos.writeByte((byte) mop.sideHit.ordinal());
        } else if (obj instanceof Vec3) {
            Vec3 vec = (Vec3) obj;
            dos.writeDouble(vec.xCoord);
            dos.writeDouble(vec.yCoord);
            dos.writeDouble(vec.zCoord);
        } else {
            throw new IllegalArgumentException("Can only do Quaternions/Integers/Bytes/Floats/Doubles/MovingObjectPosition/Vec3! Not " + obj);
        }
    }
    return new FMLProxyPacket(new PacketBuffer(Unpooled.wrappedBuffer(dos.toByteArray())), channelName);
}
 
開發者ID:purpleposeidon,項目名稱:Factorization,代碼行數:31,代碼來源:HammerNet.java

示例7: getBytes

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] getBytes() throws Exception {
    if (cache == null || dirty) {
        ByteArrayDataOutput output = ByteStreams.newDataOutput();
        output.write(toByteArray(blocks, pocketBlock -> pocketBlock.getType().getByte())); //Block IDs
        output.write(toByteArray(new Object[16*16*64], block -> (byte) 0)); //Data
        output.write(toByteArray(new Object[16*16*64], block -> (byte) -1)); //TODO
        output.write(toByteArray(new Object[16*16*64], block -> (byte) 0));
        for (int i = 0; i < 16 * 16; i++) {
            //Height map TODO
            output.writeByte(2 & 0xff);
        }


        int[] biomeColors = new int[256];
        Arrays.fill(biomeColors, readInt(new byte[]{(byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00}));
        for (int color : biomeColors) {
            System.out.println(color);
            output.writeInt(color);
        }

        output.write(writeLInt(0));
        output.write(new byte[0]);
        cache = output.toByteArray();
        dirty = false;
    }
    return cache;
}
 
開發者ID:PocketServer,項目名稱:PocketServer-Ref,代碼行數:29,代碼來源:PocketChunk.java

示例8: makePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public final Packet makePacket()
{
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeByte( getPacketId() );
    write( out );
    return PacketDispatcher.getPacket( ModMetadata.CHANNEL_NAME,
                                       out.toByteArray() );
}
 
開發者ID:Maxwolf,項目名稱:MC-MineAPI.Java,代碼行數:9,代碼來源:PacketList.java

示例9: writeSpawnData

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public void writeSpawnData(ByteArrayDataOutput data) {
	data.writeByte(facing);
	
	data.writeByte(
		(active              ? 1 : 0) << 0 |
		(displayName != null ? 1 : 0) << 1
	);
	
	if (displayName != null) {
		data.writeUTF(displayName);
	}
}
 
開發者ID:austinv11,項目名稱:PeripheralsPlusPlus,代碼行數:14,代碼來源:Tile.java

示例10: onMissingData

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
protected <V> void onMissingData(DataKey<V> key) {
    super.onMissingData(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(() -> {
            plugin.getLogger().log(Level.SEVERE, "Unexpected exception", th);
        });
        requestAll = true;
    }
}
 
開發者ID:CodeCrafter47,項目名稱:BungeeTabListPlus,代碼行數:30,代碼來源:BukkitBridge.java

示例11: makePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public final Packet makePacket()
{
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeByte(getPacketId());
    write(out);
    return PacketDispatcher.getPacket(Reference.CHANNEL_NAME,
            out.toByteArray());
}
 
開發者ID:PaleoCrafter,項目名稱:R0b0ts,代碼行數:9,代碼來源:PacketBase.java

示例12: generatePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] generatePacket(Object... data)
{
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    Set<ModContainer> activeMods = FMLNetworkHandler.instance().getNetworkModList();
    dat.writeInt(activeMods.size());
    for (ModContainer mc : activeMods)
    {
        dat.writeUTF(mc.getModId());
    }
    dat.writeByte(FMLNetworkHandler.getCompatibilityLevel());
    return dat.toByteArray();
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:14,代碼來源:ModListRequestPacket.java

示例13: writeSpawnData

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public void writeSpawnData(ByteArrayDataOutput data) {
	data.writeByte(type);
}
 
開發者ID:austinv11,項目名稱:PeripheralsPlusPlus,代碼行數:5,代碼來源:TileLanCable.java

示例14: generatePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] generatePacket(Object... data)
{
    EntityRegistration er = (EntityRegistration) data[0];
    Entity ent = (Entity) data[1];
    NetworkModHandler handler = (NetworkModHandler) data[2];
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();

    dat.writeInt(handler.getNetworkId());
    dat.writeInt(er.getModEntityId());
    // entity id
    dat.writeInt(ent.field_70157_k);

    // entity pos x,y,z
    dat.writeInt(MathHelper.func_76128_c(ent.field_70165_t * 32D));
    dat.writeInt(MathHelper.func_76128_c(ent.field_70163_u * 32D));
    dat.writeInt(MathHelper.func_76128_c(ent.field_70161_v * 32D));

    // yaw, pitch
    dat.writeByte((byte) (ent.field_70177_z * 256.0F / 360.0F));
    dat.writeByte((byte) (ent.field_70125_A * 256.0F / 360.0F));

    // head yaw
    if (ent instanceof EntityLiving)
    {
        dat.writeByte((byte) (((EntityLiving)ent).field_70759_as * 256.0F / 360.0F));
    }
    else
    {
        dat.writeByte(0);
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    try
    {
        ent.func_70096_w().func_75689_a(dos);
    }
    catch (IOException e)
    {
        // unpossible
    }

    dat.write(bos.toByteArray());

    if (ent instanceof IThrowableEntity)
    {
        Entity owner = ((IThrowableEntity)ent).getThrower();
        dat.writeInt(owner == null ? ent.field_70157_k : owner.field_70157_k);
        double maxVel = 3.9D;
        double mX = ent.field_70159_w;
        double mY = ent.field_70181_x;
        double mZ = ent.field_70179_y;
        if (mX < -maxVel) mX = -maxVel;
        if (mY < -maxVel) mY = -maxVel;
        if (mZ < -maxVel) mZ = -maxVel;
        if (mX >  maxVel) mX =  maxVel;
        if (mY >  maxVel) mY =  maxVel;
        if (mZ >  maxVel) mZ =  maxVel;
        dat.writeInt((int)(mX * 8000D));
        dat.writeInt((int)(mY * 8000D));
        dat.writeInt((int)(mZ * 8000D));
    }
    else
    {
        dat.writeInt(0);
    }
    if (ent instanceof IEntityAdditionalSpawnData)
    {
        ((IEntityAdditionalSpawnData)ent).writeSpawnData(dat);
    }

    return dat.toByteArray();
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:74,代碼來源:EntitySpawnPacket.java

示例15: generatePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] generatePacket(Object... data)
{
    EntityRegistration er = (EntityRegistration) data[0];
    Entity ent = (Entity) data[1];
    NetworkModHandler handler = (NetworkModHandler) data[2];
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();

    dat.writeInt(handler.getNetworkId());
    dat.writeInt(er.getModEntityId());
    // entity id
    dat.writeInt(ent.entityId);

    // entity pos x,y,z
    dat.writeInt(MathHelper.floor_double(ent.posX * 32D));
    dat.writeInt(MathHelper.floor_double(ent.posY * 32D));
    dat.writeInt(MathHelper.floor_double(ent.posZ * 32D));

    // yaw, pitch
    dat.writeByte((byte) (ent.rotationYaw * 256.0F / 360.0F));
    dat.writeByte((byte) (ent.rotationPitch * 256.0F / 360.0F));

    // head yaw
    if (ent instanceof EntityLiving)
    {
        dat.writeByte((byte) (((EntityLiving)ent).rotationYawHead * 256.0F / 360.0F));
    }
    else
    {
        dat.writeByte(0);
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    try
    {
        ent.getDataWatcher().writeWatchableObjects(dos);
    }
    catch (IOException e)
    {
        // unpossible
    }

    dat.write(bos.toByteArray());

    if (ent instanceof IThrowableEntity)
    {
        Entity owner = ((IThrowableEntity)ent).getThrower();
        dat.writeInt(owner == null ? ent.entityId : owner.entityId);
        double maxVel = 3.9D;
        double mX = ent.motionX;
        double mY = ent.motionY;
        double mZ = ent.motionZ;
        if (mX < -maxVel) mX = -maxVel;
        if (mY < -maxVel) mY = -maxVel;
        if (mZ < -maxVel) mZ = -maxVel;
        if (mX >  maxVel) mX =  maxVel;
        if (mY >  maxVel) mY =  maxVel;
        if (mZ >  maxVel) mZ =  maxVel;
        dat.writeInt((int)(mX * 8000D));
        dat.writeInt((int)(mY * 8000D));
        dat.writeInt((int)(mZ * 8000D));
    }
    else
    {
        dat.writeInt(0);
    }
    if (ent instanceof IEntityAdditionalSpawnData)
    {
        ((IEntityAdditionalSpawnData)ent).writeSpawnData(dat);
    }

    return dat.toByteArray();
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:74,代碼來源:EntitySpawnPacket.java


注:本文中的com.google.common.io.ByteArrayDataOutput.writeByte方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。