Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2000, 2010 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.util;
  
A replacement for ByteArrayInputStream that does not synchronize every byte read.

This class extends java.io.InputStream and its read() methods allow it to be used as a standard input stream. In addition, it provides readFast() methods that are not declared to throw IOException. IOException is never thrown by this class.

Author(s):
Mark Hayes
 
 public class FastInputStream extends InputStream {
 
     protected int len;
     protected int off;
     protected int mark;
     protected byte[] buf;

    
Creates an input stream.

Parameters:
buffer the data to read.
 
     public FastInputStream(byte[] buffer) {
 
          = buffer;
          = buffer.length;
     }

    
Creates an input stream.

Parameters:
buffer the data to read.
offset the byte offset at which to begin reading.
length the number of bytes to read.
 
     public FastInputStream(byte[] bufferint offsetint length) {
 
          = buffer;
          = offset;
          = offset + length;
     }
 
     // --- begin ByteArrayInputStream compatible methods ---
 
     @Override
     public int available() {
 
         return  - ;
     }
 
     @Override
     public boolean markSupported() {
 
         return true;
     }
 
     @Override
     public void mark(int readLimit) {
 
          = ;
     }
 
     @Override
     public void reset() {
 
          = ;
     }
 
     @Override
     public long skip(long count) {
 
         int myCount = (intcount;
         if (myCount +  > ) {
             myCount =  - ;
         }
         skipFast(myCount);
         return myCount;
     }
 
     @Override
     public int read() {
         return readFast();
     }
 
    @Override
    public int read(byte[] toBuf) {
        return readFast(toBuf, 0, toBuf.length);
    }
    @Override
    public int read(byte[] toBufint offsetint length) {
        return readFast(toBufoffsetlength);
    }
    // --- end ByteArrayInputStream compatible methods ---

    
Equivalent to skip() but takes an int parameter instead of a long, and does not check whether the count given is larger than the number of remaining bytes.

See also:
skip(long)
    public final void skipFast(int count) {
         += count;
    }

    
Equivalent to read() but does not throw IOException.

See also:
read()
    public final int readFast() {
        return ( < ) ? ([++] & 0xff) : (-1);
    }

    
Equivalent to read(byte[]) but does not throw IOException.

See also:
read(byte[])
    public final int readFast(byte[] toBuf) {
        return readFast(toBuf, 0, toBuf.length);
    }

    
Equivalent to read(byte[],int,int) but does not throw IOException.

    public final int readFast(byte[] toBufint offsetint length) {
        int avail =  - ;
        if (avail <= 0) {
            return -1;
        }
        if (length > avail) {
            length = avail;
        }
        System.arraycopy(toBufoffsetlength);
         += length;
        return length;
    }

    
Returns the underlying data being read.

Returns:
the underlying data.
    public final byte[] getBufferBytes() {
        return ;
    }

    
Returns the offset at which data is being read from the buffer.

Returns:
the offset at which data is being read.
    public final int getBufferOffset() {
        return ;
    }

    
Returns the end of the buffer being read.

Returns:
the end of the buffer.
    public final int getBufferLength() {
        return ;
    }
New to GrepCode? Check out our FAQ X