Example usage for com.google.common.io ByteArrayDataInput readInt

List of usage examples for com.google.common.io ByteArrayDataInput readInt

Introduction

In this page you can find the example usage for com.google.common.io ByteArrayDataInput readInt.

Prototype

@Override
    int readInt();

Source Link

Usage

From source file:cpw.mods.ironchest.PacketHandler.java

@Override
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player) {
    ByteArrayDataInput dat = ByteStreams.newDataInput(packet.data);
    int x = dat.readInt();
    int y = dat.readInt();
    int z = dat.readInt();
    int typDat = dat.readByte();
    byte typ = (byte) (typDat & 0xf);
    byte facing = (byte) ((typDat >> 4) & 0xf);
    boolean hasStacks = dat.readByte() != 0;
    int[] items = new int[0];
    if (hasStacks) {
        items = new int[24];
        for (int i = 0; i < items.length; i++) {
            items[i] = dat.readInt();//from www .ja  va 2 s .  co  m
        }
    }
    World world = IronChest.proxy.getClientWorld();
    TileEntity te = world.getBlockTileEntity(x, y, z);
    if (te instanceof TileEntityIronChest) {
        TileEntityIronChest icte = (TileEntityIronChest) te;
        icte.setFacing(facing);
        icte.handlePacketData(typ, items);
    }
}

From source file:eplus.network.packets.EnchantPacket.java

@Override
public void read(ByteArrayDataInput input) {
    HashMap<Integer, Integer> temp = new HashMap<Integer, Integer>();
    this.cost = input.readInt();

    int size = input.readInt();

    for (int i = 0; i < size; i++) {
        temp.put(input.readInt(), input.readInt());
    }// w  w w .jav a 2 s.c o m
    this.map = temp;
}

From source file:eplus.network.packets.ConfigPacket.java

@Override
public void read(ByteArrayDataInput input) {
    HashMap<String, String> temp = new HashMap<String, String>();
    int count = input.readInt();

    for (int i = 0; i < count; i++) {
        temp.put(input.readUTF(), input.readUTF());
    }//from ww  w . j av a 2  s.co m

    this.configSettings = temp;
}

From source file:org.apache.hadoop.hbase.index.TableIndices.java

/**
 * @param bytes// www  .  ja  v a  2 s. c o  m
 * @throws IOException
 */
public void readFields(byte[] bytes) throws IOException {
    ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
    int indicesSize = in.readInt();
    indices.clear();
    for (int i = 0; i < indicesSize; i++) {
        IndexSpecification is = new IndexSpecification();
        is.readFields(in);
        this.indices.add(is);
    }
}

From source file:cpw.mods.fml.common.network.ModListRequestPacket.java

@Override
public FMLPacket consumePacket(byte[] data) {
    sentModList = Lists.newArrayList();/*from  www. j  a  v a  2s.  c o m*/
    ByteArrayDataInput in = ByteStreams.newDataInput(data);
    int listSize = in.readInt();
    for (int i = 0; i < listSize; i++) {
        sentModList.add(in.readUTF());
    }
    try {
        compatibilityLevel = in.readByte();
    } catch (IllegalStateException e) {
        FMLLog.fine("No compatibility byte found - the server is too old");
    }
    return this;
}

From source file:cpw.mods.fml.common.network.ModMissingPacket.java

@Override
public FMLPacket consumePacket(byte[] data) {
    ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    int missingLen = dat.readInt();
    missing = Lists.newArrayListWithCapacity(missingLen);
    for (int i = 0; i < missingLen; i++) {
        ModData md = new ModData();
        md.modId = dat.readUTF();/*from ww  w  . j a v  a2s.  c  om*/
        md.modVersion = dat.readUTF();
        missing.add(md);
    }
    int badVerLength = dat.readInt();
    badVersion = Lists.newArrayListWithCapacity(badVerLength);
    for (int i = 0; i < badVerLength; i++) {
        ModData md = new ModData();
        md.modId = dat.readUTF();
        md.modVersion = dat.readUTF();
        badVersion.add(md);
    }
    return this;
}

From source file:shadowmage.ancient_warfare.common.network.PacketHandler.java

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
    try {//from   www.  j av a2 s .  c o m
        ByteArrayDataInput data = ByteStreams.newDataInput(packet.data);
        int packetType = data.readInt();
        NBTTagCompound tag = NBTWriter.readTagFromStream(data);
        PacketBase realPacket = this.constructPacket(packetType);
        if (realPacket == null) {
            //i think it will throw before this..but w/e
            return;
        }
        realPacket.packetData = tag;
        realPacket.player = (EntityPlayer) player;
        realPacket.world = realPacket.player.worldObj;
        realPacket.readDataStream(data);
        realPacket.execute();
    } catch (Exception e) {
        Config.logError(
                "Extreme error during packet handling, could not instantiate packet instance, improper packetType info");
        Config.log("Exception During Packet Handling, problem reading packet data");
        e.printStackTrace();
    }

}

From source file:micdoodle8.mods.galacticraft.core.tile.GCCoreTileEntityFallenMeteor.java

@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet,
        EntityPlayer player, ByteArrayDataInput dataStream) {
    try {/*from   w  w w  . j a v a 2 s  .  c  o  m*/
        if (this.worldObj.isRemote) {
            this.heatLevel = dataStream.readInt();
        }
    } catch (Exception e) {
        FMLLog.severe("Failed to read packet");
        e.printStackTrace();
    }
}

From source file:cpw.mods.fml.common.network.ModListResponsePacket.java

@Override
public FMLPacket consumePacket(byte[] data) {
    ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    int versionListSize = dat.readInt();
    modVersions = Maps.newHashMapWithExpectedSize(versionListSize);
    for (int i = 0; i < versionListSize; i++) {
        String modName = dat.readUTF();
        String modVersion = dat.readUTF();
        modVersions.put(modName, modVersion);
    }//w  ww .j  av a 2  s.  c  o m

    int missingModSize = dat.readInt();
    missingMods = Lists.newArrayListWithExpectedSize(missingModSize);

    for (int i = 0; i < missingModSize; i++) {
        missingMods.add(dat.readUTF());
    }
    return this;
}

From source file:micdoodle8.mods.galacticraft.core.tile.TileEntityMulti.java

@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet,
        EntityPlayer player, ByteArrayDataInput dataStream) {
    try {//from   w ww.ja v  a 2 s . co m
        this.mainBlockPosition = new Vector3(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
    } catch (Exception e) {
        e.printStackTrace();
    }
}