/[classpath]/classpath/java/io/Writer.java
ViewVC logotype

Diff of /classpath/java/io/Writer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by mark, Tue Jan 22 22:26:59 2002 UTC revision 1.8 by arenn, Sun Mar 9 21:54:37 2003 UTC
# Line 1  Line 1 
1  /* Writer.java -- Base class for character output streams  /* Writer.java -- Base class for character output streams
2     Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.     Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 55  package java.io; Line 55  package java.io;
55    */    */
56  public abstract class Writer  public abstract class Writer
57  {  {
58      /**
59  /*************************************************************************/      * This is the object used to synchronize criticial code sections for
60        * thread safety.  Subclasses should use this field instead of using
61  /**      * synchronized methods or explicity synchronizations on <code>this</code>
62    * This is the object used to synchronize criticial code sections for      */
63    * thread safety.  Subclasses should use this field instead of using    protected Object lock;
64    * synchronized methods or explicity synchronizations on <code>this</code>  
65    */    /*************************************************************************/
66  protected Object lock;  
67      /*
68  /*************************************************************************/     * Constructors
69       */
70  /*  
71   * Constructors    /**
72   */      * This is the default no-argument constructor for this class.  This method
73        * will set up the class to synchronize criticial sections on itself.
74  /**      */
75    * This is the default no-argument constructor for this class.  This method    protected Writer()
76    * will set up the class to synchronize criticial sections on itself.    {
77    */      lock = this;
78  protected    }
79  Writer()  
80  {    /*************************************************************************/
81    lock = this;  
82  }    /**
83        * This method initializes a <code>Writer</code> that will synchronize
84  /*************************************************************************/      * on the specified <code>Object</code>.
85        *
86  /**      * @param obj The <code>Object</code> to use for synchronizing critical
87    * This method initializes a <code>Writer</code> that will synchronize      *            sections
88    * on the specified <code>Object</code>.      */
89    *    protected Writer(Object lock)
90    * @param obj The <code>Object</code> to use for synchronizing critical    {
91    *            sections      this.lock = lock;
92    */    }
93  protected  
94  Writer(Object lock)    /*************************************************************************/
95  {  
96    this.lock = lock;    /*
97  }     * Instance Methods
98       */
99  /*************************************************************************/  
100      /**
101  /*      * This method forces any data that may have been buffered to be written
102   * Instance Methods      * to the underlying output device.  Please note that the host environment
103   */      * might perform its own buffering unbeknowst to Java.  In that case, a
104        * write made (for example, to a disk drive) might be cached in OS
105  /**      * buffers instead of actually being written to disk.
106    * This method forces any data that may have been buffered to be written      *
107    * to the underlying output device.  Please note that the host environment      * @exception IOException If an error occurs
108    * might perform its own buffering unbeknowst to Java.  In that case, a      */
109    * write made (for example, to a disk drive) might be cached in OS    public abstract void flush() throws IOException;
110    * buffers instead of actually being written to disk.  
111    *    /*************************************************************************/
112    * @exception IOException If an error occurs  
113    */    /**
114  public abstract void      * This method closes the stream.  Any internal or native resources
115  flush() throws IOException;      * associated
116        * with this stream are freed.  Any subsequent attempt to access the stream
117  /*************************************************************************/      * might throw an exception.
118        * <p>
119  /**      * This method in this class does nothing.
120    * This method closes the stream.  Any internal or native resources associated      *
121    * with this stream are freed.  Any subsequent attempt to access the stream      * @exception IOException If an error occurs
122    * might throw an exception.      */
123    * <p>    public abstract void close() throws IOException;
124    * This method in this class does nothing.  
125    *    /*************************************************************************/
126    * @exception IOException If an error occurs  
127    */    /**
128  public abstract void      * This method writes a single char to the output stream.
129  close() throws IOException;      *
130        * @param b The char to be written to the output stream, passed as an int
131  /*************************************************************************/      *
132        * @exception IOException If an error occurs
133  /**      */
134    * This method writes a single char to the output stream.    public void write(int b) throws IOException
135    *    {
136    * @param b The char to be written to the output stream, passed as an int      char[] buf = new char[1];
137    *  
138    * @exception IOException If an error occurs      buf[0] = (char)b;
139    */      write(buf, 0, buf.length);
140  public void    }
141  write(int b) throws IOException  
142  {    /*************************************************************************/
143    char[] buf = new char[1];  
144      /**
145    buf[0] = (char)b;      * This method all the writes char from the passed array to the output
146    write(buf, 0, buf.length);      * stream. This method is equivalent to
147  }      * <code>write(buf, 0, buf.length)</code> which
148        * is exactly how it is implemented in this class.
149  /*************************************************************************/      *
150        * @param buf The array of char to write
151  /**      *
152    * This method all the writes char from the passed array to the output stream.      * @exception IOException If an error occurs
153    * This method is equivalent to <code>write(buf, 0, buf.length)</code> which      */
154    * is exactly how it is implemented in this class.    public void write(char[] buf) throws IOException
155    *    {
156    * @param buf The array of char to write      write(buf, 0, buf.length);
157    *    }
158    * @exception IOException If an error occurs  
159    */    /*************************************************************************/
160  public void  
161  write(char[] buf) throws IOException    /**
162  {      * This method writes <code>len</code> char from the specified array
163    write(buf, 0, buf.length);      * <code>buf</code> starting at index <code>offset</code> into the array.
164  }      * <p>
165        * Subclasses must provide an implementation of this abstract method.
166  /*************************************************************************/      *
167        * @param buf The array of char to write from
168  /**      * @param offset The index into the array to start writing from
169    * This method writes <code>len</code> char from the specified array      * @param len The number of char to write
170    * <code>buf</code> starting at index <code>offset</code> into the array.      *
171    * <p>      * @exception IOException If an error occurs
172    * Subclasses must provide an implementation of this abstract method.      */
173    *    public abstract void write(char[] buf, int offset, int len)
174    * @param buf The array of char to write from      throws IOException;
175    * @param offset The index into the array to start writing from  
176    * @param len The number of char to write    /*************************************************************************/
177    *  
178    * @exception IOException If an error occurs    /**
179    */      * This method writes all the characters in a <code>String</code> to the
180  public abstract void      * output.
181  write(char[] buf, int offset, int len) throws IOException;      *
182        * @param str The <code>String</code> whose chars are to be written.
183  /*************************************************************************/      *
184        * @param IOException If an error occurs
185  /**      */
186    * This method writes all the characters in a <code>String</code> to the    public void write(String str) throws IOException
187    * output.    {
188    *      write(str, 0, str.length());
189    * @param str The <code>String</code> whose chars are to be written.    }
190    *  
191    * @param IOException If an error occurs    /*************************************************************************/
192    */  
193  public void    /**
194  write(String str) throws IOException      * This method writes <code>len</code> chars from the <code>String</code>
195  {      * starting at position <code>offset</code>.
196    write(str, 0, str.length());      *
197  }      * @param str The <code>String</code> that is to be written
198        * @param offset The character offset into the <code>String</code> to start
199  /*************************************************************************/      *               writing from
200        * @param len The number of chars to write
201  /**      *
202    * This method writes <code>len</code> chars from the <code>String</code>      * @exception IOException If an error occurs
203    * starting at position <code>offset</code>.      */
204    *    public void write(String str, int offset, int len) throws IOException
205    * @param str The <code>String</code> that is to be written    {
206    * @param offset The character offset into the <code>String</code> to start      // FIXME - for libgcj re-write using native code to not require
207    *               writing from      // copied buffer.
208    * @param len The number of chars to write      char[] buf = new char[len];
209    *  
210    * @exception IOException If an error occurs      str.getChars(offset, offset + len, buf, 0);
211    */      write(buf, 0, len);
212  public void    }
 write(String str, int offset, int len) throws IOException  
 {  
   // FIXME - for libgcj re-write using native code to not require copied buffer.  
   char[] buf = new char[len];  
   
   str.getChars(offset, offset + len, buf, 0);  
   write(buf, 0, len);  
 }  
213    
214  } // class Writer  } // class Writer
215    

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26