Console app change StandardInputStream

I’m trying to write a helper app that has an ‘optional’ file name as a parameter, otherwise it reads StdIn.

Is there a way to assign the StandardInputStream to a TextInputStream property?

Easy to do and very common in C.

Dim inFile  As TextInputStream
Dim FileName As String

...read arguments
...set FileName if found

If Filename>"" then
  dim f as folderitem(filename)
  inFile = TextInputStream.Open(f)
else
  // this won't compile
  inFile = StandardInputStream
end if

dim t as string
t = inFile.Readall
... etc

You can’t store a reference to the StandardInputStream in a TextInputStream reference, however both of these classes implement the Readable class interface and so both can be stored in a Readable reference.

Bear in mind that this will mean you can only use methods that are part of the interface (e.g. “ReadAll” is not part of the interface).

Also note that “StandardInputStream” is the name of the class, not an instance of the class. Use the StdIn keyword to get the instance of StandardInputStream.

[code]Dim inFile As Readable
Dim FileName As String

…read arguments
…set FileName if found

If Filename>"" then
dim f as folderitem(filename)
inFile = TextInputStream.Open(f)
else
inFile = StdIn
end if
// now code without caring what inFile actually is
[/code]

[quote=380724:@Andrew Lambert]You can’t store a reference to the StandardInputStream in a TextInputStream reference, however both of these classes implement the Readable class interface and so both can be stored in a Readable reference.

Bear in mind that this will mean you can only use methods that are part of the interface (e.g. “ReadAll” is not part of the interface).

Also note that “StandardInputStream” is the name of the class, not an instance of the class. Use the StdIn keyword to get the instance of StandardInputStream.

[code]Dim inFile As Readable
Dim FileName As String

…read arguments
…set FileName if found

If Filename>"" then
dim f as folderitem(filename)
inFile = TextInputStream.Open(f)
else
inFile = StdIn
end if
// now code without caring what inFile actually is
[/code][/quote]

Thanks @Andrew Lambert
I can extend this with a ReadAll.
I’ve tried all sorts of base classes and casting.
Kept getting IllegalCastException.