Coverage Report - org.apache.maven.doxia.module.apt.AptReaderSource
 
Classes in this File Line Coverage Branch Coverage Complexity
AptReaderSource
70%
14/20
75%
3/4
2
 
 1  
 package org.apache.maven.doxia.module.apt;
 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.IOException;
 23  
 import java.io.LineNumberReader;
 24  
 import java.io.Reader;
 25  
 
 26  
 import org.codehaus.plexus.util.IOUtil;
 27  
 
 28  
 /**
 29  
  * Reader for apt source documents.
 30  
  *
 31  
  * @version $Id: AptReaderSource.java 746982 2009-02-23 12:25:50Z vsiveton $
 32  
  */
 33  
 public class AptReaderSource
 34  
     implements AptSource
 35  
 {
 36  
     /** A reader. */
 37  
     private LineNumberReader reader;
 38  
 
 39  
     /** lineNumber. */
 40  
     private int lineNumber;
 41  
 
 42  
     /**
 43  
      * Constructor: intialize reader.
 44  
      *
 45  
      * @param in the reader.
 46  
      */
 47  
     public AptReaderSource( Reader in )
 48  36
     {
 49  36
         reader = new LineNumberReader( in );
 50  
 
 51  36
         lineNumber = -1;
 52  36
     }
 53  
 
 54  
     /** {@inheritDoc} */
 55  
     public String getNextLine()
 56  
         throws AptParseException
 57  
     {
 58  1404
         if ( reader == null )
 59  
         {
 60  0
             return null;
 61  
         }
 62  
 
 63  
         String line;
 64  
 
 65  
         try
 66  
         {
 67  1404
             line = reader.readLine();
 68  1404
             if ( line == null )
 69  
             {
 70  36
                 reader.close();
 71  36
                 reader = null;
 72  
             }
 73  
             else
 74  
             {
 75  1368
                 lineNumber = reader.getLineNumber();
 76  
             }
 77  
         }
 78  0
         catch ( IOException e )
 79  
         {
 80  
             // TODO handle column number
 81  0
             throw new AptParseException( "IOException: " + e.getMessage(), e, lineNumber, -1 );
 82  1404
         }
 83  
 
 84  1404
         return line;
 85  
     }
 86  
 
 87  
     /** {@inheritDoc} */
 88  
     public String getName()
 89  
     {
 90  480
         return "";
 91  
     }
 92  
 
 93  
     /** {@inheritDoc} */
 94  
     public int getLineNumber()
 95  
     {
 96  480
         return lineNumber;
 97  
     }
 98  
 
 99  
     /**
 100  
      * Closes the reader associated with this AptReaderSource.
 101  
      */
 102  
     public void close()
 103  
     {
 104  0
         IOUtil.close( reader );
 105  0
         reader = null;
 106  0
     }
 107  
 }