@ GwtIncompatible ( "java.io.ByteArrayOutputStream" ) public byte [ ] toBytes ( ) { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; Writer writer = new OutputStreamWriter ( baos , UTF_8 ) ; try { // The output order should be stable. for ( Map . Entry < String , String > entry : ImmutableSortedSet . copyOf ( comparingByKey ( ) , map . entrySet ( ) ) ) { writer . write ( escape ( entry . getKey ( ) ) ) ; writer . write ( SEPARATOR ) ; writer . write ( escape ( entry . getValue ( ) ) ) ; writer . write ( ' ' ) ; } writer . close ( ) ; } catch ( IOException e ) { // Note: A ByteArrayOutputStream never throws IOException. This try/catch // is just here to appease the Java compiler. throw new RuntimeException ( e ) ; } return baos . toByteArray ( ) ; }
Serializes the variable map to a byte array .