Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package divconq.json3.io;
  
To limit number of configuration and state objects to pass, all contextual objects that need to be passed by the factory to readers and writers are combined under this object. One instance is created for each reader and writer.

NOTE: non-final since 2.4, to allow sub-classing.

 
 public class IOContext
 {
     /*
     /**********************************************************
     /* Configuration
     /**********************************************************
      */

    
Reference to the source object, which can be used for displaying location information
 
     protected final Object _sourceRef;

    
Encoding used by the underlying stream, if known.
 
     protected JsonEncoding _encoding;

    
Flag that indicates whether underlying input/output source/target object is fully managed by the owner of this context (parser or generator). If true, it is, and is to be closed by parser/generator; if false, calling application has to do closing (unless auto-closing feature is enabled for the parser/generator in question; in which case it acts like the owner).
 
     protected final boolean _managedResource;
 
     /*
     /**********************************************************
     /* Buffer handling, recycling
     /**********************************************************
      */

    
Recycler used for actual allocation/deallocation/reuse
 
     protected final BufferRecycler _bufferRecycler;

    
Reference to the allocated I/O buffer for low-level input reading, if any allocated.
 
     protected byte[] _readIOBuffer = null;

    
Reference to the allocated I/O buffer used for low-level encoding-related buffering.
 
     protected byte[] _writeEncodingBuffer = null;
    
    
Reference to the buffer allocated for temporary use with base64 encoding or decoding.
 
     protected byte[] _base64Buffer = null;

    
Reference to the buffer allocated for tokenization purposes, in which character input is read, and from which it can be further returned.
 
     protected char[] _tokenCBuffer = null;

    
Reference to the buffer allocated for buffering it for output, before being encoded: generally this means concatenating output, then encoding when buffer fills up.
 
     protected char[] _concatCBuffer = null;

    
Reference temporary buffer Parser instances need if calling app decides it wants to access name via 'getTextCharacters' method. Regular text buffer can not be used as it may contain textual representation of the value token.
 
     protected char[] _nameCopyBuffer = null;
 
     /*
     /**********************************************************
     /* Life-cycle
     /**********************************************************
      */
    public IOContext(BufferRecycler brObject sourceRefboolean managedResource)
    {
         = br;
         = sourceRef;
         = managedResource;
    }
    public void setEncoding(JsonEncoding enc) {
         = enc;
    }
    /*
    /**********************************************************
    /* Public API, accessors
    /**********************************************************
     */
    public Object getSourceReference() { return ; }
    public JsonEncoding getEncoding() { return ; }
    public boolean isResourceManaged() { return ; }
    /*
    /**********************************************************
    /* Public API, buffer management
    /**********************************************************
     */
    public TextBuffer constructTextBuffer() {
        return new TextBuffer();
    }
    /*
     *<p>
     * Note: the method can only be called once during its life cycle.
     * This is to protect against accidental sharing.
     */
    public byte[] allocReadIOBuffer() {
        _verifyAlloc();
    }
    /*
     * @since 2.4
     */
    public byte[] allocReadIOBuffer(int minSize) {
        _verifyAlloc();
    }
    
    public byte[] allocWriteEncodingBuffer() {
    }
    /*
     * @since 2.4
     */
    public byte[] allocWriteEncodingBuffer(int minSize) {
    }
    
    /*
     * @since 2.1
     */
    public byte[] allocBase64Buffer() {
        _verifyAlloc();
    }
    
    public char[] allocTokenBuffer() {
        _verifyAlloc();
    }
    /*
     * @since 2.4
     */
    public char[] allocTokenBuffer(int minSize) {
        _verifyAlloc();
    }
    
    public char[] allocConcatBuffer() {
    }
    public char[] allocNameCopyBuffer(int minSize) {
    }
    /*
     * Method to call when all the processing buffers can be safely
     * recycled.
     */
    public void releaseReadIOBuffer(byte[] buf) {
        if (buf != null) {
            /* Let's do sanity checks to ensure once-and-only-once release,
             * as well as avoiding trying to release buffers not owned
             */
            _verifyRelease(buf);
             = null;
        }
    }
    public void releaseWriteEncodingBuffer(byte[] buf) {
        if (buf != null) {
            /* Let's do sanity checks to ensure once-and-only-once release,
             * as well as avoiding trying to release buffers not owned
             */
            _verifyRelease(buf);
             = null;
        }
    }
    public void releaseBase64Buffer(byte[] buf) {
        if (buf != null) { // sanity checks, release once-and-only-once, must be one owned
            _verifyRelease(buf);
             = null;
        }
    }
    
    public void releaseTokenBuffer(char[] buf) {
        if (buf != null) {
            _verifyRelease(buf);
             = null;
        }
    }
    public void releaseConcatBuffer(char[] buf) {
        if (buf != null) {
            // 14-Jan-2014, tatu: Let's actually allow upgrade of the original buffer.
            _verifyRelease(buf);
             = null;
        }
    }
    public void releaseNameCopyBuffer(char[] buf) {
        if (buf != null) {
            // 14-Jan-2014, tatu: Let's actually allow upgrade of the original buffer.
            _verifyRelease(buf);
             = null;
        }
    }
    /*
    /**********************************************************
    /* Internal helpers
    /**********************************************************
     */
    protected final void _verifyAlloc(Object buffer) {
        if (buffer != null) { throw new IllegalStateException("Trying to call same allocXxx() method second time"); }
    }
    protected final void _verifyRelease(byte[] toReleasebyte[] src) {
        if ((toRelease != src) && (toRelease.length <= src.length)) { throw wrongBuf(); }
    }
    protected final void _verifyRelease(char[] toReleasechar[] src) {
        if ((toRelease != src) && (toRelease.length <= src.length)) { throw wrongBuf(); }
    }
    private IllegalArgumentException wrongBuf() { return new IllegalArgumentException("Trying to release buffer not owned by the context"); }
New to GrepCode? Check out our FAQ X