[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new return value of LocalDatabase.create in ozone-0.3
On Tue, 12 Oct 1999, Hannes Haug wrote:
> Falko Braeutigam wrote:
> >
> > StringWriter: Yes, maybe it's a bit strange but it was the first solution that
> > came in my mind. You can convert it to String and StringBuffer and no
> > conversion to String (creating a new object) is needed, if the output is not
> > used.
>
> StringWriter.getBuffer() doesn't create a new object and
> even toString's impact on db benchmarks shouldn't be that
> big.
>
> Another solution would be to have some additional create
> methods that take StringBuffers as additional arguments.
> This create methods could use
>
> class StringBufferWriter extends Writer {
> private final StringBuffer buf;
>
> public StringBufferWriter(StringBuffer buf) {
> this.buf = buf;
> }
>
> public void close() {}
> public void flush() {}
>
> public void write(char[] cbuf) {
> buf.append(cbuf);
> }
>
> public void write(char[] cbuf, int off, int len) {
> buf.append(cbuf, off, len);
> }
>
> public void write(int c) {
> buf.append((char)c);
> }
>
> public void write(String str) {
> buf.append(str);
> }
>
> public void write(String str, int off, int len) {
> buf.append(str.substring(off, off + len));
> }
> }
>
> So the logs would go to the StringBuffer.
>
>
> The old ones could use
>
> class NullWriter extends Writer {
> private final static NullWriter instance = new NullWriter();
>
> private NullWriter() {}
>
> public NullWriter getInstance() {
> return instance;
> }
>
> public void close() {}
> public void flush() {}
> public void write(char[] cbuf) {}
> public void write(char[] cbuf, int off, int len) {}
> public void write(int c) {}
> public void write(String str) {}
> public void write(String str, int off, int len) {}
> }
>
> In this case you save the creation of StringWriters and their
> internal StringBuffers.
great idea. LogWriter works like this but...
>
>
> But I don't think that it's worth the trouble. I'd just return a
> String.
... I agree, it's String now.
Falko
--
______________________________________________________________________
Falko Braeutigam mailto:falko@softwarebuero.de
softwarebuero m&b (SMB) http://www.softwarebuero.de