/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
public void testNewDataInput_BAIS() { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {0x12, 0x34, 0x56, 0x78}); ByteArrayDataInput in = ByteStreams.newDataInput(bais); assertEquals(0x12345678, in.readInt()); }
public void testNewDataInput_empty() { byte[] b = new byte[0]; ByteArrayDataInput in = ByteStreams.newDataInput(b); try { in.readInt(); fail("expected exception"); } catch (IllegalStateException expected) { } }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
/** * Returns an integer representing an IPv4 address regardless of whether the supplied argument is * an IPv4 address or not. * * <p>IPv6 addresses are <b>coerced</b> to IPv4 addresses before being converted to integers. * * <p>As long as there are applications that assume that all IP addresses are IPv4 addresses and * can therefore be converted safely to integers (for whatever purpose) this function can be used * to handle IPv6 addresses as well until the application is suitably fixed. * * <p>NOTE: an IPv6 address coerced to an IPv4 address can only be used for such purposes as * rudimentary identification or indexing into a collection of real {@link InetAddress}es. They * cannot be used as real addresses for the purposes of network communication. * * @param ip {@link InetAddress} to convert * @return {@code int}, "coerced" if ip is not an IPv4 address * @since 7.0 */ public static int coerceToInteger(InetAddress ip) { return ByteStreams.newDataInput(getCoercedIPv4Address(ip).getAddress()).readInt(); }
@Override public int readInt() { int result = in.readInt(); available -= INT_LENGTH; return result; }
@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; } }
@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; } }
@Override public boolean acceptResponse(Player receiver, ByteArrayDataInput in) { in.readUTF(); int count = in.readInt(); this.callback.supply(count); return true; } }
@Override public boolean acceptResponse(Player receiver, ByteArrayDataInput in) { in.readUTF(); int count = in.readInt(); this.callback.supply(count); return true; } }
@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; } }
@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; } }
@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); }
@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()); }
public void testNewDataInput_BAIS() { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {0x12, 0x34, 0x56, 0x78}); ByteArrayDataInput in = ByteStreams.newDataInput(bais); assertEquals(0x12345678, in.readInt()); }
public void testNewDataInput_empty() { byte[] b = new byte[0]; ByteArrayDataInput in = ByteStreams.newDataInput(b); try { in.readInt(); fail("expected exception"); } catch (IllegalStateException expected) { } }