Coverage Report - org.mockftpserver.core.util.IoUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
IoUtil
0%
0/13
0%
0/2
2
 
 1  
 /*
 2  
  * Copyright 2008 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.mockftpserver.core.util;
 17  
 
 18  
 import java.io.ByteArrayOutputStream;
 19  
 import java.io.IOException;
 20  
 import java.io.InputStream;
 21  
 
 22  
 /**
 23  
  * Contains static I/O-related utility methods.
 24  
  *
 25  
  * @author Chris Mair
 26  
  * @version $Revision: 182 $ - $Date: 2008-11-30 21:37:49 -0500 (Sun, 30 Nov 2008) $
 27  
  */
 28  
 public class IoUtil {
 29  
 
 30  
     /**
 31  
      * Read the contents of the InputStream and return as a byte[].
 32  
      *
 33  
      * @param input - the InputStream to read
 34  
      * @return the contents of the InputStream as a byte[]
 35  
      * @throws AssertFailedException - if the InputStream is null
 36  
      * @throws java.io.IOException   - if an error occurs reading the bytes
 37  
      */
 38  
     public static byte[] readBytes(InputStream input) throws IOException {
 39  0
         Assert.notNull(input, "input");
 40  0
         ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
 41  
 
 42  
         try {
 43  
             while (true) {
 44  0
                 int b = input.read();
 45  0
                 if (b == -1) {
 46  0
                     break;
 47  
                 }
 48  0
                 outBytes.write(b);
 49  0
             }
 50  0
         }
 51  
         finally {
 52  0
             input.close();
 53  0
         }
 54  0
         return outBytes.toByteArray();
 55  
     }
 56  
 
 57  
     /**
 58  
      * Private constructor to prevent instantiation. All members are static.
 59  
      */
 60  0
     private IoUtil() {
 61  0
     }
 62  
 
 63  
 }