RSerializer { public void writeVector(double[] v) throws IOException { dataOut.write(getBytes("A")); dataOut.write(getBytes("2")); dataOut.write(getBytes("197214")); dataOut.write(getBytes("131840")); dataOut.write(getBytes("14")); dataOut.write(getBytes(v.length)); for (int i = 0; i < v.length; i++) { dataOut.write(getBytes(v[i])); } dataOut.flush(); byteOut.flush(); dataOut.close(); byteOut.close(); } RSerializer(); void writeVector(double[] v); void writeDoubleMatrix(double[][] d); void save(String filename);  }
@Test public void WriteVectorTest() throws IOException { RSerializer rs = new RSerializer(); double[] v = new double[]{1.0, 2.0, 3.0}; rs.writeVector(v); TempFileService tmpServ = new TempFileService(); File tmpFile = tmpServ.createTempFile("RCaller", "Test"); rs.save(tmpFile.getCanonicalPath()); RCaller caller = RCaller.create(); RCode code = RCode.create(); code.addRCode("conn <- file(\"" + Globals.getSystemSpecificRPathParameter(tmpFile) + "\" , \"r\")"); code.addRCode("x <- unserialize(conn)"); caller.setRCode(code); caller.runAndReturnResult("x"); double[] x = caller.getParser().getAsDoubleArray("x"); assertEquals(1.0, x[0], delta); assertEquals(2.0, x[1], delta); assertEquals(3.0, x[2], delta); }