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

Diff of /classpath/java/io/FileOutputStream.java

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

revision 1.20 by mkoch, Tue Mar 25 12:20:50 2003 UTC revision 1.21 by mkoch, Fri Mar 28 08:39:16 2003 UTC
# Line 50  import gnu.java.nio.FileChannelImpl; Line 50  import gnu.java.nio.FileChannelImpl;
50   * This classes allows a stream of data to be written to a disk file or   * This classes allows a stream of data to be written to a disk file or
51   * any open <code>FileDescriptor</code>.   * any open <code>FileDescriptor</code>.
52   *   *
53   * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn <arenn@urbanophile.com>
54     * @author Tom Tromey <tromey@cygnus.com>
55   */   */
56  public class FileOutputStream extends OutputStream  public class FileOutputStream extends OutputStream
57  {  {
# Line 77  public class FileOutputStream extends Ou Line 78  public class FileOutputStream extends Ou
78     * @exception SecurityException If write access to the file is not allowed     * @exception SecurityException If write access to the file is not allowed
79     * @exception FileNotFoundException If a non-security error occurs     * @exception FileNotFoundException If a non-security error occurs
80     */     */
81    public FileOutputStream (String name, boolean append)    public FileOutputStream (String path, boolean append)
82      throws SecurityException, FileNotFoundException      throws SecurityException, FileNotFoundException
83    {    {
84      SecurityManager sm = System.getSecurityManager();      SecurityManager s = System.getSecurityManager();
85      if (sm != null)      if (s != null)
86        sm.checkWrite(name);        s.checkWrite(path);
87    
88      fd = new FileDescriptor();      fd = new FileDescriptor();
89    
90      try      try
91        {        {
92          if (append)          if (append)
93            fd.open(name, "a");            fd.open(path, "a");
94          else          else
95            fd.open(name, "w");            fd.open(path, "w");
96        }        }
97      catch(IOException e)      catch(IOException e)
98        {        {
99          throw new FileNotFoundException(name + ": " + e.getMessage());          throw new FileNotFoundException(path + ": " + e.getMessage());
100        }        }
101    }    }
102    
# Line 114  public class FileOutputStream extends Ou Line 115  public class FileOutputStream extends Ou
115     * @exception SecurityException If write access to the file is not allowed     * @exception SecurityException If write access to the file is not allowed
116     * @exception FileNotFoundException If a non-security error occurs     * @exception FileNotFoundException If a non-security error occurs
117     */     */
118    public    public FileOutputStream (String path)
119    FileOutputStream(String name) throws SecurityException, FileNotFoundException      throws SecurityException, FileNotFoundException
120    {    {
121      this (name, false);      this (path, false);
122    }    }
123    
124    /**    /**
# Line 184  public class FileOutputStream extends Ou Line 185  public class FileOutputStream extends Ou
185     *     *
186     * @exception SecurityException If write access to the file is not allowed     * @exception SecurityException If write access to the file is not allowed
187     */     */
188    public FileOutputStream (FileDescriptor fd) throws SecurityException    public FileOutputStream (FileDescriptor fdObj)
189        throws SecurityException
190    {    {
191      // Hmm, no other exception but this one to throw, but if the descriptor      // Hmm, no other exception but this one to throw, but if the descriptor
192      // isn't valid, we surely don't have "permission" to write to it.      // isn't valid, we surely don't have "permission" to write to it.
193      if (!fd.valid())      if (!fdObj.valid())
194        throw new SecurityException("Invalid FileDescriptor");        throw new SecurityException("Invalid FileDescriptor");
195    
196      SecurityManager sm = System.getSecurityManager();      SecurityManager s = System.getSecurityManager();
197      if (sm != null)      if (s != null)
198        sm.checkWrite(fd);        s.checkWrite(fdObj);
199    
200        fd = fdObj;
201      }
202    
203      this.fd = fd;    protected void finalize () throws IOException
204      {
205        // We don't actually need this, but we include it because it is
206        // mentioned in the JCL.
207    }    }
208    
209    /**    /**
# Line 233  public class FileOutputStream extends Ou Line 241  public class FileOutputStream extends Ou
241     *     *
242     * @exception IOException If an error occurs     * @exception IOException If an error occurs
243     */     */
244    public void write(byte[] buf) throws IOException    public void write (byte[] buf)
245        throws IOException
246    {    {
247      write (buf, 0, buf.length);      write (buf, 0, buf.length);
248    }    }
# Line 248  public class FileOutputStream extends Ou Line 257  public class FileOutputStream extends Ou
257     *     *
258     * @exception IOException If an error occurs     * @exception IOException If an error occurs
259     */     */
260    public void write(byte[] buf, int offset, int len) throws IOException    public void write (byte[] buf, int offset, int len)
261        throws IOException
262    {    {
263        if (offset < 0
264            || len < 0
265            || offset + len > buf.length)
266          throw new ArrayIndexOutOfBoundsException ();
267        
268      fd.write (buf, offset, len);      fd.write (buf, offset, len);
269    }    }
270    

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

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