Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.core.io;
  
  import java.io.*;

Simple java.io.InputStream implementation that is used to "unwind" some data previously read from an input stream; so that as long as some of that data remains, it's returned; but as long as it's read, we'll just use data from the underlying original stream. This is similar to java.io.PushbackInputStream, but here there's only one implicit pushback, when instance is constructed.
 
 public final class MergedStream
     extends InputStream
 {
     final protected IOContext _context;
 
     final InputStream _in;
 
     byte[] _buffer;
 
     int _ptr;
 
     final int _end;
 
     public MergedStream(IOContext context,
             InputStream inbyte[] bufint startint end)
     {
          = context;
          = in;
          = buf;
          = start;
          = end;
     }
 
     @Override
     public int available() throws IOException
     {
         if ( != null) {
             return  - ;
         }
         return .available();
     }
 
     @Override
     public void close() throws IOException
     {
         freeMergedBuffer();
         .close();
     }
 
     @Override
     public void mark(int readlimit)
     {
         if ( == null) {
             .mark(readlimit);
         }
     }
     
     @Override
     public boolean markSupported()
     {
         // Only supports marks past the initial rewindable section...
         return ( == null) && .markSupported();
     }
     
     @Override
     public int read() throws IOException
     {
         if ( != null) {
             int c = [++] & 0xFF;
             if ( >= ) {
                 freeMergedBuffer();
             }
             return c;
         }
         return .read();
     }
     
     @Override
     public int read(byte[] bthrows IOException
     {
         return read(b, 0, b.length);
     }
 
     @Override
     public int 	read(byte[] bint offint lenthrows IOException
     {
         if ( != null) {
             int avail =  - ;
             if (len > avail) {
                 len = avail;
             }
             System.arraycopy(bofflen);
              += len;
             if ( >= ) {
                 freeMergedBuffer();
             }
             return len;
        }
        return .read(bofflen);
    }
    @Override
    public void reset() throws IOException
    {
        if ( == null) {
            .reset();
        }
    }
    @Override
    public long skip(long nthrows IOException
    {
        long count = 0L;
        if ( != null) {
            int amount =  - ;
            if (amount > n) { // all in pushed back segment?
                 += (intn;
                return n;
            }
            freeMergedBuffer();
            count += amount;
            n -= amount;
        }
        if (n > 0) {
            count += .skip(n);
        }
        return count;
    }
    private void freeMergedBuffer()
    {
        byte[] buf = ;
        if (buf != null) {
             = null;
            if ( != null) {
                .releaseReadIOBuffer(buf);
            }
        }
    }
New to GrepCode? Check out our FAQ X