Coverage Report - org.apache.commons.flatfile.EntitySupport
 
Classes in this File Line Coverage Branch Coverage Complexity
EntitySupport
22%
4/18
0%
0/4
2.75
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.flatfile;
 18  
 
 19  
 import java.io.IOException;
 20  
 
 21  
 import org.apache.commons.flatfile.util.RepeatingInputStream;
 22  
 
 23  
 /**
 24  
  * Generic entity support stuff.
 25  
  * @version $Revision: 757266 $ $Date: 2009-03-22 17:12:27 -0500 (Sun, 22 Mar 2009) $
 26  
  */
 27  195
 public abstract class EntitySupport implements Entity {
 28  
 
 29  
     /** Serialization version */
 30  
     private static final long serialVersionUID = 1067918863342682612L;
 31  
 
 32  
     /**
 33  
      * {@inheritDoc}
 34  
      */
 35  
     public void fill(byte b) throws IOException {
 36  10
         readFrom(RepeatingInputStream.getInstance(b));
 37  10
     }
 38  
 
 39  
     /**
 40  
      * {@inheritDoc}
 41  
      */
 42  
     public EntitySupport clone() {
 43  
         try {
 44  930
             return (EntitySupport) super.clone();
 45  0
         } catch (CloneNotSupportedException e) {
 46  0
             throw new RuntimeException(e);
 47  
         }
 48  
     }
 49  
 
 50  
     /**
 51  
      * {@inheritDoc}
 52  
      */
 53  
     public byte[] getValue(int offset, int length) {
 54  0
         if (offset + length > length()) {
 55  0
             throw new IndexOutOfBoundsException();
 56  
         }
 57  0
         byte[] value = getValue();
 58  0
         byte[] result = new byte[length];
 59  0
         System.arraycopy(value, offset, result, 0, length);
 60  0
         return result;
 61  
     }
 62  
 
 63  
     /**
 64  
      * {@inheritDoc}
 65  
      */
 66  
     public void setValue(byte[] b, int offset, int length) {
 67  0
         if (offset + length > b.length) {
 68  0
             throw new IndexOutOfBoundsException();
 69  
         }
 70  0
         byte[] subset = new byte[length];
 71  0
         System.arraycopy(b, offset, subset, 0, length);
 72  0
         setValue(subset);
 73  0
     }
 74  
 
 75  
 }