|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.org.ogsadai.activity.Activity | +--uk.org.ogsadai.activity.files.AbstractFileActivity | +--uk.org.ogsadai.activity.indexedfiles.FileReadingActivity
An activity to read 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. See the activity user documentation for more details: OGSADAI/doc/interaction/activities/indexedfiles/readFile.html
Field Summary | |
private static int |
BLOCK_SIZE
Size of blocks when retrieving bytes from random access file (1024) |
private static java.lang.String |
COPYRIGHT_NOTICE
Copyright statement |
private static DAILogger |
LOG
Logger object for logging in this class |
private boolean |
mBase64encode
Is the output base64 encoded? |
private java.io.RandomAccessFile |
mBinaryFile
Random access file |
private java.io.File |
mFile
Text / random access file |
private java.lang.String |
mFilename
Name of the text or random access file |
private BlockReader |
mInput
Activity input - names of files to read |
private boolean |
mIsBinaryFile
Do we have a binary/random access or a text file? |
private long |
mLength
Number of bytes or lines to be read, -1 if reading to the end of the file |
private long |
mOffset
Offset - skipped bytes or lines |
private BlockWriter |
mOutput
Activity output - bytes/lines read |
private java.io.BufferedReader |
mTextFile
Text file reader |
Fields inherited from class uk.org.ogsadai.activity.files.AbstractFileActivity |
mCredentials, mFileAccessProvider, mTopDir |
Fields inherited from class uk.org.ogsadai.activity.Activity |
mContext, mExternalInputs, mExternalOutputs, mInternalInputs, mInternalOutputs |
Constructor Summary | |
FileReadingActivity(org.w3c.dom.Element element)
|
Method Summary | |
protected void |
cleanUp()
This method can be overridden by any Activity
implementations that need to free up resources in the event of
an error or intermediate termination of the activity
processing. |
private boolean |
hasNextFile()
Checks if there is another instruction waiting in the input stream and retrieves filename, offset and length. |
void |
initialise()
Gets the data resource accessor for the files data resource according to whether the users credentials permit this access. |
private boolean |
openFile(java.lang.String filename)
Opens a file and skips mOffset lines or bytes |
private void |
parseOffsetAndLength(java.lang.String namespace,
org.w3c.dom.Element element)
Extracts offset and length attributes
from an element that contains either a bytes or
lines subelement and stores these. |
protected void |
processBlock()
Performs an iteration of the processing of an activity. |
protected void |
processFirst()
This method is called during the first iteration of processing an activity. |
private int |
readFromBinaryFile()
Reads a block of bytes from a file (at most mLength bytes), and puts it into the output stream |
private boolean |
readFromTextFile()
Reads one line from a text file mLength is the remaining number of lines to read |
Methods inherited from class uk.org.ogsadai.activity.Activity |
connectsTo, createOutputPipe, getActivityConfiguration, getActivityName, getCause, getName, getObservableStatus, getProperties, getSession, getStatus, hasActivityConfiguration, hasProperties, process, setActivityName, setCompleted, setError |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final java.lang.String COPYRIGHT_NOTICE
private static final DAILogger LOG
private static final int BLOCK_SIZE
private java.lang.String mFilename
private java.io.File mFile
private java.io.RandomAccessFile mBinaryFile
private java.io.BufferedReader mTextFile
private boolean mBase64encode
private boolean mIsBinaryFile
private long mOffset
private long mLength
private BlockWriter mOutput
private BlockReader mInput
Constructor Detail |
public FileReadingActivity(org.w3c.dom.Element element) throws ActivityCreationException, ActivitySpecificationException
Method Detail |
public void initialise() throws ActivitySpecificationException, ActivityExecutionException
AbstractFileActivity
initialise
in class AbstractFileActivity
ActivitySpecificationException
- If the user is not permitted to access the resource.
ActivityExecutionException
- If some internal problem occurs.Activity.initialise()
protected void processFirst()
Activity
processFirst
in class Activity
protected void processBlock()
Activity
setCompleted
method to indicate that
processing is complete, or the setError
method if
an error occurs that will prevent the processing from
completing.
processBlock
in class Activity
protected void cleanUp()
Activity
Activity
implementations that need to free up resources in the event of
an error or intermediate termination of the activity
processing.
cleanUp
in class Activity
private boolean readFromTextFile() throws DAIFileReadIOException
mLength
is the remaining number of lines to read
DAIFileReadIOException
- If there is a problem.private int readFromBinaryFile() throws DAIFileReadIOException
mLength
bytes), and puts it into the output stream
DAIFileReadIOException
- If there is a problem.private boolean hasNextFile() throws ActivitySpecificationException, ActivityExecutionException
The instruction is expected to be of form:
<readFile> <file>FILE</file> <bytes offset="M" length="M"/> </readFile>or
<readFile> <file>FILE</file> <lines offset="M" length="M"/> </readFile>
true
if there is another instruction to
process, false
if there are no more instructions
or the input stream is null
.
ActivitySpecificationException
- If the instruction format is not as expected, the file name
is missing, the offset and length are not numbers or are <
0.
ActivityExecutionException
- If an internal parsing-related problem occurs.private void parseOffsetAndLength(java.lang.String namespace, org.w3c.dom.Element element) throws ActivitySpecificationException
offset
and length
attributes
from an element that contains either a bytes
or
lines
subelement and stores these.
namespace
- Namespace of elements in element
.element
- Element to parse.
ActivitySpecificationException
- If the offset and length are not numbers or are < 0.private boolean openFile(java.lang.String filename) throws ActivitySpecificationException, ActivityExecutionException
mOffset
lines or bytes
filename
- Name of file to open.
true
if the file has been openend and the
cursor is positioned after the offset, false
if
the file is not open (e.g. because the offset is larger than
the length of the file
ActivitySpecificationException
- If the file does not exist or is outside the
root directory
ActivityExecutionException
- If some internal problem arises.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |