uk.ac.starlink.util

## Class Base64OutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - uk.ac.starlink.util.Base64OutputStream

- All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

      public class Base64OutputStream
      extends java.io.FilterOutputStream

  An output stream filter that takes arbitrary bytes and outputs their base64 encoding. Call `endBase64()` `close()` to write out the final padding. The class also automatically puts line breaks in the output stream.

  Minor modifications made for use in Starlink software: constructors now take OutputStream not PrintStream, assertion mechanism changed.

- - ### Field Summary

    - ### Fields inherited from class java.io.FilterOutputStream

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Base64OutputStream(java.io.OutputStream out)` Create a stream that does not insert line breaks.
    `Base64OutputStream(java.io.OutputStream out, int quadsPerLine)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` This invokes `endBase64()` and closes the next stream downstream.
    `void` | `endBase64()` Calling this will put the ending padding on the base64 stream, so don't call it until you have no data left.
    `void` | `write(byte[] buffer)`
    `void` | `write(byte[] buffer, int offset, int count)`
    `void` | `write(int oneByte)`

    - ### Methods inherited from class java.io.FilterOutputStream

      `flush`

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

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

- - ### Constructor Detail

    - #### Base64OutputStream

          public Base64OutputStream(java.io.OutputStream out)

      Create a stream that does not insert line breaks. To have line breaks, use the other constructor.

    - #### Base64OutputStream

          public Base64OutputStream(java.io.OutputStream out,
                                    int quadsPerLine)

      Parameters:
        `quadsPerLine` - Number of 4-character blocks to write before outputting a line break. For example, for 76-characters per line, pass in 76/4 = 19.

  - ### Method Detail

    - #### write

          public void write(int oneByte)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`

    - #### close

          public void close()
                     throws java.io.IOException

      This invokes `endBase64()` and closes the next stream downstream.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`

    - #### endBase64

          public void endBase64()
                         throws java.io.IOException

      Calling this will put the ending padding on the base64 stream, so don't call it until you have no data left. The class does no unnecessary buffering, so you probably shouldn't call it at all.
      Throws:
        `java.io.IOException`

    - #### write

          public void write(byte[] buffer)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`

    - #### write

          public void write(byte[] buffer,
                            int offset,
                            int count)
                     throws java.io.IOException

      Overrides:
        `write` in class `java.io.FilterOutputStream`
      Throws:
        `java.io.IOException`