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

  • 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

  • stream: java.io.ByteArrayInputStream - An open InputStream created from the contents of the input bytes parameter.

Usage Notes

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

  • inputStream: java.io.InputStream. Optional - An open InputStream.
Note: 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.
  • reader: java.io.Reader.Optional - An open reader object.

Output Parameters

None.

Usage Notes

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

  • length: String. The length of the byte array to be created.

Output Parameters

  • bytes: Object The new byte array.

Usage Notes

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

  • stream: java.io.InputStream. Optional - The InputStream.
Note: 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

  • 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

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

  • stream: java.io.InputStream. Optional - The InputStream.
Note: 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

  • 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:
    • true indicates that the InputStream supports the mark and reset operations.
    • false indicates 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

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

  • 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

  • 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

  • reader: java.io.Reader - The reader object.

  • length: String - The maximum number of characters to read from the input reader object.

Output Parameters

  • 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

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

  • reader: java.io.Reader - The reader object.

Output Parameters

  • string: String - Data read from the reader object.

Usage Notes

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

  • stream: java.io.InputStream. Optional - The InputStream.

Note: 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

  • 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

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

  • stream: java.io.InputStream. Optional - The InputStream.
Note: 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

  • 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

The Skip service uses the Java methodskip, which might skip some smaller number of 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

  • stream: java.io.InputStream - The InputStream that you want to convert.

Output Parameters

  • bytes: byte[ ] - The bytes read from stream.

Usage Notes

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

  • 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

  • reader: java.io.Reader - The reader object read from inputStream.

streamToString

Creates a string from data that is read from an InputStream.

Input Parameters

  • 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

  • string: String - Data read from inputStream and converted to a string.

stringToReader

Converts a string object to a StringReader object.

Input Parameters

  • string: String - The string to convert to a StringReader object.

Output Parameters

  • reader: java.io.StringReader - The StringReader object.

stringToStream

Converts a string to a binary stream.

Input Parameters

  • 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

  • inputStream: java.io.ByteArrayInputStream - An open InputStream created from the contents of string.