public void writeBytesEscaped ( byte [ ] bytes , int len , boolean noBackslashEscapes ) throws IOException { if ( len * 2 > buf . length - pos ) { //makes buffer bigger (up to 16M) if ( buf . length != getMaxPacketLength ( ) ) { growBuffer ( len * 2 ) ; } //data may be bigger than buffer. //must flush buffer when full (and reset position to 0) if ( len * 2 > buf . length - pos ) { if ( mark != - 1 ) { growBuffer ( len * 2 ) ; if ( mark != - 1 ) { flushBufferStopAtMark ( ) ; } } else { //not enough space in buffer, will fill buffer if ( noBackslashEscapes ) { for ( int i = 0 ; i < len ; i ++ ) { if ( QUOTE == bytes [ i ] ) { buf [ pos ++ ] = QUOTE ; if ( buf . length <= pos ) { flushBuffer ( false ) ; } } buf [ pos ++ ] = bytes [ i ] ; if ( buf . length <= pos ) { flushBuffer ( false ) ; } } } else { for ( int i = 0 ; i < len ; i ++ ) { if ( bytes [ i ] == QUOTE || bytes [ i ] == BACKSLASH || bytes [ i ] == DBL_QUOTE || bytes [ i ] == ZERO_BYTE ) { buf [ pos ++ ] = ' ' ; if ( buf . length <= pos ) { flushBuffer ( false ) ; } } buf [ pos ++ ] = bytes [ i ] ; if ( buf . length <= pos ) { flushBuffer ( false ) ; } } } return ; } } } //sure to have enough place filling buffer directly if ( noBackslashEscapes ) { for ( int i = 0 ; i < len ; i ++ ) { if ( QUOTE == bytes [ i ] ) { buf [ pos ++ ] = QUOTE ; } buf [ pos ++ ] = bytes [ i ] ; } } else { for ( int i = 0 ; i < len ; i ++ ) { if ( bytes [ i ] == QUOTE || bytes [ i ] == BACKSLASH || bytes [ i ] == ' ' || bytes [ i ] == ZERO_BYTE ) { buf [ pos ++ ] = BACKSLASH ; //add escape slash } buf [ pos ++ ] = bytes [ i ] ; } } }
Write escape bytes to socket .