+ vorbaclient.updateDocument(doc);
+ // merge vamsasObjects with vamsas objects in document
+
+ }
+ private int appdatareads=0;
+ private void processAppData(IClientDocument doc) throws Exception {
+ appdatareads++;
+ boolean writtenonce=false;
+ if (doc!=null)
+ {
+ uk.ac.vamsas.client.IClientAppdata appd = doc.getClientAppdata();
+ if (appd.hasClientAppdata() && !(appdatareads % 2==0))
+ {
+ //byte[] cappd = appd.getClientAppdata();
+ //if (cappd!=null)
+ // System.out.println("Client appdata\n"+cappd.toString()+"\nEnd of Appdata\n");
+ System.out.println("Testing read from inputstream");
+ String cappds = readData(appd.getClientInputStream());
+ System.out.println("Client appdata\n"+cappds+"\nEnd of Appdata\n");
+ } else {
+ if (!writtenonce)
+ {
+ writtenonce=true;
+ // appd.setClientAppdata(makeappData("Client Appdata for "+user.toString()+" written"));
+ writeData(appd.getClientOutputStream(), "Client Appdata for all users written on "+appdatareads+" read by "+vorbaclient.getUserHandle());
+ System.out.println("Written to ClientAppdata stream.");
+ }
+ }
+ if (appd.hasUserAppdata() && !(appdatareads % 2==0))
+ {
+ byte[] cappd = appd.getUserAppdata();
+ if (cappd!=null)
+ System.out.println("User appdata\n"+new String(cappd)+"\nEnd of Users' Appdata\n");
+ else
+ {
+ System.out.println("No user appdata.");
+ appd.setUserAppdata(("no default - overwritten null byte set on "+appdatareads+" read by "+vorbaclient.getUserHandle()+"").getBytes());
+ }
+ } else
+ if (!writtenonce)
+ {
+ writtenonce=true;
+ byte[] bts = makeappData("User Appdata for "+user+" written on "+appdatareads+" read at ");
+ System.out.println("Setting appData bytes to\n"+new String(bts)+"\nEnd.");
+ appd.setUserAppdata(bts);
+ System.out.println("Written to UserAppdata stream.");
+ }
+ }
+ }
+ private byte[] makeappData(String message)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(message);
+ sb.append("on "+new java.util.Date());
+ return sb.toString().getBytes();
+ }
+ private boolean writeData(AppDataOutputStream os, String message)
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append(message);
+ sb.append("on "+new java.util.Date());
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(os);
+ oos.writeObject(sb.toString());
+ oos.flush();
+ oos.close();
+ }
+ catch (Exception e) {
+ System.err.println("Problem serialising this message:\n"+sb);
+ e.printStackTrace(System.err);
+ return false;
+ }
+ return true;
+ }
+ private String readData(AppDataInputStream is)
+ {
+ try {
+ ObjectInputStream ois = new ObjectInputStream(is);
+ String rs = (String) ois.readObject();
+ return rs;
+ }
+ catch (Exception e)
+ {
+ System.err.println("Failed to read a string from input stream!");
+ e.printStackTrace(System.err);
+ }
+ return "";