Activity - readFile
Activity Type: Indexed File
Description
Reads data from one or more binary or text files stored on
the server. The file data is then written to an output which can
be connected to another activity or delivered back to the user in
the response document.
Examples
To read 9 bytes from the some/file.ext file,
starting immediately after byte number 3, and to output the file data
as a string without base-64 encoding it:
<readFile name="read">
<file>some/file.ext</file>
<bytes offset="3" length="9"/>
<output name="fileAccessOutput" base64encode="false"/>
</readFile>
To read 5 lines from the some/file.ext
text file, starting immediately after line number 2, and to
output the data as a base-64 encoded string:
<readFile name="read">
<file>some/file.ext</file>
<lines offset="2" length="5"/>
<output name="fileAccessOutput" base64encode="true"/>
</readFile>
To read data from one or more files and to base-64 encode the
resulting data. The description of what data to read must be
produced by another activity and connected to the
fromLocal input:
<readFile name="read">
<fromLocal from="searchOutput"/>
<output name="fileAccessOutput" base64encode="true"/>
</readFile>
Specification
Element readFile:
-
Attribute name - unique name for the
activity within the scope of a request.
-
One of the following element groups, either:
-
Element fromLocal -
refers to the output stream of another activity.
-
Attribute from - name of an input stream
providing the data to deliver.
-
Or:
-
Element file -
contains the path to the file to access. This path should be
relative to the top-level directory exposed by the associated
OGSA-DAI service and must not attempt to traverse up the directory
hierarchy higher than this directory.
-
One of the following two elements (required):
-
Element bytes - access the
contents of a file on a byte-by-byte basis.
-
Attribute offset - index of first byte to
access, starting at 0.
-
Attribute length - number of bytes to
access or -1 to read all bytes until the end of file.
-
Element lines - access the
contents of a file on a line-by-line basis.
-
Attribute offset - index of first line to
access, starting at 0.
-
Attribute length - number of lines to
access or -1 to read all lines until the end of file.
-
output (required) - output
stream.
-
Attribute name - name of the activity's
output stream.
-
Attribute base64encode - flag indicating
whether the output will be base64 encoded (true) or not (false).
Input and Output Types
-
Input: fromLocal (optional)
— String of XML data where each block
contains a <readFile> element conforming
to the same specification described above. If used, this input allows
the readFile activity to perfrom multiple
file reading operations.
-
Output: output — String
or byte[] data containing the requested file
contents. If the contents have been accessed on a line-by-line basis then
each data block is a plain string or base-64 encoded string, depending on
the value of the base64encode attribute for the activity.
If the contents have been accessed on a byte-by-byte bases the data is a
plain byte array or a base-64 encoded byte array, depending on the value of
the base64encode attribute for the activity.
If multiple file reading operations are performed, the
output will contain a sequence of data from multiple files.
Warning to Service Deployers
This activity can be used by clients to potentially access
any directory on your server below
that exposed by the associated OGSA-DAI service.
Data Resource Accessor
This activity requires a data resource accessor that implements the following
interface:
uk.org.ogsadai.dataresource.FileAccessProvider
XML Schema
OGSA-DAI/schema/ogsadai/xsd/activities/file_reading.xsd
Class
uk.org.ogsadai.activity.indexedfiles.FileReadingActivity
Client Toolkit Class
uk.org.ogsadai.client.toolkit.activity.indexedfiles.ReadFile