### Question:
FileDataSource extends DataSource { @Override public void close() { exec.shutdownNow(); super.close(); } FileDataSource(FileDataSourceConfiguration conf); @Override void close();  }### Answer:
@Test public void udpateFile() throws Exception { CountDownPVReaderListener listener = new CountDownPVReaderListener(1, PVReaderEvent.VALUE_MASK); File filename = File.createTempFile("file.", ".csv"); PrintWriter writer = new PrintWriter(filename); writer.println("Name,Value"); writer.println("Andrew,34"); writer.println("Bob,12"); writer.close(); pv = PVManager.read(vType(filename.toURI().getPath())).from(file) .readListener(listener) .maxRate(ofMillis(10)); listener.await(ofMillis(1500)); assertThat(listener.getCount(), equalTo(0)); assertThat(pv.getValue(), instanceOf(VTable.class)); VTable vTable = (VTable) pv.getValue(); assertThat(vTable.getRowCount(), equalTo(2)); assertThat(vTable.getColumnCount(), equalTo(2)); assertThat(vTable.getColumnName(0), equalTo("Name")); assertThat(vTable.getColumnName(1), equalTo("Value")); assertThat(vTable.getColumnData(0), equalTo((Object) Arrays.asList("Andrew", "Bob"))); assertThat(vTable.getColumnData(1), equalTo((Object) new ArrayDouble(34,12))); listener.resetCount(1); writer = new PrintWriter(new BufferedWriter(new FileWriter(filename, true))); writer.println("Charlie,71"); writer.close(); listener.await(ofMillis(3000)); assertThat(listener.getCount(), equalTo(0)); assertThat(pv.getValue(), instanceOf(VTable.class)); vTable = (VTable) pv.getValue(); assertThat(vTable.getRowCount(), equalTo(3)); assertThat(vTable.getColumnCount(), equalTo(2)); assertThat(vTable.getColumnName(0), equalTo("Name")); assertThat(vTable.getColumnName(1), equalTo("Value")); assertThat(vTable.getColumnData(0), equalTo((Object) Arrays.asList("Andrew", "Bob", "Charlie"))); assertThat(vTable.getColumnData(1), equalTo((Object) new ArrayDouble(34,12,71))); }
@Test public void writeToList1() throws Exception { CountDownPVReaderListener listener = new CountDownPVReaderListener(1, PVReaderEvent.VALUE_MASK); File filename = File.createTempFile("file.", ".list"); PrintWriter writer = new PrintWriter(filename); writer.println("A"); writer.println("B"); writer.println("C"); writer.close(); PV<VType, Object> fullPv = PVManager.readAndWrite(vType(filename.toURI().getPath())).from(file) .readListener(listener) .synchWriteAndMaxReadRate(ofMillis(10)); pv = fullPv; listener.await(ofMillis(700)); assertThat(listener.getCount(), equalTo(0)); assertThat(pv.getValue(), instanceOf(VStringArray.class)); VStringArray array = (VStringArray) pv.getValue(); assertThat(array.getData(), equalTo(Arrays.asList("A", "B", "C"))); listener.resetCount(1); fullPv.write(ValueFactory.toVType(Arrays.asList("A", "B", "C", "D"))); listener.await(ofMillis(2000)); assertThat(listener.getCount(), equalTo(0)); assertThat(pv.getValue(), instanceOf(VStringArray.class)); array = (VStringArray) pv.getValue(); assertThat(array.getData(), equalTo(Arrays.asList("A", "B", "C", "D"))); try (BufferedReader reader = new BufferedReader(new FileReader(filename))) { String line = reader.readLine(); assertThat(line, equalTo("A")); line = reader.readLine(); assertThat(line, equalTo("B")); line = reader.readLine(); assertThat(line, equalTo("C")); line = reader.readLine(); assertThat(line, equalTo("D")); line = reader.readLine(); assertThat(line, nullValue()); } }