Class PGbytea


  • public class PGbytea
    extends java.lang.Object
    Converts to and from the postgresql bytea datatype used by the backend.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int[] HEX_VALS
      Lookup table for each of the valid ascii code points (offset by '0') to the 4 bit numeric value.
      private static int MAX_3_BUFF_SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      PGbytea()  
    • Field Detail

      • HEX_VALS

        private static final int[] HEX_VALS
        Lookup table for each of the valid ascii code points (offset by '0') to the 4 bit numeric value.
    • Constructor Detail

      • PGbytea

        public PGbytea()
    • Method Detail

      • toBytes

        public static byte[] toBytes​(byte[] s)
                              throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • toBytesHexEscaped

        private static byte[] toBytesHexEscaped​(byte[] s)
      • getHex

        private static int getHex​(byte b)
      • toBytesOctalEscaped

        private static byte[] toBytesOctalEscaped​(byte[] s)
      • toPGString

        public static java.lang.String toPGString​(byte[] buf)
      • appendHexString

        public static void appendHexString​(java.lang.StringBuilder sb,
                                           byte[] buf,
                                           int offset,
                                           int length)
        Appends given byte array as hex string. See HexEncodingBenchmark for the benchmark.
        Parameters:
        sb - output builder
        buf - buffer to append
        offset - offset within the buffer
        length - the length of sequence to append
      • toPGLiteral

        @Deprecated
        public static java.lang.String toPGLiteral​(java.lang.Object value)
                                            throws java.io.IOException
        Deprecated.
        prefer toPGLiteral(Object, SqlSerializationContext) to clarify the behaviour regarding InputStream objects
        Formats input object as bytea literal like '\xcafebabe'::bytea. The following inputs are supported: byte[], StreamWrapper, and ByteStreamWriter.
        Parameters:
        value - input value to format
        Returns:
        formatted value
        Throws:
        java.io.IOException - in case there's underflow in the input value
      • toPGLiteral

        public static java.lang.String toPGLiteral​(java.lang.Object value,
                                                   SqlSerializationContext context)
                                            throws java.io.IOException
        Formats input object as bytea literal like '\xcafebabe'::bytea. The following inputs are supported: byte[], StreamWrapper, and ByteStreamWriter.
        Parameters:
        value - input value to format
        context - specifies configuration for converting the parameters to string
        Returns:
        formatted value
        Throws:
        java.io.IOException - in case there's underflow in the input value