Write( ) method (MemoryOutputStream)

Writes data from specified input parameters to a MemoryOutputStream object. Returns the total number of characters written for CHARACTER and LONGCHAR data parameter, or the total number of bytes written for a MEMPTR parameter.

Return type: INT64

Access: PUBLIC

Applies to:Progress.IO.MemoryOutputStream class

Syntax

Write(INPUT source-data AS MEMPTR, INPUT offset AS INT64,INPUT length AS INT64)
Write(INPUT source-data AS  CHARACTER)
Write(INPUT source-data AS  CHARACTER, INPUT incldNull AS LOGICAL)
Write(INPUT source-data AS LONGCHAR)
Write(INPUT source-data AS LONGCHAR, INPUT incldNull AS LOGICAL))
source-data
A CHARACTER, LONGCHAR, or MEMPTR variable containing the data the method will write to the MemoryOutputStream object.
Note: The AVM converts LONGCHAR data values to the code page specified by the -cpinternal parameter.
offset
Indicates which byte of the source-data MEMPTR the method should start with when writing to the current MemoryOutputStream object.
length
Number of bytes to write to the MemoryOutputStream object.
incldNull
If set to TRUE, includes the null terminator in CHARACTER or LONGCHAR data written to the current MemoryOutputStream object.

Example

DEFINE VAR outMs  AS Progress.io.MemoryOutputStream. 
DEFINE VAR mem    AS MEMPTR.
DEFINE VAR len    AS INT64.
DEFINE VAR ret    AS INT64.
DEFINE VAR mylc   AS LONGCHAR.

outMs  = NEW Progress.io.MemoryOutputStream().
mylc = "123456789".
ret = outMs:Write(mylc,yes).
MESSAGE ret " == " outMs:BytesWritten " == " 10 VIEW-AS ALERT-BOX.

outMs:Clear().

outMs  = NEW Progress.io.MemoryOutputStream().
mylc = "123456789".
ret = outMs:Write(mylc). //null terminator will be exclued
MESSAGE ret " == " outMs:BytesWritten " == " 9 VIEW-AS ALERT-BOX.

outMs:Clear().

SET-SIZE(mem) = 11.
PUT-STRING(mem,1) = "123456789".
ret = outMs:Write(mem, 1, LENGTH(STRING(mem))).
MESSAGE "123456789 == " STRING(outMs:Data)  VIEW-AS ALERT-BOX. 

Note

The following table illustrates values that result from constructors and Write( )/Clear( ) methods:

Method/Constructor Values
Obj:Length Obj:BytesWritten
Obj = NEW MemoryOutputStream() 0 0
Obj:Write(“12345�) 5 5
Obj:Clear() 0 0
Obj = NEW MemoryOutputStream(100) 100 0
Obj:Write(“12345678�) 100 8
Obj:Clear() 100 0