public final class Tools extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Tools.LogUncaughtExceptionHandler |
Modifier and Type | Field and Description |
---|---|
static String |
ES_DATE_FORMAT |
static org.joda.time.format.DateTimeFormatter |
ES_DATE_FORMAT_FORMATTER |
static String |
ES_DATE_FORMAT_NO_MS |
static org.joda.time.format.DateTimeFormatter |
ISO_DATE_FORMAT_FORMATTER |
Modifier and Type | Method and Description |
---|---|
static <T extends Comparable<? super T>> |
asSortedSet(Collection<T> c) |
static String |
buildElasticSearchTimeFormat(org.joda.time.DateTime timestamp) |
static String |
bytesToHex(byte[] a) |
static org.joda.time.DateTime |
dateTimeFromDouble(double x)
The double representation of a UNIX timestamp with milliseconds is a strange, human readable format.
|
static org.joda.time.DateTime |
dateTimeFromString(String s)
Parse the string representation of an ISO 8601 date/timestamp with milliseconds and timezone.
|
static String |
decodeBase64(String what) |
static String |
decompressGzip(byte[] compressedData)
Decompress GZIP (RFC 1952) compressed data
|
static String |
decompressGzip(byte[] compressedData,
long maxBytes)
Decompress GZIP (RFC 1952) compressed data
|
static String |
decompressZlib(byte[] compressedData)
Decompress ZLIB (RFC 1950) compressed data
|
static String |
decompressZlib(byte[] compressedData,
long maxBytes)
Decompress ZLIB (RFC 1950) compressed data
|
static String |
elasticSearchTimeFormatToISO8601(String time)
Try to parse a date in ES_DATE_FORMAT format considering it is in UTC and convert it to an ISO8601 date.
|
static String |
encodeBase64(String what) |
static Optional<AbsoluteRange> |
extractHistogramBoundaries(String query) |
static String |
generateServerId() |
static Double |
getDouble(Object x)
Convert something to a double in a fast way having a good guess
that it is a double.
|
static String |
getISO8601String(org.joda.time.DateTime time) |
static <T,E> T |
getKeyByValue(Map<T,E> map,
E value) |
static String |
getLocalCanonicalHostname() |
static String |
getLocalHostname() |
static Number |
getNumber(Object o,
Number defaultValue) |
static String |
getPID()
Get the own PID of this process.
|
static String |
getSystemInformation()
Get a String containing version information of JRE, OS, ...
|
static int |
getTimestampDaysAgo(int ts,
int days) |
static URI |
getUriWithDefaultPath(URI uri,
String path) |
static URI |
getUriWithPort(URI uri,
int port) |
static URI |
getUriWithScheme(URI uri,
String scheme) |
static int |
getUTCTimestamp() |
static double |
getUTCTimestampWithMilliseconds()
Get the current UNIX epoch with milliseconds of the system
|
static double |
getUTCTimestampWithMilliseconds(long timestamp)
Get the UNIX epoch with milliseconds of the provided millisecond timestamp
|
static InetAddress |
guessPrimaryNetworkAddress(boolean preferIPv4)
Try to get the primary
InetAddress of the primary network interface with
fallback to the local loopback address (usually 127.0.0.1 or ::1 . |
static org.joda.time.DateTime |
iso8601()
Deprecated.
Use
nowUTC() instead. |
static boolean |
isWildcardInetAddress(InetAddress inetAddress) |
static URI |
normalizeURI(URI uri,
String scheme,
int port,
String path) |
static org.joda.time.DateTime |
nowUTC() |
static String |
rdnsLookup(InetAddress socketAddress) |
static String |
safeSubstring(String target,
int start,
int end) |
static void |
silenceUncaughtExceptionsInThisThread()
The default uncaught exception handler will print to STDERR, which we don't always want for threads.
|
static String |
syslogFacilityToReadable(int facility)
Converts integer syslog facility to human readable string
|
static String |
syslogLevelToReadable(int level)
Converts integer syslog loglevel to human readable string
|
static org.joda.time.format.DateTimeFormatter |
timeFormatterWithOptionalMilliseconds()
Accepts our ElasticSearch time formats without milliseconds.
|
static URI |
uriWithTrailingSlash(URI uri) |
public static final String ES_DATE_FORMAT
public static final String ES_DATE_FORMAT_NO_MS
public static final org.joda.time.format.DateTimeFormatter ES_DATE_FORMAT_FORMATTER
public static final org.joda.time.format.DateTimeFormatter ISO_DATE_FORMAT_FORMATTER
public static String getPID()
public static String syslogLevelToReadable(int level)
level
- The level to convertpublic static String syslogFacilityToReadable(int facility)
facility
- The facility to convertpublic static String getSystemInformation()
public static String decompressZlib(byte[] compressedData) throws IOException
compressedData
- A byte array containing the ZLIB-compressed data.IOException
public static String decompressZlib(byte[] compressedData, long maxBytes) throws IOException
compressedData
- A byte array containing the ZLIB-compressed data.maxBytes
- The maximum number of uncompressed bytes to read.IOException
public static String decompressGzip(byte[] compressedData) throws IOException
compressedData
- A byte array containing the GZIP-compressed data.IOException
public static String decompressGzip(byte[] compressedData, long maxBytes) throws IOException
compressedData
- A byte array containing the GZIP-compressed data.maxBytes
- The maximum number of uncompressed bytes to read.IOException
public static int getUTCTimestamp()
public static double getUTCTimestampWithMilliseconds()
public static double getUTCTimestampWithMilliseconds(long timestamp)
timestamp
- a millisecond timestamp (milliseconds since UNIX epoch)public static String getLocalHostname()
public static String getLocalCanonicalHostname()
public static int getTimestampDaysAgo(int ts, int days)
public static String rdnsLookup(InetAddress socketAddress) throws UnknownHostException
UnknownHostException
public static String generateServerId()
public static <T extends Comparable<? super T>> SortedSet<T> asSortedSet(Collection<T> c)
public static String buildElasticSearchTimeFormat(org.joda.time.DateTime timestamp)
public static org.joda.time.DateTime dateTimeFromDouble(double x)
public static org.joda.time.DateTime dateTimeFromString(String s)
public static org.joda.time.format.DateTimeFormatter timeFormatterWithOptionalMilliseconds()
public static org.joda.time.DateTime nowUTC()
@Deprecated public static org.joda.time.DateTime iso8601()
nowUTC()
instead.public static String getISO8601String(org.joda.time.DateTime time)
public static String elasticSearchTimeFormatToISO8601(String time)
public static String safeSubstring(String target, int start, int end)
target
- String to cut.start
- Character position to start cutting at. Inclusive.end
- Character position to stop cutting at. Exclusive!public static Double getDouble(Object x)
x
- The object to convert to a doublepublic static InetAddress guessPrimaryNetworkAddress(boolean preferIPv4) throws SocketException
InetAddress
of the primary network interface with
fallback to the local loopback address (usually 127.0.0.1
or ::1
.InetAddress
of the primary network interface
or the loopback address as fallback.SocketException
- if the list of network interfaces couldn't be retrievedpublic static boolean isWildcardInetAddress(@Nullable InetAddress inetAddress)
@Nullable public static URI getUriWithDefaultPath(@Nullable URI uri, String path)
@Nullable public static URI normalizeURI(@Nullable URI uri, String scheme, int port, String path)
public static String bytesToHex(byte[] a)
public static void silenceUncaughtExceptionsInThisThread()
public static Optional<AbsoluteRange> extractHistogramBoundaries(String query)
Copyright © 2012–2020 Graylog, Inc.. All rights reserved.