1 21 22 package org.continuent.sequoia.controller.backup.backupers; 23 24 import java.io.BufferedOutputStream ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 29 37 public class NativeCommandInputSource 38 { 39 String [] inputStringArray; 40 InputStream inputStream; 41 42 48 public NativeCommandInputSource(String [] arrayInput) 49 { 50 this.inputStringArray = arrayInput; 51 } 52 53 59 public NativeCommandInputSource(InputStream inputStream) 60 { 61 this.inputStream = inputStream; 62 } 63 64 70 public static NativeCommandInputSource createArrayInputSource( 71 String [] inputArray) 72 { 73 if (inputArray == null) 74 return null; 75 else 76 return new NativeCommandInputSource(inputArray); 77 } 78 79 85 public static NativeCommandInputSource createInputStreamSource( 86 InputStream inputStream) 87 { 88 if (inputStream == null) 89 return null; 90 else 91 return new NativeCommandInputSource(inputStream); 92 } 93 94 101 public void write(OutputStream outputStream) throws IOException 102 { 103 if (inputStringArray != null) 104 { 105 BufferedOutputStream feed = new BufferedOutputStream (outputStream); 107 for (int i = 0; i < inputStringArray.length; i++) 108 { 109 feed.write(inputStringArray[i].getBytes()); 110 feed.write("\n".getBytes()); 111 feed.flush(); 112 } 113 } 114 else 115 { 116 byte[] buff = new byte[1024]; 118 int len = 0; 119 while ((len = inputStream.read(buff)) > 0) 120 { 121 outputStream.write(buff, 0, len); 122 } 123 } 124 } 125 126 131 public void close() throws IOException 132 { 133 if (inputStringArray != null) 134 { 135 } 137 else 138 { 139 inputStream.close(); 140 } 141 } 142 } | Popular Tags |