org.apache.commons.compress.utils

## Class FixedLengthBlockOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - org.apache.commons.compress.utils.FixedLengthBlockOutputStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, Channel, WritableByteChannel

      public class FixedLengthBlockOutputStream
      extends OutputStream
      implements WritableByteChannel

  This class supports writing to an OutputStream or WritableByteChannel in fixed length blocks.

  It can be be used to support output to devices such as tape drives that require output in this format. If the final block does not have enough content to fill an entire block, the output will be padded to a full block size.

  This class can be used to support TAR,PAX, and CPIO blocked output to character special devices. It is not recommended that this class be used unless writing to such devices, as the padding serves no useful purpose in such cases.

  This class should normally wrap a FileOutputStream or associated WritableByteChannel directly. If there is an intervening filter that modified the output, such as a CompressorOutputStream, or performs its own buffering, such as BufferedOutputStream, output to the device may no longer be of the specified size.

  Any content written to this stream should be self-delimiting and should tolerate any padding added to fill the last block.

  Since:
    1.15

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FixedLengthBlockOutputStream(OutputStream os, int blockSize)` Create a fixed length block output stream with given destination stream and block size
    `FixedLengthBlockOutputStream(WritableByteChannel out, int blockSize)` Create a fixed length block output stream with given destination writable byte channel and block size

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `flushBlock()` Potentially pads and then writes the current block to the underlying stream.
    `boolean` | `isOpen()`
    `void` | `write(byte[] b, int offset, int length)`
    `int` | `write(ByteBuffer src)`
    `void` | `write(int b)`

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

      `flush, write`

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

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

- - ### Constructor Detail

    - #### FixedLengthBlockOutputStream

          public FixedLengthBlockOutputStream(OutputStream os,
                                              int blockSize)

      Create a fixed length block output stream with given destination stream and block size
      Parameters:
        `os` - The stream to wrap.
        `blockSize` - The block size to use.

    - #### FixedLengthBlockOutputStream

          public FixedLengthBlockOutputStream(WritableByteChannel out,
                                              int blockSize)

      Create a fixed length block output stream with given destination writable byte channel and block size
      Parameters:
        `out` - The writable byte channel to wrap.
        `blockSize` - The block size to use.

  - ### Method Detail

    - #### write

          public void write(int b)
                     throws IOException

      Specified by:
        `write` in class `OutputStream`
      Throws:
        `IOException`

    - #### write

          public void write(byte[] b,
                            int offset,
                            int length)
                     throws IOException

      Overrides:
        `write` in class `OutputStream`
      Throws:
        `IOException`

    - #### write

          public int write(ByteBuffer src)
                    throws IOException

      Specified by:
        `write` in interface `WritableByteChannel`
      Throws:
        `IOException`

    - #### isOpen

          public boolean isOpen()

      Specified by:
        `isOpen` in interface `Channel`

    - #### flushBlock

          public void flushBlock()
                          throws IOException

      Potentially pads and then writes the current block to the underlying stream.
      Throws:
        `IOException` - if writing fails

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Channel`
      Overrides:
        `close` in class `OutputStream`
      Throws:
        `IOException`

Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.