public class Util extends Object
| Modifier and Type | Method and Description |
|---|---|
static long |
addressToLong(InetAddress address)
Converts the bytes that make up an internet address into the corresponding integer value to make
it easier to perform bit-masking operations on them.
|
static long |
bytesToNumber(byte[] buffer,
int start,
int length)
Reconstructs a number that is represented by more than one byte in a network packet in big-endian order.
|
static double |
pitchToMultiplier(long pitch)
Convert a pitch value reported by a device to the corresponding multiplier (0.0 to 2.0, where normal, unadjusted
pitch has the multiplier 1.0).
|
static double |
pitchToPercentage(long pitch)
Convert a pitch value reported by a device to the corresponding percentage (-100% to +100%, where normal,
unadjusted pitch has the value 0%).
|
static boolean |
sameNetwork(int prefixLength,
InetAddress address1,
InetAddress address2)
Checks whether two internet addresses are on the same subnet.
|
static int |
unsign(byte b)
Converts a signed byte to its unsigned int equivalent in the range 0-255.
|
static boolean |
validateHeader(DatagramPacket packet,
int kind,
String name)
Check to see whether a packet starts with the standard header bytes, followed by a byte identifying it as the
kind of packet that is expected.
|
public static boolean validateHeader(DatagramPacket packet, int kind, String name)
packet - a packet that has just been receivedkind - the expected value of the eleventh byte, which seems to identify the packet typename - the name of the kind of packet expected, for use in logging warnings if a mismatch is foundtrue if the packet has the right headerpublic static int unsign(byte b)
b - a byte value to be considered an unsigned integerpublic static long bytesToNumber(byte[] buffer,
int start,
int length)
buffer - the byte array containing the packet datastart - the index of the first byte containing a numeric valuelength - the number of bytes making up the valuepublic static long addressToLong(InetAddress address)
address - an address whose integer equivalent is desiredpublic static boolean sameNetwork(int prefixLength,
InetAddress address1,
InetAddress address2)
prefixLength - the number of bits within an address that identify the networkaddress1 - the first address to be comparedaddress2 - the second address to be comparedpublic static double pitchToPercentage(long pitch)
pitch - the reported device pitchpublic static double pitchToMultiplier(long pitch)
pitch - the reported device pitchCopyright © 2016 Deep Symmetry, LLC. All rights reserved.