Refine search
/** * 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 the Teredo information embedded in a Teredo address. * * @param ip {@link Inet6Address} to be examined for embedded Teredo information * @return extracted {@code TeredoInfo} * @throws IllegalArgumentException if the argument is not a valid IPv6 Teredo address */ public static TeredoInfo getTeredoInfo(Inet6Address ip) { checkArgument(isTeredoAddress(ip), "Address '%s' is not a Teredo address.", toAddrString(ip)); byte[] bytes = ip.getAddress(); Inet4Address server = getInet4Address(Arrays.copyOfRange(bytes, 4, 8)); int flags = ByteStreams.newDataInput(bytes, 8).readShort() & 0xffff; // Teredo obfuscates the mapped client port, per section 4 of the RFC. int port = ~ByteStreams.newDataInput(bytes, 10).readShort() & 0xffff; byte[] clientBytes = Arrays.copyOfRange(bytes, 12, 16); for (int i = 0; i < clientBytes.length; i++) { // Teredo obfuscates the mapped client IP, per section 4 of the RFC. clientBytes[i] = (byte) ~clientBytes[i]; } Inet4Address client = getInet4Address(clientBytes); return new TeredoInfo(server, client, port, flags); }
public void testNewDataInput_readUTF() { byte[] data = new byte[17]; data[1] = 15; System.arraycopy("Kilroy was here".getBytes(Charsets.UTF_8), 0, data, 2, 15); ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals("Kilroy was here", in.readUTF()); }
ByteArrayDataInput in = ByteStreams.newDataInput(data); long timestamp = in.readLong(); String metric = readString(in); String type = getType(metric, aggs, i); byte metricNullability = in.readByte(); if (metricNullability == NullHandling.IS_NULL_BYTE) { event.put(metric, in.readFloat()); } else if ("long".equals(type)) { event.put(metric, WritableUtils.readVLong(in)); } else if ("double".equals(type)) { event.put(metric, in.readDouble()); } else { ComplexMetricSerde serde = getComplexMetricSerde(type);
private ClassPatch readPatch(JarEntry patchEntry, JarInputStream jis) throws IOException { log("\t%s", patchEntry.getName()); ByteArrayDataInput input = ByteStreams.newDataInput(ByteStreams.toByteArray(jis)); String name = input.readUTF(); String sourceClassName = input.readUTF(); String targetClassName = input.readUTF(); boolean exists = input.readBoolean(); int inputChecksum = 0; if (exists) { inputChecksum = input.readInt(); } int patchLength = input.readInt(); byte[] patchBytes = new byte[patchLength]; input.readFully(patchBytes); return new ClassPatch(name, sourceClassName, targetClassName, exists, inputChecksum, patchBytes); }
Key key = entry.getKey(); ByteArrayDataInput in = ByteStreams.newDataInput(entry.getValue().get()); Counters counters = new Counters(); try { in = ByteStreams.newDataInput(entry.getValue().get()); int numGroups = in.readInt(); while (numGroups-- > 0) { String groupName = Text.readString(in); String counterName = Text.readString(in); String counterDisplayName = counterName; if (in.readBoolean()) counterDisplayName = Text.readString(in); long value = WritableUtils.readVLong(in); ByteArrayDataOutput out = ByteStreams.newDataOutput(); counters.write(out); Mutation m = new Mutation(key.getRow());
in.readFully(b); available -= b.length; in.readFully(b, off, len); available -= len; int skipped = in.skipBytes(n); available -= skipped; return skipped; boolean result = in.readBoolean(); available--; return result; byte result = in.readByte(); available--; return result; int result = in.readUnsignedByte(); available--; return result; short result = in.readShort(); available -= 2; return result; int result = in.readUnsignedShort(); available -= 2; return result;
@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 } } }
public void testNewDataInput_readBoolean() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); assertTrue(in.readBoolean()); }
@Override protected void reduce(final Text key, final Iterable<LongWritable> values, final Context context) throws IOException, InterruptedException { long count = 0; for (final LongWritable lw : values) { count += lw.get(); } if (count <= TOO_LOW) { return; } final ByteArrayDataInput badi = ByteStreams.newDataInput(key.getBytes()); final String v = badi.readUTF(); cat_txt.set(badi.readUTF()); Text columnQualifier = RdfCloudTripleStoreConstants.EMPTY_TEXT; final boolean includesContext = badi.readBoolean(); if (includesContext) { columnQualifier = new Text(badi.readUTF()); } row.set(v); final Mutation m = new Mutation(row); v_out.set((count + "").getBytes(StandardCharsets.UTF_8)); m.put(cat_txt, columnQualifier, cv, v_out); context.write(table, m); }
public void testNewDataInput_readByte() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); for (int i = 0; i < bytes.length; i++) { assertEquals(bytes[i], in.readByte()); } try { in.readByte(); fail("expected exception"); } catch (IllegalStateException ex) { assertThat(ex).hasCauseThat().isInstanceOf(EOFException.class); } }
public void testNewDataInput_readLong() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals(0x1234567876543210L, in.readLong()); }
@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(); }
@Override public void readFrom(ByteArrayDataInput in) { playerName = in.readUTF(); }
@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 int readInt() { int result = in.readInt(); available -= INT_LENGTH; return result; }
@Override public void readFrom(ByteArrayDataInput input) { willEnable = input.readBoolean(); playerName = input.readUTF(); isSourceInvoker = input.readBoolean(); }
@Override public short readShort() { short result = in.readShort(); available -= 2; return result; }