Package org.postgresql.util

# Class PGbytea

java.lang.Object
org.postgresql.util.PGbytea

public class PGbytea extends Object
Converts to and from the postgresql bytea datatype used by the backend.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PGbytea()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `appendHexString(StringBuilder sb, byte[] buf, int offset, int length)`
  Appends given byte array as hex string.
  `static byte @PolyNull []`
  `toBytes(byte @PolyNull [] s)`
  `static String`
  `toPGLiteral(Object value)`
  Deprecated.
  prefer `toPGLiteral(Object, SqlSerializationContext)` to clarify the behaviour regarding `InputStream` objects
  `static String`
  `toPGLiteral(Object value, SqlSerializationContext context)`
  Formats input object as `bytea` literal like `'\xcafebabe'::bytea`.
  `static @PolyNull String`
  `toPGString(byte @PolyNull [] buf)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PGbytea

    public PGbytea()

- ## Method Details

  - ### toBytes

    public static byte @PolyNull [] toBytes(byte @PolyNull [] s) throws SQLException
    Throws:
      `SQLException`

  - ### toPGString

    public static @PolyNull String toPGString(byte @PolyNull [] buf)

  - ### appendHexString

    public static void appendHexString(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 String toPGLiteral(Object value) throws 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:
      `IOException` - in case there's underflow in the input value

  - ### toPGLiteral

    public static String toPGLiteral(Object value, SqlSerializationContext context) throws 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:
      `IOException` - in case there's underflow in the input value