stream interview questions
Top stream frequently asked interview questions
What is the best way to copy the contents of one stream to another? Is there a standard utility method for this?
Source: (StackOverflow)
I am sending a stream to methods to write on, and in those methods I am using a binary reader/wrtier. When the reader/writer gets disposed, either by using
or just when it is not referenced, is the stream closed as well??
I would send a BinaryReader/Writer, but I am using a StreamReader too (maybe I should go around that. I am only using that for GetLine and ReadLine). This is quite troublesome if it closes the stream each time a writer/reader gets closed.
Source: (StackOverflow)
To redirect stdout to a truncated file in Bash, I know to use:
cmd > file.txt
To redirect stdout in Bash, appending to a file, I know to use:
cmd >> file.txt
To redirect both stdout and stderr to a truncated file, I know to use:
cmd &> file.txt
How do I redirect both stdout and stderr appending to a file? cmd &>> file.txt
did not work for me.
Source: (StackOverflow)
I am serializing an structure into a MemoryStream
and I want to save and load the serialized structure.
So, How to Save a MemoryStream
into a file and also load it back from file?
Source: (StackOverflow)
I'm developing my own social network, and I haven't found on the web examples of implementation the stream of users' actions... For example, how to filter actions for each users? How to store the action events? Which data model and object model can I use for the actions stream and for the actions itselves?
Source: (StackOverflow)
When you need to reset a stream to beginning (e.g. MemoryStream
) is it best practice to use
stream.Seek(0, SeekOrigin.Begin);
or
stream.Position = 0;
I've seen both work fine, but wondered if one was more correct than the other?
Source: (StackOverflow)
If you have java.io.InputStream
object, how should you process that object and produce a String
?
Suppose I have an InputStream
that contains text data, and I want to convert this to a String
(for example, so I can write the contents of the stream to a log file).
What is the easiest way to take the InputStream
and convert it to a String
?
public String convertStreamToString(InputStream is) {
// ???
}
Source: (StackOverflow)
I understand that a stream is a representation of a sequence of bytes. Each stream provides means for reading and writing bytes to its given backing store. But what is the point of the stream? Why isn't the backing store itself what we interact with?
For whatever reason this concept just isn't clicking for me. I've read a bunch of articles, but I think I need an analogy or something.
Source: (StackOverflow)
I know there are libs in other languages that can take a string that contains either a path to a local file or a url and open it as a readable IO stream.
Is there an easy way to do this in ruby?
Source: (StackOverflow)
I have several output listeners implementing OutputStream.
It can be PrintStream writing to stdout or to a File, it can be writing to memory or any other output destination therefore I specified OutputStream as argument in the method.
I have receiving the String. What is best way to write to streams here?
Just to use Writer.write(message.getBytes())? I give bytes but if destination stream is character stream then it will convert automatically?
Do I need to use here some bridge streams?
Thank you.
Source: (StackOverflow)
I have a StreamReader
object that I initialized with a stream, now I want to save this stream to disk (the stream may be a .gif
or .jpg
or .pdf
).
Existing Code:
StreamReader sr = new StreamReader(myOtherObject.InputStream);
- I need to save this to disk (I have the filename).
- In the future I may want to store this to SQL Server.
I have the encoding type also, which I will need if I store it to SQL Server, correct?
Source: (StackOverflow)
Can anyone explain in simple English about the differences between printf
, fprintf
, and sprintf
with examples?
What stream is it in?
I'm really confused between the three of these while reading about "File Handling in C".
Source: (StackOverflow)
I am using a library, ya-csv, that expects either a file or a stream as input, but I have a string.
How do I convert that string into a stream in Node?
Source: (StackOverflow)
What's the best way to pipe the output from an java.io.OutputStream to a String in Java?
Say I have the method:
writeToStream(Object o, OutputStream out)
Which writes certain data from the object to the given stream. However, I want to get this output into a String as easily as possible.
I'm considering writing a class like this (untested):
class StringOutputStream extends OutputStream {
StringBuilder mBuf;
public void write(int byte) throws IOException {
mBuf.append((char) byte);
}
public String getString() {
return mBuf.toString();
}
}
But is there a better way? I only want to run a test!
Source: (StackOverflow)