Class RabbitMQUtils

java.lang.Object
org.hobbit.core.rabbit.RabbitMQUtils

public class RabbitMQUtils extends Object
Contains utility methods for working with RabbitMQ.
Author:
Michael Röder (roeder@informatik.uni-leipzig.de)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.apache.jena.riot.Lang
     
    private static final org.slf4j.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Reads a byte array from the given buffer assuming that it is preceded by an int value containing the length of the byte array.
    static long
    readLong(byte[] data)
    Reads a long value from the given byte array.
    static long
    readLong(byte[] data, int offset, int length)
    Reads a long value from the given byte array.
    static org.apache.jena.rdf.model.Model
    readModel(byte[] data)
    Reads an RDF model from the given byte array.
    static org.apache.jena.rdf.model.Model
    readModel(byte[] data, int offset, int length)
    Reads an RDF model from the given byte array.
    static org.apache.jena.rdf.model.Model
    readModel(String string)
    Reads an RDF model from the given String.
    static org.apache.jena.rdf.model.Model
    Reads an RDF model from the given byte buffer assuming that the byte array containing the model is preceded by an int containing its length.
    static String
    readString(byte[] data)
    Transforms the given byte data into a String using the UTF-8 encoding.
    static String
    readString(byte[] data, int offset, int length)
    Transforms the given byte data into a String using the UTF-8 encoding.
    static String
    Reads a String from the given buffer assuming that it is preceded by an int value containing the length of the String.
    static byte[]
    writeByteArrays(byte[][] arrays)
    writes the given byte arrays and puts their length in front of them.
    static byte[]
    writeByteArrays(byte[] precedingData, byte[][] arrays, byte[] subsequentData)
    writes the given byte arrays and puts their length in front of them.
    static byte[]
    writeLong(long value)
    Creates a byte array representing the given long value.
    static byte[]
    writeModel(org.apache.jena.rdf.model.Model model)
    Creates a byte array containing the serialized RDF model using the DEFAULT_RDF_LANG.
    static String
    writeModel2String(org.apache.jena.rdf.model.Model model)
    Creates a String containing the serialized RDF model using the DEFAULT_RDF_LANG.
    static byte[]
    Creates a byte array representation of the given String using UTF-8 encoding.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • DEFAULT_RDF_LANG

      public static final org.apache.jena.riot.Lang DEFAULT_RDF_LANG
  • Constructor Details

    • RabbitMQUtils

      public RabbitMQUtils()
  • Method Details

    • readByteArray

      public static byte[] readByteArray(ByteBuffer buffer)
      Reads a byte array from the given buffer assuming that it is preceded by an int value containing the length of the byte array.
      Parameters:
      buffer - the buffer containing an int containing the length of the byte array followed by the byte array itself
      Returns:
      the byte array or null if the given byte array is null
    • readModel

      public static org.apache.jena.rdf.model.Model readModel(byte[] data)
      Reads an RDF model from the given byte array.
      Parameters:
      data - the byte array containing the serialized RDF model
      Returns:
      the deserialized model
    • readModel

      public static org.apache.jena.rdf.model.Model readModel(byte[] data, int offset, int length)
      Reads an RDF model from the given byte array.
      Parameters:
      data - the byte array containing the serialized RDF model
      offset - position at which the parsing will start
      length - number of bytes that should be parsed
      Returns:
      the deserialized model
    • readModel

      public static org.apache.jena.rdf.model.Model readModel(String string)
      Reads an RDF model from the given String.
      Parameters:
      string - the String containing the serialized RDF model
      Returns:
      the deserialized model
    • readModel

      public static org.apache.jena.rdf.model.Model readModel(ByteBuffer buffer)
      Reads an RDF model from the given byte buffer assuming that the byte array containing the model is preceded by an int containing its length.
      Parameters:
      buffer - the buffer containing the length of the serialized model (as int) and the byte array containing the serialized model
      Returns:
      the deserialized model
    • readString

      public static String readString(byte[] data)
      Transforms the given byte data into a String using the UTF-8 encoding.
      Parameters:
      data - the byte array that should be transformed
      Returns:
      the String or null if the given byte array is null
    • readString

      public static String readString(byte[] data, int offset, int length)
      Transforms the given byte data into a String using the UTF-8 encoding.
      Parameters:
      data - the byte array that should be transformed
      offset - position at which the parsing will start
      length - number of bytes that should be parsed
      Returns:
      the String or null if the given byte array is null
    • readString

      public static String readString(ByteBuffer buffer)
      Reads a String from the given buffer assuming that it is preceded by an int value containing the length of the String.
      Parameters:
      buffer - the buffer that contains the byte data of the String
      Returns:
      the String or null if the given buffer is null
    • writeByteArrays

      public static byte[] writeByteArrays(byte[][] arrays)
      writes the given byte arrays and puts their length in front of them. Thus, they can be read using a ByteBuffer and the readByteArray(ByteBuffer) method.
      Parameters:
      arrays - arrays that should be written to a single array
      Returns:
      the byte array containing all given arrays and their lengths
    • writeByteArrays

      public static byte[] writeByteArrays(byte[] precedingData, byte[][] arrays, byte[] subsequentData)
      writes the given byte arrays and puts their length in front of them. Thus, they can be read using a ByteBuffer and the readByteArray(ByteBuffer) method.
      Parameters:
      precedingData - data that should be written before the arrays are written. Note that this data is not preceded with the byte array length.
      arrays - arrays that should be written to a single array
      subsequentData - data that should be written after the arrays are written. Note that this data is not preceded with the byte array length.
      Returns:
      the byte array containing all given arrays and their lengths
    • writeString

      public static byte[] writeString(String string)
      Creates a byte array representation of the given String using UTF-8 encoding.
      Parameters:
      string - the String that should be transformed into a byte array
      Returns:
      the UTF-8 byte array of the given String
    • writeModel2String

      public static String writeModel2String(org.apache.jena.rdf.model.Model model)
      Creates a String containing the serialized RDF model using the DEFAULT_RDF_LANG.
      Parameters:
      model - the model that should be serialized
      Returns:
      the String containing the model
    • writeModel

      public static byte[] writeModel(org.apache.jena.rdf.model.Model model)
      Creates a byte array containing the serialized RDF model using the DEFAULT_RDF_LANG.
      Parameters:
      model - the model that should be serialized
      Returns:
      the byte array containing the model
    • writeLong

      public static byte[] writeLong(long value)
      Creates a byte array representing the given long value.
      Parameters:
      value - the value that should be serialized
      Returns:
      the byte array containing the given long value
    • readLong

      public static long readLong(byte[] data)
      Reads a long value from the given byte array.
      Parameters:
      data - a serialized long value
      Returns:
      the value read from the array
    • readLong

      public static long readLong(byte[] data, int offset, int length)
      Reads a long value from the given byte array.
      Parameters:
      data - a serialized long value
      offset - position at which the parsing will start
      length - number of bytes that should be parsed (should equal Long.BYTES)
      Returns:
      the value read from the array