kafka.utils

Utils

object Utils extends Logging

General helper functions!

This is for general helper functions that aren't specific to Kafka logic. Things that should have been included in the standard library etc.

If you are making a new helper function and want to add it to this class please ensure the following: 1. It has documentation 2. It is the most general possible utility, not just the thing you needed in one particular place 3. You have tests for it if it is nontrivial in any way

Linear Supertypes
Logging, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Utils
  2. Logging
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def abs(n: Int): Int

    Get the absolute value of the given number.

    Get the absolute value of the given number. If the number is Int.MinValue return 0. This is different from java.lang.Math.abs or scala.math.abs in that they return Int.MinValue (!).

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def circularIterator[T](coll: Iterable[T]): Iterator[T]

    Create a circular (looping) iterator over a collection.

    Create a circular (looping) iterator over a collection.

    coll

    An iterable over the underlying collection.

    returns

    A circular iterator over the collection.

  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. def crc32(bytes: Array[Byte], offset: Int, size: Int): Long

    Compute the CRC32 of the segment of the byte array given by the specificed size and offset

    Compute the CRC32 of the segment of the byte array given by the specificed size and offset

    bytes

    The bytes to checksum

    offset

    the offset at which to begin checksumming

    size

    the number of bytes to checksum

    returns

    The CRC32

  11. def crc32(bytes: Array[Byte]): Long

    Compute the CRC32 of the byte array

    Compute the CRC32 of the byte array

    bytes

    The array to compute the checksum for

    returns

    The CRC32

  12. def createObject[T <: AnyRef](className: String, args: AnyRef*): T

    Create an instance of the class with the given class name

  13. def croak(message: String): Unit

    Print an error message and shutdown the JVM

    Print an error message and shutdown the JVM

    message

    The error message

  14. def daemonThread(name: String, fun: () ⇒ Unit): Thread

    Create a daemon thread

    Create a daemon thread

    name

    The name of the thread

    fun

    The runction to execute in the thread

    returns

    The unstarted thread

  15. def daemonThread(name: String, runnable: Runnable): Thread

    Create a daemon thread

    Create a daemon thread

    name

    The name of the thread

    runnable

    The runnable to execute in the background

    returns

    The unstarted thread

  16. def daemonThread(runnable: Runnable): Thread

    Create a daemon thread

    Create a daemon thread

    runnable

    The runnable to execute in the background

    returns

    The unstarted thread

  17. def debug(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  18. def debug(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  19. def debug(msg: ⇒ String): Unit

    Definition Classes
    Logging
  20. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  21. def equal(b1: ByteBuffer, b2: ByteBuffer): Boolean

    Test if two byte buffers are equal.

    Test if two byte buffers are equal. In this case equality means having the same bytes from the current position to the limit

  22. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  23. def error(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  24. def error(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  25. def error(msg: ⇒ String): Unit

    Definition Classes
    Logging
  26. def fatal(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  27. def fatal(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  28. def fatal(msg: ⇒ String): Unit

    Definition Classes
    Logging
  29. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  30. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  31. def groupby[K, V](vals: Iterable[V], f: (V) ⇒ K): Map[K, List[V]]

    Group the given values by keys extracted with the given function

  32. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  33. def hashcode(as: Any*): Int

    Compute the hash code for the given items

  34. def inLock[T](lock: Lock)(fun: ⇒ T): T

    Execute the given function inside the lock

  35. def info(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  36. def info(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  37. def info(msg: ⇒ String): Unit

    Definition Classes
    Logging
  38. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  39. def loadProps(filename: String): Properties

    Read a properties file from the given path

    Read a properties file from the given path

    filename

    The path of the file to read

  40. var logIdent: String

    Attributes
    protected
    Definition Classes
    Logging
  41. def loggedRunnable(fun: () ⇒ Unit, name: String): Runnable

    Wrap the given function in a java.

    Wrap the given function in a java.lang.Runnable that logs any errors encountered

    fun

    A function

    returns

    A Runnable that just executes the function

  42. lazy val logger: Logger

    Definition Classes
    Logging
  43. val loggerName: String

    Definition Classes
    Logging
  44. def mapToJson(jsonDataMap: Map[String, String], valueInQuotes: Boolean): String

    Format a Map[String, String] as JSON object.

  45. def mapToJsonFields(jsonDataMap: Map[String, String], valueInQuotes: Boolean): Seq[String]

    Format a Map[String, String] as JSON object.

  46. def mapWithSeqValuesToJson(jsonDataMap: Map[String, Seq[Int]]): String

    Format a Map[String, Seq[Int]] as JSON

  47. def mergeJsonFields(objects: Seq[String]): String

    Merge JSON fields of the format "key" : value/object/array.

  48. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  49. def newThread(runnable: Runnable, daemon: Boolean): Thread

    Create a new thread

    Create a new thread

    runnable

    The work for the thread to do

    daemon

    Should the thread block JVM shutdown?

    returns

    The unstarted thread

  50. def newThread(name: String, runnable: Runnable, daemon: Boolean): Thread

    Create a new thread

    Create a new thread

    name

    The name of the thread

    runnable

    The work for the thread to do

    daemon

    Should the thread block JVM shutdown?

    returns

    The unstarted thread

  51. def notNull[V](v: V): V

    Throw an exception if the given value is null, else return it.

    Throw an exception if the given value is null, else return it. You can use this like: val myValue = Utils.notNull(expressionThatShouldntBeNull)

  52. final def notify(): Unit

    Definition Classes
    AnyRef
  53. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  54. def nullOrEmpty(s: String): Boolean

    Is the given string null or empty ("")?

  55. def openChannel(file: File, mutable: Boolean): FileChannel

    Open a channel for the given file

  56. def parseCsvList(csvList: String): Seq[String]

    Parse a comma separated string into a sequence of strings.

    Parse a comma separated string into a sequence of strings. Whitespace surrounding the comma will be removed.

  57. def parseCsvMap(str: String): Map[String, String]

    This method gets comma separated values which contains key,value pairs and returns a map of key value pairs.

    This method gets comma separated values which contains key,value pairs and returns a map of key value pairs. the format of allCSVal is key1:val1, key2:val2 ....

  58. def parseHostPort(hostport: String): (String, Int)

    Parse a host and port out of a string

  59. def read(channel: ReadableByteChannel, buffer: ByteBuffer): Int

    Read some bytes into the provided buffer, and return the number of bytes read.

    Read some bytes into the provided buffer, and return the number of bytes read. If the channel has been closed or we get -1 on the read for any reason, throw an EOFException

  60. def readBytes(buffer: ByteBuffer, offset: Int, size: Int): Array[Byte]

    Read a byte array from the given offset and size in the buffer

  61. def readBytes(buffer: ByteBuffer): Array[Byte]

    Read the given byte buffer into a byte array

  62. def readFileAsString(path: String, charset: Charset = Charset.defaultCharset()): String

    Attempt to read a file as a string

  63. def readString(buffer: ByteBuffer, encoding: String = Charset.defaultCharset.toString): String

    Translate the given buffer into a string

    Translate the given buffer into a string

    buffer

    The buffer to translate

    encoding

    The encoding to use in translating bytes to characters

  64. def readUnsignedInt(buffer: ByteBuffer, index: Int): Long

    Read an unsigned integer from the given position without modifying the buffers position

    Read an unsigned integer from the given position without modifying the buffers position

    buffer

    the buffer to read from

    index

    the index from which to read the integer

    returns

    The integer read, as a long to avoid signedness

  65. def readUnsignedInt(buffer: ByteBuffer): Long

    Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes

    Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes

    buffer

    The buffer to read from

    returns

    The integer read, as a long to avoid signedness

  66. def registerMBean(mbean: AnyRef, name: String): Boolean

    Register the given mbean with the platform mbean server, unregistering any mbean that was there before.

    Register the given mbean with the platform mbean server, unregistering any mbean that was there before. Note, this method will not throw an exception if the registration fails (since there is nothing you can do and it isn't fatal), instead it just returns false indicating the registration failed.

    mbean

    The object to register as an mbean

    name

    The name to register this mbean with

    returns

    true if the registration succeeded

  67. def rm(file: File): Unit

    Recursively delete the given file/directory and any subfiles (if any exist)

    Recursively delete the given file/directory and any subfiles (if any exist)

    file

    The root file at which to begin deleting

  68. def rm(files: Seq[String]): Unit

    Recursively delete the list of files/directories and any subfiles (if any exist)

  69. def rm(file: String): Unit

    Recursively delete the given file/directory and any subfiles (if any exist)

    Recursively delete the given file/directory and any subfiles (if any exist)

    file

    The root file at which to begin deleting

  70. def runnable(fun: () ⇒ Unit): Runnable

    Wrap the given function in a java.

    Wrap the given function in a java.lang.Runnable

    fun

    A function

    returns

    A Runnable that just executes the function

  71. def seqToJson(jsonData: Seq[String], valueInQuotes: Boolean): String

    Format a Seq[String] as JSON array.

  72. def stackTrace(e: Throwable): String

    Get the stack trace from an exception as a string

  73. def swallow(log: (AnyRef, Throwable) ⇒ Unit, action: ⇒ Unit): Unit

    Do the given action and log any exceptions thrown without rethrowing them

    Do the given action and log any exceptions thrown without rethrowing them

    log

    The log method to use for logging. E.g. logger.warn

    action

    The action to execute

  74. def swallow(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  75. def swallowDebug(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  76. def swallowError(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  77. def swallowInfo(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  78. def swallowTrace(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  79. def swallowWarn(action: ⇒ Unit): Unit

    Definition Classes
    Logging
  80. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  81. def toString(): String

    Definition Classes
    AnyRef → Any
  82. def trace(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  83. def trace(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  84. def trace(msg: ⇒ String): Unit

    Definition Classes
    Logging
  85. def unregisterMBean(name: String): Unit

    Unregister the mbean with the given name, if there is one registered

    Unregister the mbean with the given name, if there is one registered

    name

    The mbean name to unregister

  86. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  87. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  88. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  89. def warn(msg: ⇒ String, e: ⇒ Throwable): Unit

    Definition Classes
    Logging
  90. def warn(e: ⇒ Throwable): Any

    Definition Classes
    Logging
  91. def warn(msg: ⇒ String): Unit

    Definition Classes
    Logging
  92. def writeUnsignedInt(buffer: ByteBuffer, index: Int, value: Long): Unit

    Write the given long value as a 4 byte unsigned integer.

    Write the given long value as a 4 byte unsigned integer. Overflow is ignored.

    buffer

    The buffer to write to

    index

    The position in the buffer at which to begin writing

    value

    The value to write

  93. def writetUnsignedInt(buffer: ByteBuffer, value: Long): Unit

    Write the given long value as a 4 byte unsigned integer.

    Write the given long value as a 4 byte unsigned integer. Overflow is ignored.

    buffer

    The buffer to write to

    value

    The value to write

Inherited from Logging

Inherited from AnyRef

Inherited from Any

Ungrouped