Interface
Writeable
Description
Provides "specs" for classes with methods which can be used to write data to disk or ports.
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
text As String |
|||
Method descriptions
Writeable.Flush
Flush
Immediately sends the contents of internal write buffers to disk or to the output stream.
This function can be useful in point-to-point communication over sockets and similar connections: To optimize for transmission performance, some types of output streams try to collect small pieces of written data into one larger piece for sending instead of sending each piece out individually. By calling Flush, the data collection is stopped and the data is sent without further delay, reducing latency.
When using this on a stream that ends up as a file on disk, it is useful, too: Any short parts of previously written data are written to disk right away, ensuring the data is actually on disk if the application terminates abruptly, e.g. due to a crash.
Avoid calling this method too often. For example, do not call it between successive Write calls because you'll slow down performance without getting much benefit.
A typical use case would look like this:
mySocket.Write("you typed: ")
mySocket.Write(key)
mySocket.Write(".")
mySocket.Flush
Writeable.Write
Write(text As String)
Writes the passed data to the output stream.
Note that in order to make sure that the data actually ends up on disk or gets sent to the socket it is connected to, the stream must either get closed or the Flush method be called. Otherwise, the data, if small, may end up temporarily in a write buffer before either a certain time has passed or more data is written. This buffering increases performance when writing lots of small pieces of data, but may be causing unwanted delays when another process, e.g. the other end of a socket connection, is waiting for the data. Consider calling the Flush method to reduce latencies that this buffering may cause in such cases.
If Write fails, an IOException will be raised.
This example displays the Save As dialog box and writes the contents of the TextArea1 to a text file.
Var f As FolderItem
Var stream As BinaryStream
f = FolderItem.ShowSaveFileDialog(FileTypes1.Text, "Untitled.txt")
If f <> Nil Then
stream = BinaryStream.Create(f, True)
stream.Write(TextArea1.Text)
stream.Close
End If
Writeable.WriteError
WriteError As Boolean
If True then an error occurred during writing.
Notes
The BinaryStream, IPCSocket, SerialConnection, StdErr and StdOut (console applications only), TCPSocket, and TextOutputStream provide the Writeable class interface. If you implement this class interface in your application, you must provide the methods with the parameters as shown here.
Compatibility
All project types on all supported operating systems.
See also
BinaryStream, IPCSocket, SerialConnection, StdErr, StdOut, TCPSocket, TextOutputStream classes; Readable interface.