Java Code Examples for com.google.common.io.ByteArrayDataInput#readInt()

The following examples show how to use com.google.common.io.ByteArrayDataInput#readInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstantPoolReader.java    From turbine with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a constant value at the given index, which must be one of CONSTANT_String_info,
 * CONSTANT_Integer_info, CONSTANT_Float_info, CONSTANT_Long_info, or CONSTANT_Double_info.
 */
Const.Value constant(int index) {
  ByteArrayDataInput reader = byteReader.seek(constantPool[index - 1]);
  byte tag = reader.readByte();
  switch (tag) {
    case CONSTANT_LONG:
      return new Const.LongValue(reader.readLong());
    case CONSTANT_FLOAT:
      return new Const.FloatValue(reader.readFloat());
    case CONSTANT_DOUBLE:
      return new Const.DoubleValue(reader.readDouble());
    case CONSTANT_INTEGER:
      return new Const.IntValue(reader.readInt());
    case CONSTANT_STRING:
      return new Const.StringValue(utf8(reader.readUnsignedShort()));
    case CONSTANT_UTF8:
      return new Const.StringValue(reader.readUTF());
    default:
      throw new AssertionError(String.format("bad tag: %x", tag));
  }
}
 
Example 2
Source File: BungeeCordVariables.java    From ScoreboardStats with MIT License 6 votes vote down vote up
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(BUNGEE_CHANNEL)) {
        return;
    }

    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    String subChannel = in.readUTF();
    if ("PlayerCount".equals(subChannel)) {
        try {
            String server = in.readUTF();
            int count = in.readInt();

            if ("ALL".equals(server)) {
                onlinePlayers = count;
            }
        } catch (Exception eofException) {
            //happens if bungeecord doesn't know the server
            //ignore the admin should be notified by seeing the -1
        }
    }
}
 
Example 3
Source File: PlayerSqlProtocol.java    From PlayerSQL with GNU General Public License v2.0 5 votes vote down vote up
public PlayerSqlProtocol decode(ByteArrayDataInput input) {
    DataSupply pk = new DataSupply();
    pk.setId(new UUID(input.readLong(), input.readLong()));
    pk.setGroup(input.readUTF());
    byte[] buf = new byte[input.readInt()];
    input.readFully(buf);
    pk.setBuf(buf);
    return pk;
}
 
Example 4
Source File: PacketMonitorFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	fluidID = in.readInt();
}
 
Example 5
Source File: PacketTerminalFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	type = in.readByte();
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	fluidID = in.readInt();
	amount = in.readInt();
}
 
Example 6
Source File: PacketLevelEmitterFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	filterAmount = in.readLong();
	type = in.readInt();
}
 
Example 7
Source File: PacketBusFluidExport.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
	action = in.readInt();
}
 
Example 8
Source File: PacketBusFluidImport.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
	action = in.readInt();
}
 
Example 9
Source File: PacketBusFluidStorage.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	priority = in.readInt();
}
 
Example 10
Source File: PacketMEBattery.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
}
 
Example 11
Source File: PacketSolderingStation.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	playerName = in.readUTF();
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	deltaSize = in.readInt();
	deltaTypes = in.readInt();
	slotID = in.readInt();
}
 
Example 12
Source File: OreDictCachePacket.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public GT_Packet decode(ByteArrayDataInput byteArrayDataInput) {
    int size = byteArrayDataInput.readInt();
    for (int i = 0; i < size; i++) {
        this.hashSet.add(new Pair<>(byteArrayDataInput.readInt(),byteArrayDataInput.readShort()));
    }
    return new OreDictCachePacket(this.hashSet);
}
 
Example 13
Source File: PermResultMessage.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    allowed = in.readBoolean();

    int rowId = in.readInt();
    String encodedValue = in.readUTF();
    String encodedSignature = in.readUTF();

    skin = SkinModel.createSkinFromEncoded(encodedValue, encodedSignature);
    skin.setRowId(rowId);

    receiverUUID = UUID.fromString(in.readUTF());
}
 
