1 18 19 27 package org.apache.jmeter.protocol.tcp.sampler; 28 29 import java.io.ByteArrayOutputStream ; 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.io.InterruptedIOException ; 33 import java.io.OutputStream ; 34 35 import org.apache.jmeter.util.JMeterUtils; 36 import org.apache.jorphan.logging.LoggingManager; 37 import org.apache.log.Logger; 38 39 44 public class TCPClientImpl implements TCPClient 45 { 46 private static Logger log = LoggingManager.getLoggerForClass(); 47 private byte eolByte = (byte) JMeterUtils.getPropDefault("tcp.eolByte",0); 48 49 public TCPClientImpl() 50 { 51 super(); 52 log.info("Using eolByte="+eolByte); 53 } 54 55 56 59 public void setupTest() 60 { 61 log.info("setuptest"); 62 } 63 64 67 public void teardownTest() 68 { 69 log.info("teardowntest"); 70 71 } 72 73 76 public void write(OutputStream os, String s) { 77 try 78 { 79 os.write(s.getBytes()); 80 os.flush(); 81 } 82 catch (IOException e) 83 { 84 log.debug("Write error",e); 85 } 86 log.debug("Wrote: "+s); 87 return; 88 } 89 90 91 94 public String read(InputStream is) 95 { 96 byte [] buffer = new byte[4096]; 97 ByteArrayOutputStream w = new ByteArrayOutputStream (); 98 int x = 0; 99 try { 100 while ((x = is.read(buffer)) > -1) 101 { 102 w.write(buffer, 0, x); 103 if ((eolByte != 0) && (buffer[x-1] == eolByte)) 104 break; 105 } 106 119 } catch (InterruptedIOException e) { 120 } catch (IOException e) { 122 log.warn("Read error:"+e); 123 return ""; 124 } 125 126 log.debug("Read: "+w.size()+ "\n"+w.toString()); 128 return w.toString(); 129 } 130 131 132 135 public void write(OutputStream os, InputStream is) { 136 return; 138 } 139 140 143 public byte getEolByte() { 144 return eolByte; 145 } 146 149 public void setEolByte(byte eolByte) { 150 this.eolByte = eolByte; 151 } 152 } 153 | Popular Tags |