data-file-reader-bson
BSON File Format support.
This library adds BSON file format support to the DFR framework. If included in your project, the library will be automatically detected using Java’s ServiceLocator.
Certain file format conventions are enforced: Firstly, your file MUST be a plain array of objects. These objects must be simple key/value maps of only primitive types. In short, it needs to be the closest possible BSON-like abstraction of a table.
With that in mind, the BSON format does not place any restrictions on schema consistency - maps may be written with any number of elements. Because of this, please care when using file format adapters that require a strict schema (such as CSV).
<dependency> <groupId>net.krotscheck.dfr</groupId> <artifactId>data-file-reader-bson</artifactId> <version>1.0.10</version> </dependency>
Reading a BSON file
InputStream inputStream = ResourceUtil.getResourceAsStream("my_file.bson"); BSONDataDecoder decoder = new BSONDataDecoder(); decoder.setInputStream(inputStream); for(Map<String, Object> row : decoder) { // Do something } decoder.close();
Writing a BSON file
OutputStream outputStream = new FileOutputStream("my_file.bson"); IDataEncoder encoder = new BSONDataEncoder(outputStream); Map<String, Object> myRow = new LinkedHashMap<String, Object>(); encoder.write(myRow); encoder.close();