/[storm]/storm/org/nongnu/storm/util/CopyUtil.java
ViewVC logotype

Diff of /storm/org/nongnu/storm/util/CopyUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by benja, Thu Apr 3 14:38:14 2003 UTC revision 1.3 by benja, Sat Apr 19 12:20:32 2003 UTC
# Line 31  import java.io.*; Line 31  import java.io.*;
31  /** Utility methods for copying data from input to output streams.  /** Utility methods for copying data from input to output streams.
32   */   */
33  public class CopyUtil {  public class CopyUtil {
34        static private int BLOCKSIZE = 4096;
35    
36      static public int copy(InputStream from, OutputStream to)      static public int copy(InputStream from, OutputStream to)
37                                                  throws IOException {                                                  throws IOException {
38          return copy(from, to, 4096);          return copy(from, to, BLOCKSIZE, true);
39        }
40    
41        static public int copy(InputStream from, OutputStream to,
42                               int blocksize)
43                                                    throws IOException {
44            return copy(from, to, blocksize, true);
45        }
46    
47        static public int copy(InputStream from, OutputStream to,
48                               boolean close)
49                                                    throws IOException {
50            return copy(from, to, BLOCKSIZE, close);
51      }      }
52    
53      /** Copy data from an input to an output stream in blocks of a given size.      /** Copy data from an input to an output stream in blocks of a given size.
54       *  Closes both streams when the copy operation is complete.       *  If <code>close</code> is true, both streams are closed
55         *  when the copy operation is complete.
56       */       */
57      static public int copy(InputStream from, OutputStream to, int blockSize)      static public int copy(InputStream from, OutputStream to,
58                               int blockSize, boolean close)
59                                                  throws IOException {                                                  throws IOException {
60          try {          try {
61              byte[] buf = new byte[blockSize];              byte[] buf = new byte[blockSize];
# Line 57  public class CopyUtil { Line 73  public class CopyUtil {
73              //p("... all read.");              //p("... all read.");
74              return bytesCopied;              return bytesCopied;
75          } finally {          } finally {
76              from.close();              if(close) {
77              to.close();                  from.close();
78                    to.close();
79                }
80          }          }
81      }      }
82    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26