IO services
Use IO services to convert data between byte[ ], characters, and InputStream representations. These services are used for reading and writing bytes, characters, and streamed data to the file system and behave like the corresponding methods in the java.io.InputStream class. These services can be started only by other services. Streams cannot be passed between clients and the server, so these services will not run if they are started from a client.
bytesToStream
Converts a byte[ ] to java.io.ByteArrayInputStream.
Input Parameters for bytesToStream
- bytes: byte[ ] - The byte array to convert.
- length: String Optional - The maximum number of bytes to read and convert. If length is not specified, the default value for this parameter is the length of the input byte array.
- offset: String Optional - The offset into the input byte array from which to start converting. If no value specified, the default value is zero.
Output Parameters for bytesToStream
- stream: java.io.ByteArrayInputStream - An open InputStream created from the contents of the input bytes parameter.
Usage Notes for bytesToStream
This service constructs stream from the byte array using the constructor ByteArrayInputStream(byte[ ]). This constructor does not make a copy of the byte array, so any changes to bytes will be reflected in the data read from the stream.
close
Closes an InputStream or a reader object and releases the resources.
Input parameters for close
- inputStream: java.io.InputStream. Optional - An open
InputStream.
You can use either inputStream or reader to specify the input object. If both the input parameters are provided, then both the objects are closed.
Output parameters for close
- reader: java.io.Reader.Optional - An open reader object.
Usage notes for close
If the InputStream is already closed, invoking this service has no effect. However, leaving an InputStream open can cause errors that might not be recoverable. Use the close service to explicitly close the input stream when a service leaves it open.
createByteArray
Creates a byte array of the specified length.
Input parameters for createByteArray
- length: String. The length of the byte array to be created.
Output parameters for createByteArray
- bytes: Object The new byte array.
Usage notes for createByteArray
The read service reads data from an InputStream into a byte array. You can use this service to
create the byte array. Invoking this service is the equivalent of the Java™ code new byte[length].
mark
Marks the current position in the InputStream or reader object. A subsequent call to reset repositions this stream at the last marked position. Marking and respositioning the input stream allows subsequent service calls to re-read the same bytes.
Input parameters for mark
- stream: java.io.InputStream. Optional - The InputStream.
You can use either stream or reader to specify the input object. If both stream and reader input parameters are provided, then both the objects will be marked.
-
reader: java.io.Reader. Optional - The reader object.
-
limit: String - The maximum number of bytes that can be read before the mark position becomes invalid. If more than this number of bytes are read from the stream after the mark service is started, the reset service will have no effect.
Output parameters for mark
- stream: java.io.InputStream. Conditional - The InputStream. Returned only if the input parameter is stream.
- reader: java.io.Reader. Conditional - The reader object. Returned only if the input parameter is reader.
Usage notes for mark
If the InputStream does not support the mark operation, invoking this service has no effect.
Either of the optional input parameters, stream or reader, is required.
markSupported
Enables you to test whether your InputStream or reader object supports the mark and reset operations.
Input parameters for markSupported
- stream: java.io.InputStream. Optional - The InputStream.
You can use either stream or reader to specify the input object. If both stream and reader input parameters are provided, then the stream input parameter is ignored.
- reader: java.io.Reader. Optional - The reader object.
Output parameters for markSupported
- stream: java.io.InputStream. Conditional - The InputStream. Returned only if the input parameter is stream.
- supported: String - Indicates whether the stream supports the mark and reset operations.
A value of:
trueindicates that the InputStream supports the mark and reset operations.falseindicates that the InputStream does not support the mark and reset operations.
-
reader: java.io.Reader. Conditional - The reader object. Returned only if the input parameter is reader.
Usage notes for markSupported
Either of the input parameters, stream or reader, is required.
read
Reads a specified number of bytes from the InputStream and stores them into a buffer.
Input parameters for read
- stream: Object - The InputStream. Object from which the service is to read bytes.
- offset: String. Optional - The offset into the byte array in the buffer to which the data is written. If no value is supplied, this defaults to 0.
- length: String. Optional - The maximum number of bytes to read from the InputStream. If no value is supplied, the default is the length of buffer. If the value supplied for length is greater than the length of buffer, an exception will be thrown.
-
buffer: Object - The buffer into which data is written. This is a byte array, which can be created from a flow service by invoking createByteArray.
Output parameters for read
-
stream: Object - The InputStream. If any bytes were read from the stream, the stream is repositioned after the last byte read.
-
buffer: Object - The buffer into which data was written.
-
bytesRead: String - The number of bytes read from the InputStream and copied to buffer. If there is no more data because the end of the stream has been reached, bytesRead will be -1.
readAsString
Reads the data from a reader object and returns the contents as a string.
Input parameters for readAsString
-
reader: java.io.Reader - The reader object.
-
length: String - The maximum number of characters to read from the input reader object.
Output parameters for readAsString
-
reader: java.io.Reader - The reader object.
-
lengthRead: String - The number of characters read from the input reader object. If there is no more data because the end of the stream has been reached, lengthRead will be -1.
-
value: String - The data read from the reader object, or null if end of stream has been reached.
Usage notes for readAsString
The readAsString service does not automatically close the reader object. To close the reader, use the close service.
readerToString
Reads the data from a reader object and converts it to a string.
Input parameters for readerToString
- reader: java.io.Reader - The reader object.
Output parameters for readerToString
- string: String - Data read from the reader object.
Usage notes for readerToString
The readerToString service does not automatically close the reader object. To close the reader, use the close service.
reset
Repositions the InputStream or the reader object to the position at the time the mark service was last started on the stream.
Input parameters for reset
-
stream: java.io.InputStream. Optional - The InputStream.
You use either stream or reader to specify the input object. If both stream and reader input parameters are provided, then both the objects will be reset.
- reader: java.io.Reader. Optional - The reader object.
Output parameters for reset
-
stream: java.io.InputStream. Conditional - The InputStream. Returned only if the input parameter is stream.
-
reader: java.io.Reader. Conditional - The reader object. Returned only if the input parameter is reader.
Usage notes for reset
If the InputStream does not support the reset operation, invoking this service has no effect.
Either of the input parameters, stream or reader, is required.
skip
Skips over and discards the specified number of bytes or characters from the input stream or a reader object.
Input parameters for skip
- stream: java.io.InputStream. Optional - The InputStream.
You can use either stream or reader to specify the input object. If both stream and reader input parameters are provided, then the stream and reader object data will be skipped.
- reader: java.io.Reader. Optional - The reader object.
- length: String - The number of bytes or characters to skip.
Output parameters for skip
- stream: java.io.InputStream. Conditional - The InputStream. Returned only if the input parameter is stream.
- reader: java.io.Reader. Conditional - The reader object. Returned only if the input parameter is reader.
- bytesSkipped: String. Conditional - The actual number of bytes that were skipped. Returned only if the input parameter is stream.
- charactersSkipped: String. Conditional - The number of characters that were skipped. Returned only if the input parameter is reader.
Usage notes for skip
The Skip service uses the Java method
skip, which might skip fewer bytes, possibly zero (0). This happens due to
conditions such as reaching the end of file before n bytes have been skipped. For more information
about the skip method, see the Java
documentation on the InputStream class.
Either of the optional input parameters, stream or reader, is required.
If both stream and reader input parameters are specified and if an exception occurs during the stream object usage, then the operations are not performed on the reader object also.
streamToBytes
Creates a byte[ ] from data that is read from an InputStream.
Input parameters for streamToBytes
- stream: java.io.InputStream - The InputStream that you want to convert.
Output parameters for streamToBytes
- bytes: byte[ ] - The bytes read from stream.
Usage notes for streamToBytes
This service reads all of the bytes from stream until the end of file is reached, and then it closes the InputStream.
streamToReader
Converts a java.io.InputStream to a java.io.Reader object.
Input Parameters for streamToReader
-
inputStream: java.io.InputStream - The InputStream to convert to a reader object.
-
encoding: String. Optional - Name of a registered, IANA character set (for example, ISO-8859-1). If you specify an unsupported encoding, the system throws an exception. If no value is specified or if the encoding is set to
autoDetect, the default operating system encoding is used.
Output Parameters for streamToReader
- reader: java.io.Reader - The reader object read from inputStream.
streamToString
Creates a string from data that is read from an InputStream.
Input parameters for streamToString
-
inputStream: java.io.InputStream - The InputStream to convert to a string.
-
encoding: String Optional - Name of a registered, IANA character set (for example, ISO-8859-1). If you specify an unsupported encoding, the system throws an exception. If no value is specified the encoding will be UTF-8.
Output parameters for streamToString
- string: String - Data read from inputStream and converted to a string.
stringToReader
Converts a string object to a StringReader object.
Input parameters for stringToReader
- string: String - The string to convert to a StringReader object.
Output parameters for stringToReader
- reader: java.io.StringReader - The StringReader object.
stringToStream
Converts a string to a binary stream.
Input parameters for stringToStream
-
string: String - The string object to be converted.
-
encoding: String - Optional. Name of a registered, IANA character set, for example, ISO-8859-1. If you specify an unsupported encoding, the system throws an exception. If no value is specified, the encoding will be UTF-8.
Output parameters for stringToStream
- inputStream: java.io.ByteArrayInputStream - An open InputStream created from the contents of string.