read (NotesStream - JavaScript)

Reads bytes from a stream.

Defined in

NotesStream

Syntax

read() : byte[]

read(length:int) : byte[]

Parameter Description
length The number of bytes to read to a maximum of 2GB. Defaults to the number of bytes in the stream starting at the current position to a maximum of 2GB.
Return value Description
byte[] The bytes read. The lower bound of the array is 0.

Usage

This method starts at getPosition and reads the number of bytes specified or the number of bytes left in the stream.

Examples

This button makes an exact copy of a file.
var inPath:string = requestScope.filepath;
var n:int = inPath.lastIndexOf(".");
var outPath:string = inPath.left(n) + "Copy" + inPath.right(inPath.length - n);
var inStream:NotesStream = session.createStream();
if (inStream.open(inPath, "binary")) {
	if (inStream.getBytes() > 0) {
		var outStream:NotesStream = session.createStream();
		if (outStream.open(outPath, "binary")) {
			if (!outStream.isReadOnly()) {
				do {
					var buffer = inStream.read(32767);
					outStream.write(buffer);
				} while (!inStream.isEOS());
			} else requestScope.status = "Output file exists and is read-only";
			outStream.close();
		} else requestScope.status = "Output file open failed";
	} else requestScope.status = "Input file has no content";
	inStream.close();
} else requestScope.status = "Input file open failed";