Beispiel #1
0
        /// <summary>
        /// Creates a <code>OWFileInputStream</code> by
        /// opening a connection to an actual file,
        /// the file named by the <code>File</code>
        /// object <code>file</code> in the Filesystem.
        /// A new <code>OWFileDescriptor</code> object
        /// is created to represent this file connection.
        /// <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>
        /// <seealso cref=        com.dalsemi.onewire.application.file.OWFile#getPath() </seealso>
        public OWFileInputStream(OWFile file)
        {
            // get the file descriptor
            try
            {
                fd = file.FD;
            }
            catch (System.IO.IOException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }

            // open the file
            try
            {
                fd.open();
            }
            catch (OWFileNotFoundException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }

            // make sure it is not a directory
            if (!fd.File)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException("Not a file");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates an output file stream to write to the file with the specified
        /// <code>name</code>.  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>OWFileDescriptor</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 <code>name</code> 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="owd">    array of OneWireContainers that this Filesystem resides on </param>
        /// <param name="name">    the system-dependent file name </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>
        public OWFileOutputStream(OneWireContainer[] owd, string name, bool append)
        {
            fd = new OWFileDescriptor(owd, name);

            try
            {
                fd.create(append, false, false, -1, -1);
            }
            catch (OWFileNotFoundException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a file output stream to write to the file represented by
        /// the specified <code>File</code> object. A new
        /// <code>OWFileDescriptor</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>
        /// <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>
        public OWFileOutputStream(OWFile file)
        {
            try
            {
                fd = file.FD;
            }
            catch (System.IO.IOException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }

            fd.open();
        }
Beispiel #4
0
        //--------
        //-------- Constructors
        //--------

        /// <summary>
        /// Creates an output file stream to write to the file with the
        /// specified name. A new <code>OWFileDescriptor</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 <code>name</code> 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="owd">    OneWireContainer that this Filesystem resides on </param>
        /// <param name="name">   the system-dependent filename </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>
        public OWFileOutputStream(OneWireContainer owd, string name)
        {
            OneWireContainer[] devices = new OneWireContainer[1];
            devices[0] = owd;
            fd         = new OWFileDescriptor(devices, name);

            try
            {
                fd.create(false, false, false, -1, -1);
            }
            catch (OWFileNotFoundException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }
        }
Beispiel #5
0
        /// <summary>
        /// Creates a <code>FileInputStream</code> by
        /// opening a connection to an actual file,
        /// the file named by the path name <code>name</code>
        /// in the Filesystem.  A new <code>OWFileDescriptor</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 <code>name</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="owd">    array of OneWireContainers that this Filesystem resides on </param>
        /// <param name="name">   the system-dependent file name. </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>
        public OWFileInputStream(OneWireContainer[] owd, string name)
        {
            fd = new OWFileDescriptor(owd, name);

            // open the file
            try
            {
                fd.open();
            }
            catch (OWFileNotFoundException e)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException(e.ToString());
            }

            // make sure this is not directory
            if (!fd.File)
            {
                fd.free();
                fd = null;
                throw new OWFileNotFoundException("Not a file");
            }
        }