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


Java ByteArrayDataOutput.writeInt方法代碼示例

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


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

示例1: getData

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public byte[] getData() {
    if (this.cache == null || this.dirty) {
        ByteArrayDataOutput output = ByteStreams.newDataOutput();
        output.write(toByteArray(blocks, pocketBlock -> (byte) pocketBlock.getId()));
        output.write(data.getRaw());
        output.write(lighting.getRaw());
        output.write(skylight.getRaw());
        output.write(height.getRaw());

        for (int i = 0; i < this.biomes.length; ++i) {
            byte r = this.biomeColors[i * 3];
            byte g = this.biomeColors[i * 3 + 1];
            byte b = this.biomeColors[i * 3 + 2];
            int color = r << 16 | g << 8 | b;
            output.writeInt(24 << this.biomes[i] | color & 0xffffff);
        }
        output.writeInt(0);

        this.dirty = false;
        this.cache = output.toByteArray();
    }
    return this.cache;
}
 
開發者ID:PocketServer,項目名稱:PocketServer,代碼行數:24,代碼來源:PocketChunk.java

示例2: createWDLPacket4

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Creates the WDL packet #4.
 * 
 * This packet specifies the initial overrides for what chunks can and
 * cannot be saved.
 *
 * This packet starts with an int stating the number of keys, and then a
 * series of values for 1 range group. The range group starts with its name
 * (the key in ranges), then an int (the number of ranges) and then each of
 * the ranges as generated by
 * {@link #writeProtectionRange(ProtectionRange, ByteArrayDataOutput)}.
 */
public static byte[] createWDLPacket4(
		Map<String, List<ProtectionRange>> ranges) {
	ByteArrayDataOutput output = ByteStreams.newDataOutput();
	
	output.writeInt(4);
	
	output.writeInt(ranges.size());
	
	for (String key : ranges.keySet()) {
		output.writeUTF(key);
		List<ProtectionRange> rangeGroup = ranges.get(key);
		output.writeInt(rangeGroup.size());
		for (ProtectionRange range : rangeGroup) {
			writeProtectionRange(range, output);
		}
	}
	
	return output.toByteArray();
}
 
開發者ID:Pokechu22,項目名稱:WorldDownloader-Serverside-Companion,代碼行數:32,代碼來源:WDLPackets.java

示例3: createWDLPacket5

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Creates the WDL packet #5.
 * 
 * This packet specifies adds additional overrides to or sets all of the
 * overrides in a single group.
 *
 * This packet starts with a String stating the group, then a boolean that
 * specifies whether it is setting (true) or adding (false) the ranges, and
 * then an int (the number of ranges that will be added). Then, each range,
 * formated by
 * {@link #writeProtectionRange(ProtectionRange, ByteArrayDataOutput)}.
 */
public static byte[] createWDLPacket5(String group,
		boolean replace, List<ProtectionRange> ranges) {
	ByteArrayDataOutput output = ByteStreams.newDataOutput();
	
	output.writeInt(5);
	
	output.writeUTF(group);
	output.writeBoolean(replace);
	output.writeInt(ranges.size());
	
	for (ProtectionRange range : ranges) {
		writeProtectionRange(range, output);
	}
	
	return output.toByteArray();
}
 
開發者ID:Pokechu22,項目名稱:WorldDownloader-Serverside-Companion,代碼行數:29,代碼來源:WDLPackets.java

示例4: createWDLPacket7

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Creates the WDL packet #7.
 * 
 * This packet replaces all of the ranges with the given tag with a new set
 * of ranges.
 *
 * This packet starts with a String stating the group, then a second string
 * that specifies the tag to replace. After that, there is an int stating
 * the number of ranges, and then each range as formated by
 * {@link #writeProtectionRange(ProtectionRange, ByteArrayDataOutput)}.
 */
public static byte[] createWDLPacket7(String group,
		String tag, List<ProtectionRange> newRanges) {
	ByteArrayDataOutput output = ByteStreams.newDataOutput();
	
	output.writeInt(7);
	
	output.writeUTF(group);
	output.writeUTF(tag);
	
	output.writeInt(newRanges.size());
	
	for (ProtectionRange range : newRanges) {
		writeProtectionRange(range, output);
	}
	
	return output.toByteArray();
}
 
開發者ID:Pokechu22,項目名稱:WorldDownloader-Serverside-Companion,代碼行數:29,代碼來源:WDLPackets.java

示例5: writeProtectionRange

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Writes a protection range to the given output stream.
 * 
 * This is a string with the range's tag, then 4 integers for the
 * coordinates (x1, z1, x2, z2). This method also swaps x1 and x2 if x1 is
 * greater than x2.
 */
private static void writeProtectionRange(ProtectionRange range, 
		ByteArrayDataOutput output) {
	output.writeUTF(range.tag);
	
	int x1 = range.x1, z1 = range.z1;
	int x2 = range.x2, z2 = range.z2;
	
	if (x1 > x2) {
		x2 = range.x1;
		x1 = range.x2;
	}
	if (z1 > z2) {
		z2 = range.z1;
		z1 = range.z2;
	}
	
	output.writeInt(x1);
	output.writeInt(z1);
	output.writeInt(x2);
	output.writeInt(z2);
}
 
開發者ID:Pokechu22,項目名稱:WorldDownloader-Serverside-Companion,代碼行數:29,代碼來源:WDLPackets.java

示例6: 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

示例7: sign

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
public SignResponse sign(DeviceRegistration registeredDevice, SignRequest startedSignature) throws Exception {
    Map<String, String> clientData = new HashMap<String, String>();
    clientData.put("typ", "navigator.id.getAssertion");
    clientData.put("challenge", startedSignature.getChallenge());
    clientData.put("origin", "http://example.com");
    String clientDataJson = objectMapper.writeValueAsString(clientData);


    byte[] clientParam = crypto.hash(clientDataJson);
    byte[] appParam = crypto.hash(startedSignature.getAppId());
    com.yubico.u2f.softkey.messages.SignRequest signRequest = new com.yubico.u2f.softkey.messages.SignRequest((byte) 0x01, clientParam, appParam, U2fB64Encoding.decode(registeredDevice.getKeyHandle()));

    RawSignResponse rawSignResponse = key.sign(signRequest);

    String clientDataBase64 = U2fB64Encoding.encode(clientDataJson.getBytes());
    ByteArrayDataOutput authData = ByteStreams.newDataOutput();
    authData.write(rawSignResponse.getUserPresence());
    authData.writeInt((int) rawSignResponse.getCounter());
    authData.write(rawSignResponse.getSignature());

    return new SignResponse(
            clientDataBase64,
            U2fB64Encoding.encode(authData.toByteArray()),
            startedSignature.getKeyHandle()
    );
}
 
開發者ID:Yubico,項目名稱:java-u2flib-server,代碼行數:27,代碼來源:Client.java

示例8: generatePacket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public byte[] generatePacket(Object... data)
{
    Map<String,String> modVersions = (Map<String, String>) data[0];
    List<String> missingMods = (List<String>) data[1];
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    dat.writeInt(modVersions.size());
    for (Entry<String, String> version : modVersions.entrySet())
    {
        dat.writeUTF(version.getKey());
        dat.writeUTF(version.getValue());
    }
    dat.writeInt(missingMods.size());
    for (String missing : missingMods)
    {
        dat.writeUTF(missing);
    }
    return dat.toByteArray();
}
 
開發者ID:HATB0T,項目名稱:RuneCraftery,代碼行數:20,代碼來源:ModListResponsePacket.java

示例9: write

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
@Override
public void write(ByteArrayDataOutput out)
{
    super.write(out);
    out.writeInt(orientation);
    out.writeBoolean(validMultiblock);
    out.writeUTF(selectedModule);
    out.writeUTF(selectedChipset);
    out.writeInt(armorId);
    out.writeBoolean(progressing);
    out.writeInt(progress);
    out.writeBoolean(energyPos != null);
    if (energyPos != null)
    {
        out.writeInt((int) energyPos.x);
        out.writeInt((int) energyPos.y);
        out.writeInt((int) energyPos.z);
    }
}
 
開發者ID:PaleoCrafter,項目名稱:R0b0ts,代碼行數:20,代碼來源:PacketFactoryController.java

示例10: updateAmount

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private void updateAmount() {
	int amount = item == null ? 0 : item.stackSize;
	if (prevAmount != amount || prevMaxSize != maxSize) {
		World world = turtle.getWorld();
		Vec3 pos = turtle.getPosition();
		int x = (int)Math.floor(pos.xCoord);
		int y = (int)Math.floor(pos.yCoord);
		int z = (int)Math.floor(pos.zCoord);
		
		ByteArrayDataOutput os = ByteStreams.newDataOutput();
		os.writeInt(x);
		os.writeInt(y);
		os.writeInt(z);
		os.writeInt(amount);
		os.writeInt(maxSize);
		PacketDispatcher.sendPacketToAllAround(pos.xCoord + 0.5D, pos.yCoord + 0.5D, pos.zCoord + 0.5D, 64.0D, world.provider.dimensionId, PacketDispatcher.getTinyPacket(MiscPeripherals.instance, (short)5, os.toByteArray()));
	}
}
 
開發者ID:austinv11,項目名稱:PeripheralsPlusPlus,代碼行數:19,代碼來源:PeripheralBarrel.java

示例11: writeMarket

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
private void writeMarket(StockList market, ByteArrayDataOutput out) {
    out.writeInt(market.getCategoryCount());

    for (int i = 0; i < market.getCategoryCount(); i++) {
        StockCategory category = market.getCategory(i);

        out.writeUTF(category.getCategoryName());
        out.writeInt(Item.itemRegistry.getIDForObject(category.getIconItem().getItem()));
        out.writeInt(category.getIconItem().getItemDamage());
        out.writeInt(category.getItemCount());

        for (int j = 0; j < category.getItemCount(); j ++) {
            StockItem item = category.get(j);

            out.writeInt(Item.itemRegistry.getIDForObject(item.getItem().getItem()));
            out.writeInt(item.getItem().getItemDamage());
            out.writeInt((item.getValue()));
        }
    }
}
 
開發者ID:CannibalVox,項目名稱:ModJamTeleporters,代碼行數:21,代碼來源:FullMarketDataPacket.java

示例12: setClusterIds

import com.google.common.io.ByteArrayDataOutput; //導入方法依賴的package包/類
/**
 * Marks that the clusters with the given clusterIds have consumed the mutation
 * @param clusterIds of the clusters that have consumed the mutation
 */
public Mutation setClusterIds(List<UUID> clusterIds) {
  ByteArrayDataOutput out = ByteStreams.newDataOutput();
  out.writeInt(clusterIds.size());
  for (UUID clusterId : clusterIds) {
    out.writeLong(clusterId.getMostSignificantBits());
    out.writeLong(clusterId.getLeastSignificantBits());
  }
  setAttribute(CONSUMED_CLUSTER_IDS, out.toByteArray());
  return this;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:Mutation.java

示例13: 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

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

示例15: 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


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