Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 66   Methods: 5
NCLOC: 41   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
Copy.java 0% 0% 0% 0%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.util.other;
 11   
 
 12   
 import java.io.IOException;
 13   
 import java.io.InputStream;
 14   
 import java.io.InputStreamReader;
 15   
 import java.io.OutputStream;
 16   
 import java.io.Reader;
 17   
 
 18   
 /**
 19   
  *
 20   
  */
 21   
 public class Copy {
 22   
 
 23   
   private static int BUFFER_SIZE = 8192;
 24   
 
 25  0
   private Copy() {}
 26   
 
 27  0
   public static void copyStream(InputStream is, OutputStream os) throws IOException {
 28  0
     byte[] buffer = new byte[BUFFER_SIZE];
 29  0
     int length;
 30  0
     while ((length = is.read(buffer)) >= 0) {
 31  0
       os.write(buffer, 0, length);
 32   
     }
 33   
   }
 34   
 
 35  0
   public static String convertToString(Reader r) throws IOException {
 36  0
     StringBuffer sb = new StringBuffer();
 37  0
     char[] buffer = new char[BUFFER_SIZE];
 38  0
     int length;
 39  0
     while ((length = r.read(buffer)) >= 0) {
 40  0
       sb.append(buffer, 0, length);
 41   
     }
 42  0
     return sb.toString();
 43   
   }
 44   
 
 45  0
   public static String convertToString(InputStream is) throws IOException {
 46  0
     return convertToString(new InputStreamReader(is));
 47   
   }
 48   
 
 49   
   /**
 50   
    * Copies the content of a stream into a byte array.
 51   
    */
 52  0
   public static byte[] copyToByteArray(InputStream is) throws IOException {
 53  0
     byte[] buffer = new byte[BUFFER_SIZE];
 54  0
     byte[] content = new byte[0];
 55  0
     int length;
 56  0
     while ((length = is.read(buffer)) > 0) {
 57  0
       byte[] tmp = content;
 58  0
       content = new byte[tmp.length + length];
 59  0
       System.arraycopy(tmp, 0, content, 0, tmp.length);
 60  0
       System.arraycopy(buffer, 0, content, tmp.length, length);
 61   
     }
 62  0
     return content;
 63   
   }
 64   
 
 65   
 }
 66