uk.ac.starlink.fits

## Class StringEncoder

- java.lang.Object
- - uk.ac.starlink.fits.StringEncoder

-     public abstract class StringEncoder
      extends java.lang.Object

  Serializes String values to byte arrays suitable for output into FITS table columns.
  Since:
    20 Mar 2026

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static StringEncoder` | `DEFAULT` Default instance.
    `static StringEncoder` | `SQUASH_TO_ASCII` Writes one byte per code point; non-ASCII code points are represented by a replacement character.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `StringEncoder(java.lang.String name)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract int` | `copyToBytes(java.lang.String txt, byte[] buf)` Encodes the given string into an existing byte array.
    `abstract byte[]` | `toBytes(java.lang.String txt)` Encodes the given string into a new byte array.
    `java.lang.String` | `toString()`

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

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

- - ### Field Detail

    - #### SQUASH_TO_ASCII

          public static final StringEncoder SQUASH_TO_ASCII

      Writes one byte per code point; non-ASCII code points are represented by a replacement character.

    - #### DEFAULT

          public static final StringEncoder DEFAULT

      Default instance.

  - ### Constructor Detail

    - #### StringEncoder

          protected StringEncoder(java.lang.String name)

      Constructor.
      Parameters:
        `name` - encoder name

  - ### Method Detail

    - #### toBytes

          public abstract byte[] toBytes(java.lang.String txt)

      Encodes the given string into a new byte array.
      Parameters:
        `txt` - string to encode, not null
      Returns:
        new array containing encoded text

    - #### copyToBytes

          public abstract int copyToBytes(java.lang.String txt,
                                          byte[] buf)

      Encodes the given string into an existing byte array. The encoding will be truncated if the supplied buffer is too short.
      Parameters:
        `txt` - string to encode, not null
        `buf` - buffer to receive encoded text
      Returns:
        number of bytes written to buffer

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`