Coverage Report - org.mule.util.ChainedReader
 
Classes in this File Line Coverage Branch Coverage Complexity
ChainedReader
0%
0/31
0%
0/12
3.4
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.util;
 8  
 
 9  
 import java.io.IOException;
 10  
 import java.io.Reader;
 11  
 
 12  
 /**
 13  
  * <code>ChainedReader</code> allows Reader objects to be chained together. Useful
 14  
  * for concatenating data from multiple Reader objects.
 15  
  */
 16  
 public class ChainedReader extends Reader
 17  
 {
 18  
     private final Reader first;
 19  
     private final Reader second;
 20  0
     private boolean firstRead = false;
 21  
 
 22  
     public ChainedReader(Reader first, Reader second)
 23  0
     {
 24  0
         this.first = first;
 25  0
         this.second = second;
 26  0
     }
 27  
 
 28  
     public void close() throws IOException
 29  
     {
 30  0
         first.close();
 31  0
         second.close();
 32  0
     }
 33  
 
 34  
     public int read(char[] cbuf, int off, int len) throws IOException
 35  
     {
 36  0
         if (!firstRead)
 37  
         {
 38  0
             int i = first.read(cbuf, off, len);
 39  0
             if (i < len)
 40  
             {
 41  0
                 firstRead = true;
 42  0
                 int x = second.read(cbuf, i, len - i);
 43  0
                 return x + i;
 44  
             }
 45  
             else
 46  
             {
 47  0
                 return i;
 48  
             }
 49  
         }
 50  
         else
 51  
         {
 52  0
             return second.read(cbuf, off, len);
 53  
         }
 54  
     }
 55  
 
 56  
     public int read() throws IOException
 57  
     {
 58  0
         if (!firstRead)
 59  
         {
 60  0
             int i = first.read();
 61  0
             if (i == -1)
 62  
             {
 63  0
                 firstRead = true;
 64  0
                 return second.read();
 65  
             }
 66  
             else
 67  
             {
 68  0
                 return i;
 69  
             }
 70  
         }
 71  
         else
 72  
         {
 73  0
             return second.read();
 74  
         }
 75  
     }
 76  
 
 77  
     public int read(char[] cbuf) throws IOException
 78  
     {
 79  0
         if (!firstRead)
 80  
         {
 81  0
             int i = first.read(cbuf);
 82  0
             if (i < cbuf.length)
 83  
             {
 84  0
                 firstRead = true;
 85  0
                 int x = second.read(cbuf, i, cbuf.length - i);
 86  0
                 return x + i;
 87  
             }
 88  
             else
 89  
             {
 90  0
                 return i;
 91  
             }
 92  
         }
 93  
         else
 94  
         {
 95  0
             return second.read(cbuf);
 96  
         }
 97  
     }
 98  
 
 99  
 }