static String escapeBytes(final ByteString input){
  final StringBuilder builder=new StringBuilder(input.size());
  for (int i=0; i < input.size(); i++) {
    final byte b=input.byteAt(i);
switch (b) {
case 0x07:
      builder.append("\\a");
    break;
case '\b':
  builder.append("\\b");
break;
case '\f':
builder.append("\\f");
break;
case '\n':
builder.append("\\n");
break;
case '\r':
builder.append("\\r");
break;
case '\t':
builder.append("\\t");
break;
case 0x0b:
builder.append("\\v");
break;
case '\\':
builder.append("\\\\");
break;
case '\'':
builder.append("\\\'");
break;
case '"':
builder.append("\\\"");
break;
default :
if (b >= 0x20) {
builder.append((char)b);
}
 else {
builder.append('\\');
builder.append((char)('0' + ((b >>> 6) & 3)));
builder.append((char)('0' + ((b >>> 3) & 7)));
builder.append((char)('0' + (b & 7)));
}
break;
}
}
return builder.toString();
}

static String escapeBytes ( final ByteString input ) { final StringBuilder builder = new StringBuilder ( input . size ( ) ) ; for ( int i = 0 ; i < input . size ( ) ; i ++ ) { final byte b = input . byteAt ( i ) ; switch ( b ) { case 0x07 : builder . append ( "\\a" ) ; break ; case '\b' : builder . append ( "\\b" ) ; break ; case '\f' : builder . append ( "\\f" ) ; break ; case '\n' : builder . append ( "\\n" ) ; break ; case '\r' : builder . append ( "\\r" ) ; break ; case '\t' : builder . append ( "\\t" ) ; break ; case 0x0b : builder . append ( "\\v" ) ; break ; case '\\' : builder . append ( "\\\\" ) ; break ; case '\'' : builder . append ( "\\\'" ) ; break ; case '"' : builder . append ( "\\\"" ) ; break ; default : if ( b >= 0x20 ) { builder . append ( ( char ) b ) ; } else { builder . append ( '\\' ) ; builder . append ( ( char ) ( '0' + ( ( b > > > 6 ) & 3 ) ) ) ; builder . append ( ( char ) ( '0' + ( ( b > > > 3 ) & 7 ) ) ) ; builder . append ( ( char ) ( '0' + ( b & 7 ) ) ) ; } break ; } } return builder . toString ( ) ; }
escapes bytes in the format used in protocol buffer text format , which is the same as the format used for c string literals . all bytes that are not printable 7 - bit ascii characters are escaped , as well as backslash , single - quote , and double - quote characters . characters for which no defined short - hand escape sequence is defined will be escaped using 3 - digit octal sequences .
