private void writeJsonDouble ( double num ) throws IOException { context . write ( ) ; String str = Double . toString ( num ) ; boolean special = false ; switch ( str . charAt ( 0 ) ) { case ' ' : // NaN case ' ' : // Infinity special = true ; break ; case ' ' : if ( str . charAt ( 1 ) == ' ' ) { // -Infinity special = true ; } break ; default : break ; } boolean escapeNum = special || context . escapeNum ( ) ; if ( escapeNum ) { transport . write ( QUOTE ) ; } try { byte [ ] b = str . getBytes ( "UTF-8" ) ; transport . write ( b , 0 , b . length ) ; } catch ( UnsupportedEncodingException e ) { throw new AssertionError ( e ) ; } if ( escapeNum ) { transport . write ( QUOTE ) ; } }
context dictates escaping write out as Json string .