Data
buffer.Data
buffer is created in open()
just after
the file has been opened.
dataBuffer = inFile.getDataBuffer()
xfer
variable (provided by Primitive
)
that holds the transfer length.xfer
to be overridden by
the /TL=
switch using:
xfer = MA.getL("/TL", xfer);
process()
the data is read in from the file.
int numRead = inFile.read(dataBuffer)
numRead
is set to:
numRead > 0 |
numRead elements have been read. |
numRead = 0 |
No elements are ready for reading. |
numRead < 0 |
End of file has been reached. |
numRead
usually indicates the return value
from process()
:
numRead > 0 |
NORMAL |
numRead = 0 |
NOOP |
numRead < 0 |
FINISH |
public class myprim extends Primitive { private DataFile inFile; // The input file private Data dataBuffer; // The data buffer public int open() { inFile = MA.getDataFile("IN"); xfer = MA.getL("/TL", xfer); inFile.open(); dataBuffer = inFile.getDataBuffer(xfer); return NORMAL; } public int process() { int status = NORMAL; int numRead = inFile.read(dataBuffer); if (numRead < 0) { status = FINISH; // End of file } else if (numRead == 0) { status = NOOP; // No data ready, wait for pipe. } else { // Process the data } return status; } public int close() { inFile.close(); return NORMAL; } }
Don't Make This Mistake: |
---|
![]()
public int open() { inFile = MA.getFile("IN"); inFile.open(); // do this before reading in the next line outFile = MA.getFile("OUT); outFile.open(); ... } |