Class ExpandableMarshalledValueByteStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable, org.jboss.marshalling.ByteOutput

    public final class ExpandableMarshalledValueByteStream
    extends MarshalledValueByteStream
    A byte stream that can be written to and expanded on the fly, not dissimilar to ExposedByteArrayOutputStream but with the benefit of not having to allocate unnecessary byte arrays by not extending ByteArrayOutputStream.
    Since:
    5.1
    Author:
    Manik Surtani
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_DOUBLING_SIZE
      Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object thatObject)  
      int getMaxDoublingSize()
      Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%.
      int getNewBufferSize​(int curSize, int minNewSize)
      Gets the number of bytes to which the internal buffer should be resized.
      byte[] getRaw()
      Gets the internal buffer array.
      int hashCode()  
      int size()
      Overriden only to avoid unneeded synchronization
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream, write
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.jboss.marshalling.ByteOutput

        write
      • Methods inherited from interface java.io.Closeable

        close
      • Methods inherited from interface java.io.Flushable

        flush
    • Field Detail

      • DEFAULT_DOUBLING_SIZE

        public static final int DEFAULT_DOUBLING_SIZE
        Default buffer size after which if more buffer capacity is needed the buffer will grow by 25% rather than 100%
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExpandableMarshalledValueByteStream

        public ExpandableMarshalledValueByteStream()
      • ExpandableMarshalledValueByteStream

        public ExpandableMarshalledValueByteStream​(int size)
      • ExpandableMarshalledValueByteStream

        public ExpandableMarshalledValueByteStream​(int size,
                                                   int maxDoublingSize)
        Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
        Parameters:
        size - the initial size.
        maxDoublingSize - the buffer size, after which if more capacity is needed the buffer will grow by 25% rather than 100%
        Throws:
        java.lang.IllegalArgumentException - if size is negative.
    • Method Detail

      • getRaw

        public final byte[] getRaw()
        Gets the internal buffer array. Note that the length of this array will almost certainly be longer than the data written to it; call size() to get the number of bytes of actual data.
        Specified by:
        getRaw in class MarshalledValueByteStream
      • write

        public final void write​(byte[] b,
                                int off,
                                int len)
        Specified by:
        write in interface org.jboss.marshalling.ByteOutput
        Overrides:
        write in class java.io.OutputStream
      • write

        public final void write​(int b)
        Specified by:
        write in interface org.jboss.marshalling.ByteOutput
        Specified by:
        write in class java.io.OutputStream
      • getMaxDoublingSize

        public final int getMaxDoublingSize()
        Gets the highest internal buffer size after which if more capacity is needed the buffer will grow in 25% increments rather than 100%.
      • getNewBufferSize

        public final int getNewBufferSize​(int curSize,
                                          int minNewSize)
        Gets the number of bytes to which the internal buffer should be resized.
        Parameters:
        curSize - the current number of bytes
        minNewSize - the minimum number of bytes required
        Returns:
        the size to which the internal buffer should be resized
      • equals

        public boolean equals​(java.lang.Object thatObject)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object