Class C2BConverter


  • public class C2BConverter
    extends java.lang.Object
    Efficient conversion of character to bytes. Now uses NIO directly
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ByteChunk bb  
      protected java.lang.String enc  
      protected java.nio.charset.CharsetEncoder encoder  
    • Constructor Summary

      Constructors 
      Constructor Description
      C2BConverter​(java.lang.String encoding)
      Create a converter
      C2BConverter​(ByteChunk output, java.lang.String encoding)
      Create a converter, with bytes going to a byte buffer
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void convert​(char c)
      Generate the bytes using the specified encoding
      void convert​(char[] c, int off, int len)
      Generate the bytes using the specified encoding
      void convert​(java.lang.String s)
      Generate the bytes using the specified encoding
      void convert​(java.lang.String s, int off, int len)
      Generate the bytes using the specified encoding
      void convert​(MessageBytes mb)
      Convert a message bytes chars to bytes
      void flushBuffer()
      Flush any internal buffers into the ByteOutput or the internal byte[]
      ByteChunk getByteChunk()  
      java.lang.String getEncoding()  
      static C2BConverter getInstance​(ByteChunk output, java.lang.String encoding)  
      void recycle()
      Reset the internal state, empty the buffers.
      void setByteChunk​(ByteChunk bb)  
      • Methods inherited from class java.lang.Object

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

      • enc

        protected final java.lang.String enc
      • encoder

        protected final java.nio.charset.CharsetEncoder encoder
    • Constructor Detail

      • C2BConverter

        public C2BConverter​(ByteChunk output,
                            java.lang.String encoding)
                     throws java.io.IOException
        Create a converter, with bytes going to a byte buffer
        Throws:
        java.io.IOException
      • C2BConverter

        public C2BConverter​(java.lang.String encoding)
                     throws java.io.IOException
        Create a converter
        Throws:
        java.io.IOException
    • Method Detail

      • getInstance

        public static C2BConverter getInstance​(ByteChunk output,
                                               java.lang.String encoding)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getByteChunk

        public ByteChunk getByteChunk()
      • getEncoding

        public java.lang.String getEncoding()
      • setByteChunk

        public void setByteChunk​(ByteChunk bb)
      • recycle

        public void recycle()
        Reset the internal state, empty the buffers. The encoding remain in effect, the internal buffers remain allocated.
      • convert

        public void convert​(char[] c,
                            int off,
                            int len)
                     throws java.io.IOException
        Generate the bytes using the specified encoding
        Throws:
        java.io.IOException
      • convert

        public void convert​(java.lang.String s)
                     throws java.io.IOException
        Generate the bytes using the specified encoding
        Throws:
        java.io.IOException
      • convert

        public void convert​(java.lang.String s,
                            int off,
                            int len)
                     throws java.io.IOException
        Generate the bytes using the specified encoding
        Throws:
        java.io.IOException
      • convert

        public void convert​(char c)
                     throws java.io.IOException
        Generate the bytes using the specified encoding
        Throws:
        java.io.IOException
      • convert

        public void convert​(MessageBytes mb)
                     throws java.io.IOException
        Convert a message bytes chars to bytes
        Throws:
        java.io.IOException
      • flushBuffer

        public void flushBuffer()
                         throws java.io.IOException
        Flush any internal buffers into the ByteOutput or the internal byte[]
        Throws:
        java.io.IOException