示例#1
0
        /// <summary>
        /// Creates a file output stream to write to the specified file
        /// descriptor, which represents an existing connection to an actual
        /// file in the file system.
        /// <para>
        /// First, if there is a security manager, its <code>checkWrite</code>
        /// method is called with the file descriptor <code>fdObj</code>
        /// argument as its argument.
        /// </para>
        /// <para>
        /// If <code>fdObj</code> is null then a <code>NullPointerException</code>
        /// is thrown.
        /// </para>
        /// <para>
        /// This constructor does not throw an exception if <code>fdObj</code>
        /// is <seealso cref="java.io.FileDescriptor#valid() invalid"/>.
        /// However, if the methods are invoked on the resulting stream to attempt
        /// I/O on the stream, an <code>IOException</code> is thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="fdObj">   the file descriptor to be opened for writing </param>
        /// <exception cref="SecurityException">  if a security manager exists and its
        ///               <code>checkWrite</code> method denies
        ///               write access to the file descriptor </exception>
        /// <seealso cref=        java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) </seealso>
        public FileOutputStream(FileDescriptor fdObj)
        {
            SecurityManager security = System.SecurityManager;

            if (fdObj == null)
            {
                throw new NullPointerException();
            }
            if (security != null)
            {
                security.CheckWrite(fdObj);
            }
            this.Fd     = fdObj;
            this.Append = false;
            this.Path   = null;

            Fd.Attach(this);
        }
示例#2
0
        /// <summary>
        /// Creates a <code>FileInputStream</code> by using the file descriptor
        /// <code>fdObj</code>, which represents an existing connection to an
        /// actual file in the file system.
        /// <para>
        /// If there is a security manager, its <code>checkRead</code> method is
        /// called with the file descriptor <code>fdObj</code> as its argument to
        /// see if it's ok to read the file descriptor. If read access is denied
        /// to the file descriptor a <code>SecurityException</code> is thrown.
        /// </para>
        /// <para>
        /// If <code>fdObj</code> is null then a <code>NullPointerException</code>
        /// is thrown.
        /// </para>
        /// <para>
        /// This constructor does not throw an exception if <code>fdObj</code>
        /// is <seealso cref="java.io.FileDescriptor#valid() invalid"/>.
        /// However, if the methods are invoked on the resulting stream to attempt
        /// I/O on the stream, an <code>IOException</code> is thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="fdObj">   the file descriptor to be opened for reading. </param>
        /// <exception cref="SecurityException">      if a security manager exists and its
        ///                 <code>checkRead</code> method denies read access to the
        ///                 file descriptor. </exception>
        /// <seealso cref=        SecurityManager#checkRead(java.io.FileDescriptor) </seealso>
        public FileInputStream(FileDescriptor fdObj)
        {
            SecurityManager security = System.SecurityManager;

            if (fdObj == null)
            {
                throw new NullPointerException();
            }
            if (security != null)
            {
                security.CheckRead(fdObj);
            }
            Fd   = fdObj;
            Path = null;

            /*
             * FileDescriptor is being shared by streams.
             * Register this stream with FileDescriptor tracker.
             */
            Fd.Attach(this);
        }
示例#3
0
        /// <summary>
        /// Creates a <code>FileInputStream</code> by
        /// opening a connection to an actual file,
        /// the file named by the <code>File</code>
        /// object <code>file</code> in the file system.
        /// A new <code>FileDescriptor</code> object
        /// is created to represent this file connection.
        /// <para>
        /// First, if there is a security manager,
        /// its <code>checkRead</code> method  is called
        /// with the path represented by the <code>file</code>
        /// argument as its argument.
        /// </para>
        /// <para>
        /// If the named file does not exist, is a directory rather than a regular
        /// file, or for some other reason cannot be opened for reading then a
        /// <code>FileNotFoundException</code> is thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="file">   the file to be opened for reading. </param>
        /// <exception cref="FileNotFoundException">  if the file does not exist,
        ///                   is a directory rather than a regular file,
        ///                   or for some other reason cannot be opened for
        ///                   reading. </exception>
        /// <exception cref="SecurityException">      if a security manager exists and its
        ///               <code>checkRead</code> method denies read access to the file. </exception>
        /// <seealso cref=        java.io.File#getPath() </seealso>
        /// <seealso cref=        java.lang.SecurityManager#checkRead(java.lang.String) </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public FileInputStream(File file) throws FileNotFoundException
        public FileInputStream(File file)
        {
            String          name     = (file != null ? file.Path : null);
            SecurityManager security = System.SecurityManager;

            if (security != null)
            {
                security.CheckRead(name);
            }
            if (name == null)
            {
                throw new NullPointerException();
            }
            if (file.Invalid)
            {
                throw new FileNotFoundException("Invalid file path");
            }
            Fd = new FileDescriptor();
            Fd.Attach(this);
            Path = name;
            Open(name);
        }
示例#4
0
        /// <summary>
        /// Creates a file output stream to write to the file represented by
        /// the specified <code>File</code> object. If the second argument is
        /// <code>true</code>, then bytes will be written to the end of the file
        /// rather than the beginning. A new <code>FileDescriptor</code> object is
        /// created to represent this file connection.
        /// <para>
        /// First, if there is a security manager, its <code>checkWrite</code>
        /// method is called with the path represented by the <code>file</code>
        /// argument as its argument.
        /// </para>
        /// <para>
        /// If the file exists but is a directory rather than a regular file, does
        /// not exist but cannot be created, or cannot be opened for any other
        /// reason then a <code>FileNotFoundException</code> is thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="file">               the file to be opened for writing. </param>
        /// <param name="append">      if <code>true</code>, then bytes will be written
        ///                   to the end of the file rather than the beginning </param>
        /// <exception cref="FileNotFoundException">  if the file exists but is a directory
        ///                   rather than a regular file, does not exist but cannot
        ///                   be created, or cannot be opened for any other reason </exception>
        /// <exception cref="SecurityException">  if a security manager exists and its
        ///               <code>checkWrite</code> method denies write access
        ///               to the file. </exception>
        /// <seealso cref=        java.io.File#getPath() </seealso>
        /// <seealso cref=        java.lang.SecurityException </seealso>
        /// <seealso cref=        java.lang.SecurityManager#checkWrite(java.lang.String)
        /// @since 1.4 </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public FileOutputStream(File file, boolean append) throws FileNotFoundException
        public FileOutputStream(File file, bool append)
        {
            String          name     = (file != null ? file.Path : null);
            SecurityManager security = System.SecurityManager;

            if (security != null)
            {
                security.CheckWrite(name);
            }
            if (name == null)
            {
                throw new NullPointerException();
            }
            if (file.Invalid)
            {
                throw new FileNotFoundException("Invalid file path");
            }
            this.Fd = new FileDescriptor();
            Fd.Attach(this);
            this.Append = append;
            this.Path   = name;

            Open(name, append);
        }