How can I "modify" an InputStream? I have a file as input, I would like to modify some variable and forward a new InputStream.
For example, the initial InputStream contains Hello ${var}. Then I want to "modify" this InputStream with var = "world", resulting an InputStream Hello world.
What's the best practice to do this? Thanks.
This method returns the MIME type of the data in the form of a string. InputStream. getInputStream() This method returns an InputStream representing the data and throws the appropriate exception if it can not do so.
The InputStream is used to read data from a source and the OutputStream is used for writing data to a destination. Here is a hierarchy of classes to deal with Input and Output streams. The two important streams are FileInputStream and FileOutputStream, which would be discussed in this tutorial.
waitFor. Causes the current thread to wait, if necessary, until the subprocess represented by this Process object has terminated, or the specified waiting time elapses.
Process provides control of native processes started by ProcessBuilder. start and Runtime. exec. The class provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
The java.io
is one and all decorator pattern. Make use of it and create a class which extends InputStream
(maybe DataInputStream
or better, some Reader
since you're actually interested in characters, not in bytes, but ala), add a constructor which takes the original InputStream
and override the read()
methods to read the original stream in, buffer it to a certain degree (e.g. from ${
until with firstnext }
) and then determine the key and return the modified data instead.
If you call your new class FormattedInputStream
or so, then you could return new FormattedInputStream(originalInputStream)
to the enduser instead and have the enduser still just assign and use it as an InputStream
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With