public class Utils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Utils.Stringifier<T>
Define to
String conversion for various types. |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
appendBuffers(ByteBuffer buffer,
ByteBuffer buffer1,
int incomingBufferSize,
int BUFFER_STEP_SIZE)
Concatenates two buffers into one.
|
static <T> void |
checkNotNull(T reference,
String parameterName)
Check for null.
|
static <T> String |
getHeaderFromList(List<T> list)
Creates single
String value from provided List by calling Object.toString() on each item
and separating existing ones with ", " . |
static <T> String |
getHeaderFromList(List<T> list,
Utils.Stringifier<T> stringifier)
Convert list of values to singe
String usable as HTTP header value. |
static <T> T |
getProperty(Map<String,Object> properties,
String key,
Class<T> type)
Get typed property from generic property map.
|
static <T> T |
getProperty(Map<String,Object> properties,
String key,
Class<T> type,
T defaultValue)
Get typed property from generic property map.
|
static byte[] |
getRemainingArray(ByteBuffer buffer)
Creates the array of bytes containing the bytes from the position to the limit of the
ByteBuffer . |
static <T> List<String> |
getStringList(List<T> list,
Utils.Stringifier<T> stringifier)
Get list of strings from List<T>.
|
static int |
getWsPort(URI uri)
Get port from provided
URI . |
static int |
getWsPort(URI uri,
String scheme)
Get port from provided
URI . |
static List<String> |
parseHeaderValue(String headerValue)
Parse header value - splits multiple values (quoted, unquoted) separated by
comma.
|
static Date |
parseHttpDate(String stringValue)
Parse HTTP date.
|
static String |
stringifyUpgradeRequest(UpgradeRequest upgradeRequest)
Converts upgrade request to a HTTP-formatted string.
|
static String |
stringifyUpgradeResponse(UpgradeResponse upgradeResponse)
Converts upgrade response to a HTTP-formatted string.
|
static byte[] |
toArray(long value)
Convert
long to byte[] . |
static long |
toLong(byte[] bytes,
int start,
int end)
Convert
byte[] to long . |
static List<String> |
toString(byte[] bytes) |
static List<String> |
toString(byte[] bytes,
int start,
int end) |
public static List<String> parseHeaderValue(String headerValue)
headerValue
- string containing header values.public static byte[] getRemainingArray(ByteBuffer buffer)
ByteBuffer
.buffer
- where the bytes are taken from.ByteBuffer
.public static <T> String getHeaderFromList(List<T> list)
String
value from provided List by calling Object.toString()
on each item
and separating existing ones with ", "
.T
- item type.list
- to be serialized.String
containing all items from provided list.public static <T> List<String> getStringList(List<T> list, Utils.Stringifier<T> stringifier)
list
- list to be converted.stringifier
- strignifier used for conversion. When null
, Object.toString()
method will be
used.public static <T> String getHeaderFromList(List<T> list, Utils.Stringifier<T> stringifier)
String
usable as HTTP header value.list
- list of values.stringifier
- strignifier used for conversion. When null
, Object.toString()
method will be
used.public static <T> void checkNotNull(T reference, String parameterName)
IllegalArgumentException
if provided value is null.T
- object type.reference
- object to check.parameterName
- name of parameter to be formatted into localized message of thrown IllegalArgumentException
.public static byte[] toArray(long value)
long
to byte[]
.value
- to be converted.public static long toLong(byte[] bytes, int start, int end)
byte[]
to long
.bytes
- to be converted.start
- start index.end
- end index.public static ByteBuffer appendBuffers(ByteBuffer buffer, ByteBuffer buffer1, int incomingBufferSize, int BUFFER_STEP_SIZE)
buffer
- first buffer.buffer1
- second buffer.public static <T> T getProperty(Map<String,Object> properties, String key, Class<T> type)
properties
- property map.key
- key of value to be retrieved.type
- type of value to be retrieved.null
if property is not set or value is not assignable.public static <T> T getProperty(Map<String,Object> properties, String key, Class<T> type, T defaultValue)
properties
- property map.key
- key of value to be retrieved.type
- type of value to be retrieved.defaultValue
- value returned when record does not exist in supplied map.null
if property is not set or value is not assignable.public static int getWsPort(URI uri)
URI
.
Expected schemes are "ws"
and "wss"
and this method will return 80
or
443
when the port is not explicitly set in the provided URI
.uri
- provided uri.public static int getWsPort(URI uri, String scheme)
URI
.
Expected schemes are "ws"
and "wss"
and this method will return 80
or
443
when the port is not explicitly set in the provided URI
.uri
- provided uri.scheme
- scheme to be used when checking for "ws"
and "wss"
.public static Date parseHttpDate(String stringValue) throws ParseException
Sun, 06 Nov 1994 08:49:37 GMT
(RFC 822, updated by RFC 1123)Sunday, 06-Nov-94 08:49:37 GMT
(RFC 850, obsoleted by RFC 1036)Sun Nov 6 08:49:37 1994
(ANSI C's asctime() format)stringValue
- String value to be parsed.Date
parsed from the string.ParseException
- if the specified string cannot be parsed in neither of all three HTTP date formats.public static String stringifyUpgradeRequest(UpgradeRequest upgradeRequest)
upgradeRequest
- upgrade request to be formatted.public static String stringifyUpgradeResponse(UpgradeResponse upgradeResponse)
upgradeResponse
- upgrade request to be formatted.Copyright © 2012-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.