try {
WKBWriter w = new WKBWriter();
//write the geometry
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
w.write( g , new OutputStreamOutStream( bytes ) );
//supplement it with the srid
int srid = g.getSRID();
bytes.write( (byte)(srid >>> 24) );
bytes.write( (byte)(srid >> 16 & 0xff) );