PemWriter (Bouncy Castle Library 1.85 API Specification)
Date: 2026-07-12

org.bouncycastle.util.io.pem

## Class PemWriter

- java.lang.Object
- - java.io.Writer
  - - java.io.BufferedWriter
    - - org.bouncycastle.util.io.pem.PemWriter

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

      public class PemWriter
      extends java.io.BufferedWriter

  A generic PEM writer, based on RFC 1421

- - ### Field Summary

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

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PemWriter(java.io.Writer out)` Base constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getOutputSize(PemObject obj)` Return the number of bytes or characters required to contain the passed in object if it is PEM encoded.
    `void` | `writeObject(PemObjectGenerator objGen)`

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

      `close, flush, newLine, write, write, write`

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

      `append, append, append, write, write`

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

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

- - ### Constructor Detail

    - #### PemWriter

          public PemWriter(java.io.Writer out)

      Base constructor.
      Parameters:
        `out` - output stream to use.

  - ### Method Detail

    - #### getOutputSize

          public int getOutputSize(PemObject obj)

      Return the number of bytes or characters required to contain the passed in object if it is PEM encoded.
      Parameters:
        `obj` - pem object to be output
      Returns:
        an estimate of the number of bytes

    - #### writeObject

          public void writeObject(PemObjectGenerator objGen)
                           throws java.io.IOException

      Throws:
        `java.io.IOException`