@Override public byte[] serializeToByteArray(final Set<String> fontsAlreadyOnClient) throws IOException {
  final ByteArrayOutputStream bos=new ByteArrayOutputStream();
  bos.write(1);
  bos.write(1);
  bos.write(rawPageNumber);
  text_color.trim();
  stroke_color.trim();
  fill_color.trim();
  stroke.trim();
  pageObjects.trim();
  javaObjects.trim();
  stroke.trim();
  pageObjects.trim();
  javaObjects.trim();
  shapeType.trim();
  af1.trim();
  af2.trim();
  af3.trim();
  af4.trim();
  clips.trim();
  objectType.trim();
  if (opacity != null) {
    opacity.trim();
  }
  if (BMvalues != null) {
    BMvalues.trim();
  }
  if (TRvalues != null) {
    TRvalues.trim();
  }
  if (fs != null) {
    fs.trim();
  }
  if (lw != null) {
    lw.trim();
  }
  RenderUtils.writeToStream(bos,x_coord);
  RenderUtils.writeToStream(bos,y_coord);
  RenderUtils.writeToStream(bos,text_color);
  RenderUtils.writeToStream(bos,textFillType);
  stroke_color.writeToStream(bos);
  fill_color.writeToStream(bos);
  stroke.writeToStream(bos);
  pageObjects.writeToStream(bos);
  RenderUtils.writeToStream(bos,javaObjects);
  RenderUtils.writeToStream(bos,shapeType);
  RenderUtils.writeToStream(bos,af1);
  RenderUtils.writeToStream(bos,af2);
  RenderUtils.writeToStream(bos,af3);
  RenderUtils.writeToStream(bos,af4);
  clips.writeToStream(bos);
  RenderUtils.writeToStream(bos,objectType);
  RenderUtils.writeToStream(bos,opacity);
  RenderUtils.writeToStream(bos,BMvalues);
  RenderUtils.writeToStream(bos,TRvalues);
  RenderUtils.writeToStream(bos,fs);
  RenderUtils.writeToStream(bos,lw);
  int fontCount=0, updateCount=0;
  final Set<String> fontsAlreadySent=new HashSet<String>(10);
  final Set<String> newFontsToSend=new HashSet<String>(10);
  for (  final String fontUsed : fontsUsed) {
    if (!fontsAlreadyOnClient.contains(fontUsed)) {
      fontCount++;
      newFontsToSend.add(fontUsed);
    }
 else {
      updateCount++;
      fontsAlreadySent.add(fontUsed);
    }
  }
  RenderUtils.writeToStream(bos,fontCount);
  for (  String key : newFontsToSend) {
    RenderUtils.writeToStream(bos,key);
    RenderUtils.writeToStream(bos,fonts.get(key));
    fontsAlreadyOnClient.add(key);
  }
  RenderUtils.writeToStream(bos,updateCount);
  for (  String key : fontsAlreadySent) {
    RenderUtils.writeToStream(bos,key);
    final PdfJavaGlyphs aa=(PdfJavaGlyphs)fonts.get(key);
    RenderUtils.writeToStream(bos,aa.getDisplayValues());
    RenderUtils.writeToStream(bos,aa.getCharGlyphs());
    RenderUtils.writeToStream(bos,aa.getEmbeddedEncs());
  }
  bos.close();
  fontsUsed.clear();
  return bos.toByteArray();
}

@ Override public byte [ ] serializeToByteArray ( final Set < String > fontsAlreadyOnClient ) throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; bos . write ( 1 ) ; bos . write ( 1 ) ; bos . write ( rawPageNumber ) ; text_color . trim ( ) ; stroke_color . trim ( ) ; fill_color . trim ( ) ; stroke . trim ( ) ; pageObjects . trim ( ) ; javaObjects . trim ( ) ; stroke . trim ( ) ; pageObjects . trim ( ) ; javaObjects . trim ( ) ; shapeType . trim ( ) ; af1 . trim ( ) ; af2 . trim ( ) ; af3 . trim ( ) ; af4 . trim ( ) ; clips . trim ( ) ; objectType . trim ( ) ; if ( opacity != null ) { opacity . trim ( ) ; } if ( BMvalues != null ) { BMvalues . trim ( ) ; } if ( TRvalues != null ) { TRvalues . trim ( ) ; } if ( fs != null ) { fs . trim ( ) ; } if ( lw != null ) { lw . trim ( ) ; } RenderUtils . writeToStream ( bos , x_coord ) ; RenderUtils . writeToStream ( bos , y_coord ) ; RenderUtils . writeToStream ( bos , text_color ) ; RenderUtils . writeToStream ( bos , textFillType ) ; stroke_color . writeToStream ( bos ) ; fill_color . writeToStream ( bos ) ; stroke . writeToStream ( bos ) ; pageObjects . writeToStream ( bos ) ; RenderUtils . writeToStream ( bos , javaObjects ) ; RenderUtils . writeToStream ( bos , shapeType ) ; RenderUtils . writeToStream ( bos , af1 ) ; RenderUtils . writeToStream ( bos , af2 ) ; RenderUtils . writeToStream ( bos , af3 ) ; RenderUtils . writeToStream ( bos , af4 ) ; clips . writeToStream ( bos ) ; RenderUtils . writeToStream ( bos , objectType ) ; RenderUtils . writeToStream ( bos , opacity ) ; RenderUtils . writeToStream ( bos , BMvalues ) ; RenderUtils . writeToStream ( bos , TRvalues ) ; RenderUtils . writeToStream ( bos , fs ) ; RenderUtils . writeToStream ( bos , lw ) ; int fontCount = 0 , updateCount = 0 ; final Set < String > fontsAlreadySent = new HashSet < String > ( 10 ) ; final Set < String > newFontsToSend = new HashSet < String > ( 10 ) ; for ( final String fontUsed : fontsUsed ) { if ( ! fontsAlreadyOnClient . contains ( fontUsed ) ) { fontCount ++ ; newFontsToSend . add ( fontUsed ) ; } else { updateCount ++ ; fontsAlreadySent . add ( fontUsed ) ; } } RenderUtils . writeToStream ( bos , fontCount ) ; for ( String key : newFontsToSend ) { RenderUtils . writeToStream ( bos , key ) ; RenderUtils . writeToStream ( bos , fonts . get ( key ) ) ; fontsAlreadyOnClient . add ( key ) ; } RenderUtils . writeToStream ( bos , updateCount ) ; for ( String key : fontsAlreadySent ) { RenderUtils . writeToStream ( bos , key ) ; final PdfJavaGlyphs aa = ( PdfJavaGlyphs ) fonts . get ( key ) ; RenderUtils . writeToStream ( bos , aa . getDisplayValues ( ) ) ; RenderUtils . writeToStream ( bos , aa . getCharGlyphs ( ) ) ; RenderUtils . writeToStream ( bos , aa . getEmbeddedEncs ( ) ) ; } bos . close ( ) ; fontsUsed . clear ( ) ; return bos . toByteArray ( ) ; }
turn object into byte [ ] so we can move across this way should be much faster than the stadard java serialise . not part of api and subject to change ( do not use )
