Re: Fav. Memory Stream Impl.
On Nov 28, 9:10 am, Jan Burse <janbu...@fastmail.fm> wrote:
Robert Klemme schrieb:
Basically if you want to use other libraries which depend on java.io to
open files you have little chance to smuggle a "memory stream" in there
without going through the effort to modify byte code of classes.
No, I don't think that the above claim is right. Look see what
is written for the class InputStream:
This abstract class is the superclass of
all classes representing an input
stream of bytes.
http://docs.oracle.com/javase/1.4.2/docs/api/java/io/Input=
Stream.html
So with proper OO I could implement:
class MemoryStream {
InputStream createInput();
}
class MemoryInput extens InputStream {
...
}
The factory method could return a MemoryInput instance
from a MemoryStream instance. Similarly I could
provide OutputStrem createOutput etc..
The MemoryStream would be not the first stream that
has been created outside of java.lang via proper OO.
Think for example of the request and respons streams
of a web server. They are also made like this.
And how do you make library code use your memory stream factory
class? Remember, there will by typically a line like this somewhere
FileInputStream fileIn = new FileInputStream(fileName);
There is no factory. There is just an invocation of the constructor.
From what you write I get the impression that you are hooked into your
idea of using in memory piles of bytes as replacement for temporary
files because it looks like a good idea (and simple to do) on first
sight. But I haven't seen anything so far which would convince me
that it's really a good idea altogether.
Kind regards
robert