コード例 #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");
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a <code>OWFileInputStream</code> by using the file descriptor
        /// <code>fdObj</code>, which represents an existing connection to an
        /// actual file in the Filesystem.
        /// <para>
        /// If <code>fdObj</code> is null then a <code>NullPointerException</code>
        /// is thrown.
        ///
        /// </para>
        /// </summary>
        /// <param name="fdObj">   the file descriptor to be opened for reading. </param>
        public OWFileInputStream(OWFileDescriptor fdObj)
        {
            if (fdObj == null)
            {
                throw new System.NullReferenceException("OWFile provided is null");
            }

            fd = fdObj;
        }
コード例 #3
0
        /// <summary>
        /// Closes this file input stream and releases any system resources
        /// associated with the stream.
        /// </summary>
        /// <exception cref="IOException">  if an I/O error occurs. </exception>
        public virtual void close()
        {
            if (fd != null)
            {
                fd.close();
            }
            else
            {
                throw new System.IO.IOException("1-Wire FileDescriptor is null");
            }

            fd = null;
        }
コード例 #4
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();
        }
コード例 #5
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());
            }
        }
コード例 #6
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());
            }
        }
コード例 #7
0
ファイル: OWFish1.cs プロジェクト: Agrimeters/winrt-onewire
    /// <summary>
    /// Sync's the file Descriptor, prompts for retry if there is
    /// an exception.
    /// </summary>
    /// <param name="fd"> OWFileDescriptor of Filesystem to sync </param>
    internal static void syncFileDescriptor(OWFileDescriptor fd)
    {
        for (;;)
        {
            try
            {
                fd.sync();
                return;
            }
            catch (OWSyncFailedException e)
            {
                Debug.WriteLine("");
                Debug.WriteLine("-----------------------------------------------");
                Debug.WriteLine(e);
                Debug.WriteLine("-----------------------------------------------");

                // prompt to try again
                if (menuSelect(retryMenu) == RETRY_NO)
                {
                    return;
                }
            }
        }
    }
コード例 #8
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");
            }
        }