Current Page:
NeXtMidas Training
File Handlers
Introduction
Example
|
|
- Usage Example:
-
Generally when a primitive reads from a file, the delegation tree looks like this:
+----------------+
| Your Primitive | Wants to read elements
+----------------+ from a file
|
| file = MA.getFile(..)
| ...
| dataBuf = file.getDataBuffer(..) // A new buffer is created, DataFile object file is used to init the parameters
| ...
| numRead = file.read(dataBuf, numElements)
|
V
+----------------+
| File Handler | Knows how to interpret
+----------------+ a particular file type
|
| numBytes = numElements * bpe
| io.read(data.getBuf(), 0, numBytes)
|
V
+----------------+
| Resource Type | Knows how to read "raw"
+----------------+ bytes (i.e. low-level I/O)
|
|
V
+----------------+
| Data Source | The "data" (could be on
+----------------+ disk, via HTTP, etc.)
- For example, when DATALIST tries to access a CSV file
over HTTP...
nM> DATALIST http://myserver/myfile.csv
...it delegates the interpretation of the file to the CsvFile
file class. CsvFile knows how to interpret a CSV file from raw bytes, but
delegates the reading of those bytes to HttpResource which
knows how to read bytes via HTTP.
+----------------+
| DATALIST | Wants to read elements
+----------------+ from a CSV file
|
V
+----------------+
| CsvFile | Knows how to interpret a
+----------------+ CSV file given raw bytes
|
V
+----------------+
| HttpResource | Knows how to read bytes
+----------------+ over an HTTP socket
|
V
+----------------+
| Data via HTTP |
+----------------+
|
|
|