Coverage Report - org.kuali.rice.kns.util.cache.FastByteArrayInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
FastByteArrayInputStream
0%
0/22
0%
0/10
2.4
 
 1  
 /*
 2  
  * Copyright 2007-2008 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.util.cache;
 17  
 
 18  
 import java.io.InputStream;
 19  
 
 20  
 /**
 21  
  * ByteArrayInputStream implementation that does not synchronize methods.
 22  
  */
 23  
 public class FastByteArrayInputStream extends InputStream {
 24  
     /**
 25  
      * Our byte buffer
 26  
      */
 27  0
     protected byte[] buf = null;
 28  
 
 29  
     /**
 30  
      * Number of bytes that we can read from the buffer
 31  
      */
 32  0
     protected int count = 0;
 33  
 
 34  
     /**
 35  
      * Number of bytes that have been read from the buffer
 36  
      */
 37  0
     protected int pos = 0;
 38  
 
 39  0
     public FastByteArrayInputStream(byte[] buf, int count) {
 40  0
         this.buf = buf;
 41  0
         this.count = count;
 42  0
     }
 43  
 
 44  
     public final int available() {
 45  0
         return count - pos;
 46  
     }
 47  
 
 48  
     public final int read() {
 49  0
         return (pos < count) ? (buf[pos++] & 0xff) : -1;
 50  
     }
 51  
 
 52  
     public final int read(byte[] b, int off, int len) {
 53  0
         if (pos >= count)
 54  0
             return -1;
 55  
 
 56  0
         if ((pos + len) > count)
 57  0
             len = (count - pos);
 58  
 
 59  0
         System.arraycopy(buf, pos, b, off, len);
 60  0
         pos += len;
 61  0
         return len;
 62  
     }
 63  
 
 64  
     public final long skip(long n) {
 65  0
         if ((pos + n) > count)
 66  0
             n = count - pos;
 67  0
         if (n < 0)
 68  0
             return 0;
 69  0
         pos += n;
 70  0
         return n;
 71  
     }
 72  
 
 73  
 }