Search in sources :

Example 6 with ByteArrayDataInput

use of com.google.common.io.ByteArrayDataInput in project cdap by caskdata.

the class AbstractBatchReadableInputFormat method getSplits.

@Override
public List<InputSplit> getSplits(final JobContext context) throws IOException, InterruptedException {
    // Decode splits from Configuration
    String splitsConf = context.getConfiguration().get(SPLITS);
    if (splitsConf == null) {
        throw new IOException("No input splits available from job configuration.");
    }
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(Bytes.toBytesBinary(splitsConf));
    int size = dataInput.readInt();
    List<InputSplit> splits = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        DataSetInputSplit inputSplit = new DataSetInputSplit();
        inputSplit.readFields(dataInput);
        splits.add(inputSplit);
    }
    return splits;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Example 7 with ByteArrayDataInput

use of com.google.common.io.ByteArrayDataInput in project SpaciousLib by anhcraft.

the class BungeeManager method onPluginMessageReceived.

@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(CHANNEL)) {
        return;
    }
    ByteArrayDataInput i = ByteStreams.newDataInput(message);
    String sc = i.readUTF();
    boolean b = false;
    for (BungeeResponse br : queue) {
        if (sc.equals("IP") && br instanceof BungeePlayerIPResponse) {
            ((BungeePlayerIPResponse) br).result(i.readUTF(), i.readInt());
            b = true;
        }
        if (sc.equals("PlayerCount") && br instanceof BungeePlayerAmountResponse) {
            ((BungeePlayerAmountResponse) br).result(i.readUTF(), i.readInt());
            b = true;
        }
        if (sc.equals("PlayerList") && br instanceof BungeePlayerListResponse) {
            ((BungeePlayerListResponse) br).result(i.readUTF(), new ArrayList<>(Arrays.asList(i.readUTF().split(", "))));
            b = true;
        }
        if (sc.equals("GetServers") && br instanceof BungeeServerListResponse) {
            ((BungeeServerListResponse) br).result(new ArrayList<>(Arrays.asList(i.readUTF().split(", "))));
            b = true;
        }
        if (sc.equals("GetServer") && br instanceof BungeeServerNameResponse) {
            ((BungeeServerNameResponse) br).result(i.readUTF());
            b = true;
        }
        if (sc.equals("UUID") && br instanceof BungeePlayerUUIDResponse) {
            ((BungeePlayerUUIDResponse) br).result(UUID.fromString(i.readUTF()));
            b = true;
        }
        if (sc.equals("UUIDOther") && br instanceof BungeeOtherPlayerUUIDResponse) {
            ((BungeeOtherPlayerUUIDResponse) br).result(i.readUTF(), UUID.fromString(i.readUTF()));
            b = true;
        }
        if (sc.equals("ServerIP") && br instanceof BungeeServerIPResponse) {
            ((BungeeServerIPResponse) br).result(i.readUTF(), i.readUTF(), i.readUnsignedShort());
            b = true;
        }
        if (b) {
            break;
        }
    }
    if (b) {
        queue.remove(0);
    } else {
        byte[] bytedata = new byte[i.readShort()];
        i.readFully(bytedata);
        DataInputStream data = new DataInputStream(new ByteArrayInputStream(bytedata));
        BungeeForwardEvent ev = new BungeeForwardEvent(sc, data);
        Bukkit.getServer().getPluginManager().callEvent(ev);
    }
}
Also used : BungeeForwardEvent(org.anhcraft.spaciouslib.events.BungeeForwardEvent) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 8 with ByteArrayDataInput

use of com.google.common.io.ByteArrayDataInput in project Network-depr by Mas281.

the class BungeeListener method onPluginMessageReceived.

@Override
public void onPluginMessageReceived(String channel, Player unused, byte[] data) {
    ByteArrayDataInput in = ByteStreams.newDataInput(data);
    if (channel.equals("BungeeCord")) {
        switch(in.readUTF()) {
            case "GetServer":
                {
                    String serverName = in.readUTF();
                    log("Received server name: %s ", serverName);
                    module.setServerName(serverName);
                    if (module instanceof RedisNetwork) {
                        ((RedisNetwork) module).resetQueue();
                    }
                    break;
                }
            case "GetServers":
                {
                    Set<String> servers = Sets.newHashSet(in.readUTF().split(", "));
                    module.setServers(Collections.unmodifiableSet(servers));
                    break;
                }
        }
    } else if (channel.equals("ServerUpdates")) {
        switch(in.readUTF()) {
            case "ProxyLeave":
                {
                    String player = in.readUTF();
                    module.removeTrackingData(player);
                }
        }
    }
}
Also used : Set(java.util.Set) RedisNetwork(me.itsmas.network.server.network.redis.RedisNetwork) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput)

Aggregations

ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)8 PrestoException (com.facebook.presto.spi.PrestoException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 Set (java.util.Set)1 UUID (java.util.UUID)1 RedisNetwork (me.itsmas.network.server.network.redis.RedisNetwork)1 BungeeForwardEvent (org.anhcraft.spaciouslib.events.BungeeForwardEvent)1 InputSplit (org.apache.hadoop.mapred.InputSplit)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1