Coverage Report - org.naftulin.configmgr.parsers.AbstractConfigEntryParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractConfigEntryParser
100%
9/9
100%
2/2
2
 
 1  
 package org.naftulin.configmgr.parsers;
 2  
 
 3  
 import java.io.BufferedReader;
 4  
 import java.io.IOException;
 5  
 import java.io.InputStreamReader;
 6  
 import java.io.InputStream;
 7  
 
 8  
 /**
 9  
  * Common configuration entry parser class. Used as more of a place-holder for
 10  
  * common functionality. The only method used so far is {@link #readStreamContentAsString(InputStream) 
 11  
  * reading the input stream}.
 12  
  * 
 13  
  * @author Henry Naftulin
 14  
  * @since 1.0
 15  
  */
 16  85
 public abstract class AbstractConfigEntryParser implements ConfigEntryParser {
 17  
 
 18  
         private static final int BUFFER_SIZE = 200;
 19  
 
 20  
         /**
 21  
          * Returns the content of the input stream. Reads the stream and creates a string out 
 22  
          * of it's content.
 23  
          * @param is the open, buffered input stream
 24  
          * @return  the content of the input stream.
 25  
          * @throws IOException if the stream could not be read.
 26  
          */
 27  
         protected String readStreamContentAsString(final InputStream is) throws IOException {
 28  
                 String content;
 29  205
                 final StringBuffer contentBuffer = new StringBuffer(BUFFER_SIZE);
 30  205
                 final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
 31  205
                 String line = reader.readLine();
 32  6560
                 while(line != null ) {
 33  6150
                         contentBuffer.append(line).append("\n");
 34  6150
                         line = reader.readLine();
 35  
                 }
 36  205
                 content = contentBuffer.toString();
 37  205
                 return content;
 38  
         }
 39  
 }