Example 14
Source File: CheckPermMessage.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    int rowId = in.readInt();
    String encodedData = in.readUTF();
    String encodedSignature = in.readUTF();

    targetSkin = SkinModel.createSkinFromEncoded(encodedData, encodedSignature);
    targetSkin.setRowId(rowId);

    //continue on success only
    receiverUUD = UUID.fromString(in.readUTF());
    skinPerm = in.readBoolean();
    isOp = in.readBoolean();
}
 
Example 15
Source File: LoginActionMessage.java    From FastLogin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput input) {
    this.type = Type.values()[input.readInt()];

    this.playerName = input.readUTF();

    //bungeecord UUID
    long mostSignificantBits = input.readLong();
    long leastSignificantBits = input.readLong();
    this.proxyId = new UUID(mostSignificantBits, leastSignificantBits);
}
 
Example 16
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    in.readUTF();
    String ip = in.readUTF();
    int port = in.readInt();
    this.callback.supply(Maps.immutableEntry(ip, port));
    return true;
}
 
Example 17
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    in.readUTF();
    int count = in.readInt();
    this.callback.supply(count);
    return true;
}
 
Example 18
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    String ip = in.readUTF();
    int port = in.readInt();
    this.callback.supply(Maps.immutableEntry(ip, port));
    return true;
}
 
Example 19
Source File: UpgradeCounterValues.java    From datawave with Apache License 2.0 4 votes vote down vote up
protected void run(String[] args) throws ParseException, AccumuloSecurityException, AccumuloException, TableNotFoundException, IOException {
    parseConfig(args);
    
    ZooKeeperInstance instance = new ZooKeeperInstance(ClientConfiguration.loadDefault().withInstance(instanceName).withZkHosts(zookeepers));
    Connector connector = instance.getConnector(username, new PasswordToken(password));
    Authorizations auths = connector.securityOperations().getUserAuthorizations(connector.whoami());
    
    try (BatchWriter writer = connector.createBatchWriter(tableName, new BatchWriterConfig().setMaxWriteThreads(bwThreads).setMaxMemory(bwMemory)
                    .setMaxLatency(60, TimeUnit.SECONDS));
                    BatchScanner scanner = connector.createBatchScanner(tableName, auths, bsThreads)) {
        scanner.setRanges(ranges);
        
        for (Entry<Key,Value> entry : scanner) {
            Key key = entry.getKey();
            
            ByteArrayDataInput in = ByteStreams.newDataInput(entry.getValue().get());
            Counters counters = new Counters();
            try {
                counters.readFields(in);
            } catch (IOException e) {
                // The IO exception means the counters are in the wrong format. We *assume* that they are in
                // the old (CDH3) format, and de-serialize according to that, and re-write the key with the new value.
                in = ByteStreams.newDataInput(entry.getValue().get());
                int numGroups = in.readInt();
                while (numGroups-- > 0) {
                    String groupName = Text.readString(in);
                    String groupDisplayName = Text.readString(in);
                    CounterGroup group = counters.addGroup(groupName, groupDisplayName);
                    
                    int groupSize = WritableUtils.readVInt(in);
                    for (int i = 0; i < groupSize; i++) {
                        String counterName = Text.readString(in);
                        String counterDisplayName = counterName;
                        if (in.readBoolean())
                            counterDisplayName = Text.readString(in);
                        long value = WritableUtils.readVLong(in);
                        group.addCounter(counterName, counterDisplayName, value);
                    }
                }
                
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                counters.write(out);
                Mutation m = new Mutation(key.getRow());
                m.put(key.getColumnFamily(), key.getColumnQualifier(), key.getColumnVisibilityParsed(), key.getTimestamp() + 1,
                                new Value(out.toByteArray()));
                writer.addMutation(m);
            }
        }
        
    }
}