boolean ascii,
SEXP version,
Environment envir,
boolean evalPromises) throws IOException {
Connection con = Connections.getConnection(context, connHandle);
boolean wasOpen = con.isOpen();
if(!wasOpen) {
con.open(new OpenSpec("wb"));
}
if(!con.canWrite()) {
throw new EvalException("connection not open for writing");
}
if(ascii) {
throw new EvalException("ascii serialization not implemented");
}
PairList.Builder list = new PairList.Builder();
for(String name : names) {
SEXP value = envir.getVariable(name);
if(value == Symbol.UNBOUND_VALUE) {
throw new EvalException("object '%s' not found", name);
}
if(evalPromises) {
value = value.force(context);
}
list.add(name, value);
}
RDataWriter writer = new RDataWriter(context, con.getOutputStream());
writer.save(list.build());
if (!wasOpen) {
con.close();
}
}