/// <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"); } }
/// <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(); }
/// <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"); } }