Thanks Hong,
I was searching the examples (implementations) for
the patterns and here they are.
Is there any link/site where they explain about the
design patterns, those are implemented in various Java
API/Framework ? (Just as you explained).
As well as it is also valuable from interview point
of view.
Dipak.
--- "Yan, Hong [IT]" <[EMAIL PROTECTED]> wrote:
> The design of IO pakcage in Java follows two design
> patterns: decorator and
> adatper.
>
> FileWriter("fileName") wraps a File object into a
> FileWriter stream,
> therefore it is an adapter
> BufferWriter( Writer ) adds buffering capability to
> the Writer, which is a
> decorator pattern
> PrintWriter( Writer) again is a decorator.
>
> You will also see a symmtry in In and Out, 8bit and
> 16bit. Once you have
> these in mind, you may change your mind toward the
> design of Java io
> package. I would say it is probably the best IO
> package ever designed.
>
> rgds
>
> Jeff
>
> -----Original Message-----
> From: Greg Nudelman [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 21, 2002 2:03 PM
> To: JDJList
> Subject: [jdjlist] RE: Java IO Question
>
>
>
> This is one of a few things I find of extreme
> annoyance in Java. I do not
> think any other modern programming language makes
> you remember:
>
> new PrintWriter(new BufferedWriter(new
> FileWriter("foo.out")));
>
> just to get a file handle!! (This is one area where
> C syntax may even be
> easier to remember then Java... Scary!)
>
> I can never remember the syntax, as I have to write
> to a file maybe 5-6
> times a year. And just imagine being tested on an
> interview by some moron
> who just looked it up himself that very morning.
> ("Greg, how do you
> implement reading the binary file vs. ASCII file in
> Java?") So, Mr. Bright,
> how often do YOU write that code (without docs and
> Google)?
>
> Hmmm... Maybe I should just write my own utility
> that I can at least
> remember the syntax for.
>
> I'm thinking something like:
>
> BufferedFileWriter fw = new
> BufferedFileWriter("foo.out");
> fw.write(stringBuffer.toString());
>
>
> For PrintWriters:
>
> PrintingBufferedFileWriter pfw = new
> PrintingBufferedFileWriter("foo.out");
> pfw.print(stringBuffer.toString());
>
> To be fair, I guess I have the advantage - I can go
> back and refactor my
> stuff, and I do not need to be v1.0 backward
> compatible...
>
> Greg
>
>
> -----Original Message-----
> From: Sashi Guduri [ mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> ]
> Sent: Wednesday, August 21, 2002 6:14 AM
> To: JDJList
> Subject: [jdjlist] RE: Java IO Question
>
>
> "In general, a Writer sends its output immediately
> to the underlying
> character or byte stream. Unless prompt output is
> required, it is advisable
> to wrap a BufferedWriter around any Writer whose
> write() operations may be
> costly, such as FileWriters and OutputStreamWriters.
> For example,
>
> PrintWriter out
> = new PrintWriter(new BufferedWriter(new
> FileWriter("foo.out")));
> will buffer the PrintWriter's output to the file.
> Without buffering, each
> invocation of a print() method would cause
> characters to be converted into
> bytes that would then be written immediately to the
> file, which can be very
> inefficient."
>
> That was a direct quote from the javadoc for
> BufferedWriter....what happened
>
> to the old art of RTFM?
>
> And also, you want to use StringReader not
> StringBufferInputStream... as it
> is deprecated..Once again you would have found that
> out if have RTFM
>
> Sashi
>
> -----Original Message-----
> From: Abhilash Nair [ mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> ]
> Sent: Wednesday, August 21, 2002 8:48 AM
> To: JDJList
> Subject: [jdjlist] RE: Java IO Question
>
>
> Yes Scot. I meant quickest to execute...
> I've used StringBufferInputStream to read the data
> from a StringBuffer and a FileWriter to write it on
> to
> a text file to be stored in the local drive. Will
> substituting BufferedWriter in place of a FileWriter
>
> help the performance? Thanks for your suggestion.
>
> Regards,
> Abhi
>
> --- Scot Mcphee <[EMAIL PROTECTED]> wrote:
> > When you say quickest, do you mean quickest to
> code
> > or quickest to execute?
> > If you want quickest to execute I would use a
> > BufferedWriter. Actually I'd
> > use a BufferedWriter anyway.
> >
> > regs
> > scot.
> >
> > > -----Original Message-----
> > > From: Abhilash Nair [ mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> ]
> > > Sent: Wednesday, 21 August 2002 03:50
> > > To: JDJList
> > > Subject: [jdjlist] Java IO Question
> > >
> > >
> > > Hi All:
> > >
> > > Could anyone please suggest the fastest and most
>
> > > efficient way to transfer data from a
> StringBuffer
> > to
> > > a text file in the local drive?
> > >
> > > Thanks in Advance
> > > Abhi
> > >
> > > =====
> > > You can reach me on:
> > > Weekdays: (617)509-5312
> > > Weekends and evenings: (781)321-2065
> > > Pager: (781)553-8323
> > > Thanks and Regards,
> > > Nair Abhilash R
> > > (Abhi)
> > >
> > >
> __________________________________________________
> > > Do You Yahoo!?
> > > HotJobs - Search Thousands of New Jobs
> > > http://www.hotjobs.com <http://www.hotjobs.com>
>
> > >
> > > To change your membership options, refer to:
> > > http://www.sys-con.com/java/list.cfm
> <http://www.sys-con.com/java/list.cfm>
> > >
> >
> >
> > To change your membership options, refer to:
> > http://www.sys-con.com/java/list.cfm
> <http://www.sys-con.com/java/list.cfm>
>
>
> =====
> You can reach me on:
> Weekdays: (617)509-5312
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm