Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.core.format;
  
  import java.io.*;
  
Interface used to expose beginning of a data file to data format detection code.
 
 public interface InputAccessor
 {
    
Method to call to check if more input is available. Since this may result in more content to be read (at least one more byte), a java.io.IOException may get thrown.
 
     boolean hasMoreBytes() throws IOException;

    
Returns next byte available, if any; if no more bytes are available, will throw java.io.EOFException.
 
     byte nextByte() throws IOException;

    
Method that can be called to reset accessor to read from beginning of input.
 
     void reset();
 
     /*
     /**********************************************************
     /* Standard implementation
     /**********************************************************
      */

    
Basic implementation that reads data from given java.io.InputStream and buffers it as necessary.
 
     class Std implements InputAccessor
     {
         protected final InputStream _in;
 
         protected final byte[] _buffer;
 
         protected final int _bufferedStart;

        
End of valid bytes in the buffer (points to one past last valid)
 
         protected int _bufferedEnd;
        
        
Pointer to next available buffered byte in _buffer.
 
         protected int _ptr;
        
        
Constructor used when content to check is available via input stream and must be read.
 
         public Std(InputStream inbyte[] buffer)
         {
              = in;
              = buffer;
              = 0;
              = 0;
              = 0;
         }

        
Constructor used when the full input (or at least enough leading bytes of full input) is available.
 
         public Std(byte[] inputDocument)
         {
              = null;
              = inputDocument;
             // we have it all:
              = 0;
              = inputDocument.length;
         }

        
Constructor used when the full input (or at least enough leading bytes of full input) is available.

Since:
2.1
 
         public Std(byte[] inputDocumentint startint len)
         {
              = null;
              = inputDocument;
              = start;
              = start;
              = start+len;
         }
        
//      @Override
        public boolean hasMoreBytes() throws IOException
        {
            if ( < ) { // already got more
                return true;
            }
            if ( == null) { // nowhere to read from
                return false;
            }
            int amount = . - ;
            if (amount < 1) { // can not load any more
                return false;
            }
            int count = .read(amount);
            if (count <= 0) { // EOF
                return false;
            }
             += count;
            return true;
        }
//      @Override
        public byte nextByte() throws IOException
        {
            // should we just try loading more automatically?
            if ( >= ) {
                if (!hasMoreBytes()) {
                    throw new EOFException("Failed auto-detect: could not read more than "++" bytes (max buffer size: "+.+")");
                }
            }
            return [++];
        }
//      @Override
        public void reset() {
             = ;
        }
        /*
        /**********************************************************
        /* Extended API for DataFormatDetector/Matcher
        /**********************************************************
         */
        public DataFormatMatcher createMatcher(JsonFactory matchMatchStrength matchStrength)
        {
            return new DataFormatMatcher(, ( - ),
                    matchmatchStrength);
        }
    }
New to GrepCode? Check out our FAQ X