FileOutputAdapter implements MLOutputAdapter { @Override public void write(String outPath, InputStream in) throws MLOutputAdapterException { if (in == null || outPath == null) { throw new MLOutputAdapterException(String.format( "Null argument values detected. Input stream: %s Out Path: %s", in, outPath)); } OutputStream out = null; try { File file = new File(outPath); out = new FileOutputStream(file); IOUtils.copy(in, out); } catch (IOException e) { throw new MLOutputAdapterException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { throw new MLOutputAdapterException(String.format("Failed to close the output stream of file %s", outPath), e); } } try { in.close(); } catch (IOException e) { throw new MLOutputAdapterException(String.format( "Failed to close the input stream after writing to file %s", outPath), e); } } }  @Override void write(String outPath, InputStream in);  }
@Test public void testWriteDataset() throws URISyntaxException, MLInputAdapterException { MLInputAdapter inputAdapter = new FileInputAdapter(); String uriString = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "fcSample.csv"; String uri; String outPath; InputStream in = null; uri = System.getProperty("user.dir") + File.separator + uriString; in = inputAdapter.read(uri); Assert.assertNotNull(in); try { File outFile = File.createTempFile("FileOutputAdapterTestOutput", ".csv"); outPath = outFile.getAbsolutePath(); } catch (IOException e) { outPath = System.getProperty("user.dir") + File.separator + uriString + ".out.csv"; } MLOutputAdapter outputAdapter = new FileOutputAdapter(); try { outputAdapter.write(outPath, in); } catch (MLOutputAdapterException e) { Assert.assertNull(e); } in = null; try { outputAdapter.write(outPath, in); } catch (Exception e) { Assert.assertEquals(e instanceof MLOutputAdapterException, true); } }