1 package com.openedit.util; 2 3 import java.io.File ; 4 import java.io.FileInputStream ; 5 import java.io.FileOutputStream ; 6 import java.io.IOException ; 7 import java.io.InputStream ; 8 9 13 public class OutputFiller 14 { 15 protected int fieldBufferSize = 1024; 16 17 20 public OutputFiller() 21 { 22 super(); 23 } 24 25 29 public OutputFiller(int inBufferSize) 30 { 31 setBufferSize(inBufferSize); 32 } 33 34 public void fill(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException 35 { 36 byte[] bytes = new byte[getBufferSize()]; 37 38 int iRead = -1; 39 40 while (true) 41 { 42 iRead = in.read(bytes); 43 44 if (iRead != -1) 45 { 46 out.write(bytes, 0, iRead); 47 } 48 else 49 { 50 break; 51 } 52 } 53 out.flush(); 54 } 55 56 public void fill(java.io.Reader in, java.io.Writer out) throws java.io.IOException 57 { 58 char[] bytes = new char[getBufferSize()]; 59 60 int iRead = -1; 61 62 while (true) 63 { 64 iRead = in.read(bytes); 65 66 if (iRead != -1) 67 { 68 out.write(bytes, 0, iRead); 69 } 70 else 71 { 72 break; 73 } 74 75 } 76 out.flush(); 77 } 78 79 public void fill(File inSource, File inOut) throws IOException 80 { 81 FileInputStream in = null; 82 try 83 { 84 in = new FileInputStream (inSource); 85 inOut.getParentFile().mkdirs(); 86 FileOutputStream out = new FileOutputStream (inOut); 87 try 88 { 89 fill(in, out); 90 } 91 finally 92 { 93 FileUtils.safeClose(out); 94 } 95 } 96 finally 97 { 98 FileUtils.safeClose(in); 99 } 100 } 101 102 106 public int getBufferSize() 107 { 108 return fieldBufferSize; 109 } 110 111 115 public void setBufferSize(int newBufferSize) 116 { 117 fieldBufferSize = newBufferSize; 118 } 119 120 123 public void close(InputStream inIn) 124 { 125 if ( inIn != null) 126 { 127 try 128 { 129 inIn.close(); 130 } catch (IOException ex) 131 { 132 } 134 } 135 } 136 } | Popular Tags |