<read-from-stream>

Purpose/Function

Allows for incremental reading from an open stream. The stream object is to be placed into the environment, then accessed by this task (see WrapResource).

If EOF is encountered, or the number of bytes read is <= 0, the return value will be null.

Attributes

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

stream

java.io.InputStream

(required)

stream wrapping file, string or resource

mark

boolean

false

call stream.mark( bytes.length ) after the read

reset

boolean

false

call stream.reset() after the read

numBytes

int

1024

number of bytes to attempt to read (= buffer size)

returnString

boolean

true

assign return value as string (otherwise, as array of bytes

Elements

None.

ReturnValues

DEFAULT NAME

TYPE

DESCRIPTION

bytes

byte[] or java.lang.String

result of the read

Examples

<ogrescript>
	<wrap-resource name="stream" declare="true" type="input" resource="review.txt"/>
	
        <declare name="byteList">
                </list>
        </declare>
	
	<for var="i" from="0" to="2">
                <declare name="bytes"/>
		<read-from-stream stream="${stream}" returnString="true">
			<return-value defaultName="bytes"/>
		</read-from-stream>
                <add collection="${byteList}" string="${bytes}"/>
	</for>
        <close toClose="${stream}"/>
</ogrescript>
  • No labels