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 long |
bytesToNumberLittleEndian(byte[] buffer,
int start,
int length)
Reconstructs a number that is represented by more than one byte in a network packet in little-endian order, for
the very few protocol values that are sent in this quirky way.
|
static long |
halfFrameToTime(long halfFrame)
Figure out the track time that corresponds to a half-frame number (75 frames per second, so 150 half-frames).
|
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 |
timeToHalfFrame(long milliseconds)
Convert a track position (time) into the corresponding half-frame value (75 frames per second, so 150 half-frames).
|
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.
|
static void |
writeFully(ByteBuffer buffer,
WritableByteChannel channel)
Writes the entire remaining contents of the buffer to the channel.
|
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 bytesToNumberLittleEndian(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 pitchpublic static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException
buffer - the data to be writtenchannel - the channel to which we want to write dataIOException - if there is a problem writing to the channelpublic static long halfFrameToTime(long halfFrame)
halfFrame - the half-frame that we are interested in knowing the time forpublic static int timeToHalfFrame(long milliseconds)
milliseconds - how long a track has been playing forCopyright © 2016–2018 Deep Symmetry, LLC. All rights reserved.