Class FixedLengthBlockOutputStream.BufferAtATimeOutputChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.WritableByteChannel
    Enclosing class:
    FixedLengthBlockOutputStream

    private static class FixedLengthBlockOutputStream.BufferAtATimeOutputChannel
    extends java.lang.Object
    implements java.nio.channels.WritableByteChannel
    Helper class to provide channel wrapper for arbitrary output stream that doesn't alter the size of writes. We can't use Channels.newChannel, because for non FileOutputStreams, it breaks up writes into 8KB max chunks. Since the purpose of this class is to always write complete blocks, we need to write a simple class to take care of it.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicBoolean closed  
      private java.io.OutputStream out  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BufferAtATimeOutputChannel​(java.io.OutputStream out)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean isOpen()  
      int write​(java.nio.ByteBuffer buffer)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • out

        private final java.io.OutputStream out
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
    • Constructor Detail

      • BufferAtATimeOutputChannel

        private BufferAtATimeOutputChannel​(java.io.OutputStream out)
    • Method Detail

      • write

        public int write​(java.nio.ByteBuffer buffer)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Throws:
        java.io.IOException
      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException