@@ -193,6 +193,15 @@ public int getRemotePort() {
193193 return this .remotePort ;
194194 }
195195
196+ private boolean supportReadLine ;
197+ public SocketClient setSupportReadLine (boolean supportReadLine ) {
198+ this .supportReadLine = supportReadLine ;
199+ return this ;
200+ }
201+ public boolean isSupportReadLine () {
202+ return this .supportReadLine ;
203+ }
204+
196205 private int connectionTimeout ;
197206 public SocketClient setConnectionTimeout (int connectionTimeout ) {
198207 if (connectionTimeout < 0 ) {
@@ -589,7 +598,30 @@ public void run() {
589598 bufferedReader = new BufferedReader (new InputStreamReader (self .getRunningSocket ().getInputStream (), "UTF-8" ));
590599
591600 while (self .isConnected () && !isInterrupted ()) {
592- String response = bufferedReader .readLine ();
601+ String response = null ;
602+ if (self .isSupportReadLine ()) {
603+ response = bufferedReader .readLine ();
604+ }
605+ else {
606+ StringBuilder stringBuilder = new StringBuilder ();
607+ char [] chars = new char [1024 * 4 ];
608+ int n = 0 ;
609+ while (-1 != (n = bufferedReader .read (chars , 0 , chars .length ))) {
610+ // remove cr
611+ while (n > 0 && (chars [n - 1 ] == '\r' || chars [n - 1 ] == '\n' )) {
612+ n --;
613+ }
614+
615+ stringBuilder .append (chars , 0 , n );
616+
617+ // if last read clear the buffer
618+ if (n < chars .length || !bufferedReader .ready ()) {
619+ break ;
620+ }
621+ }
622+
623+ response = stringBuilder .toString ();
624+ }
593625
594626 if (response == null ) {
595627 self .disconnect ();
0 commit comments