Coverage Report - org.apache.maven.surefire.util.internal.ByteBuffer
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteBuffer
0%
0/57
0%
0/14
1.412
 
 1  
 package org.apache.maven.surefire.util.internal;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.PrintStream;
 23  
 
 24  
 /**
 25  
  * @author Kristian Rosenvold
 26  
  */
 27  
 public class ByteBuffer
 28  
 {
 29  
     private final byte[] data;
 30  
 
 31  
     private int position;
 32  
 
 33  
     public ByteBuffer( int length )
 34  0
     {
 35  0
         this.data = new byte[length];
 36  0
     }
 37  
 
 38  
     public ByteBuffer( byte[] buf, int off, int len )
 39  0
     {
 40  0
         this.data = new byte[len];
 41  0
         append( buf, off, len );
 42  0
     }
 43  
 
 44  
 
 45  
     public void append( char chararcter )
 46  
     {
 47  0
         data[position++] = (byte) chararcter;
 48  0
     }
 49  
 
 50  
     public void append( byte chararcter )
 51  
     {
 52  0
         data[position++] = chararcter;
 53  0
     }
 54  
 
 55  
     static final byte comma = (byte) ',';
 56  
 
 57  
     public void comma()
 58  
     {
 59  0
         data[position++] = comma;
 60  0
     }
 61  
 
 62  
 
 63  
     public void advance( int i )
 64  
     { // Oooh nice break of encapsulation
 65  0
         position += i;
 66  0
     }
 67  
 
 68  
     public void append( Integer integer )
 69  
     {
 70  0
         toHex( integer.intValue() );
 71  0
     }
 72  
 
 73  
     /**
 74  
      * Convert the integer to an unsigned number.
 75  
      */
 76  
     private void toHex( int i )
 77  
     {
 78  0
         byte[] buf = new byte[32];
 79  0
         int charPos = 32;
 80  0
         int radix = 1 << 4;
 81  0
         int mask = radix - 1;
 82  
         do
 83  
         {
 84  0
             buf[--charPos] = (byte) digits[i & mask];
 85  0
             i >>>= 4;
 86  
         }
 87  0
         while ( i != 0 );
 88  
 
 89  0
         append( buf, charPos, ( 32 - charPos ) );
 90  0
     }
 91  
 
 92  0
     final static char[] digits =
 93  
         { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
 94  
             'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
 95  
 
 96  
 
 97  
     public byte[] getData()
 98  
     {
 99  0
         return data;
 100  
     }
 101  
 
 102  
     public int getlength()
 103  
     {
 104  0
         return position;
 105  
     }
 106  
 
 107  
     public String toString()
 108  
     {
 109  0
         return new String( data, 0, position );
 110  
     }
 111  
 
 112  
     public void append( ByteBuffer other )
 113  
     {
 114  0
         byte[] src = other.getData();
 115  0
         final int length = src.length;
 116  0
         for ( int i = 0; i < length; i++ )
 117  
         {
 118  0
             data[position++] = src[i];
 119  
         }
 120  0
     }
 121  
 
 122  
     public static byte[] copy( byte[] src1, int off1, int len1 )
 123  
     {
 124  0
         byte[] combined = new byte[len1];
 125  0
         int pos = 0;
 126  0
         for ( int i = off1; i < off1 + len1; i++ )
 127  
         {
 128  0
             combined[pos++] = src1[i];
 129  
         }
 130  0
         return combined;
 131  
     }
 132  
 
 133  
     public void append( byte[] src1, int off1, int len1 )
 134  
     {
 135  0
         for ( int i = off1; i < off1 + len1; i++ )
 136  
         {
 137  0
             data[position++] = src1[i];
 138  
         }
 139  0
     }
 140  
 
 141  
     public static byte[] join( byte[] src1, int off1, int len1, byte[] src2, int off2, int len2 )
 142  
     {
 143  0
         byte[] combined = new byte[len1 + len2];
 144  0
         int pos = 0;
 145  0
         for ( int i = off1; i < off1 + len1; i++ )
 146  
         {
 147  0
             combined[pos++] = src1[i];
 148  
         }
 149  0
         for ( int i = off2; i < off2 + len2; i++ )
 150  
         {
 151  0
             combined[pos++] = src2[i];
 152  
         }
 153  0
         return combined;
 154  
     }
 155  
 
 156  
     public void print( PrintStream printStream )
 157  
     {
 158  0
         printStream.write( data, 0, position );
 159  0
     }
 160  
 
 161  
     public static char[] toChar( byte[] b, int off, int len )
 162  
     {
 163  0
         char[] result = new char[len];
 164  0
         int pos = 0;
 165  0
         for ( int i = off; i < off + len; i++ )
 166  
         {
 167  0
             result[pos++] = (char) b[i];
 168  
         }
 169  0
         return result;
 170  
     }
 171  
 }