⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owfileinputstream.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.application.file;import java.io.IOException;import java.io.InputStream;import com.dalsemi.onewire.container.OneWireContainer;/** * A <code>OWFileInputStream</code> obtains input bytes * from a file in a 1-Wire Filesystem. What files * are available depends on the 1-Wire device. * * <p> Note that the 1-Wire File system can reside across multiple 1-Wire *  devices.  In this case only one of the devices need be supplied to the *  constructor.  Each device in a multi-device file system contains *  information to reacquire the entire list. * * <p>  File and directory <b> name </b> limitations * <ul> * <li> File/directory names limited to 4 characters not including extension * <li> File/directory names are not case sensitive and will be automatically *      changed to all-CAPS * <li> Only files can have extensions * <li> Extensions are numberical in the range 0 to 125 * <li> Extensions 100 to 125 are special purpose and not yet implemented or allowed * <li> Files can have the read-only attribute * <li> Directories can have the hidden attribute * <li> It is recommended to limit directory depth to 10 levels to accomodate *      legacy implementations * </ul> * * <H3> Usage </H3> * <DL> * <DD> <H4> Example </H4> * Read from a 1-Wire file on device 'owd': * <PRE> <CODE> *   // get an input stream to the 1-Wire file *   OWFileInputStream instream = new OWFileInputStream(owd, "DEMO.0"); * *   // read some data *   byte[] data = new byte[2000]; *   int len = instream.read(data); * *   // close the stream to release system resources *   instream.close(); * * </CODE> </PRE> * * @author  DS * @version 0.01, 1 June 2001 * @see     com.dalsemi.onewire.application.file.OWFile * @see     com.dalsemi.onewire.application.file.OWFileDescriptor * @see     com.dalsemi.onewire.application.file.OWFileOutputStream */public class OWFileInputStream   extends InputStream{   //--------   //-------- Variables   //--------   /**    * File descriptor.    */   private OWFileDescriptor fd;   //--------   //-------- Constructors   //--------   /**    * 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.    * <p>    * First, if there is a security    * manager, its <code>checkRead</code> method    * is called with the <code>name</code> argument    * as its argument.    * <p>    * 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.    *    * @param      owd    OneWireContainer that this Filesystem resides on    * @param      name   the system-dependent file name.    * @exception  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.    */   public OWFileInputStream(OneWireContainer owd, String name)      throws OWFileNotFoundException   {      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.isFile())      {         fd.free();         fd = null;         throw new OWFileNotFoundException("Not a file");      }   }   /**    * 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.    * <p>    * First, if there is a security    * manager, its <code>checkRead</code> method    * is called with the <code>name</code> argument    * as its argument.    * <p>    * 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.    *    * @param      owd    array of OneWireContainers that this Filesystem resides on    * @param      name   the system-dependent file name.    * @exception  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.    */   public OWFileInputStream(OneWireContainer[] owd, String name)      throws OWFileNotFoundException   {      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.isFile())      {         fd.free();         fd = null;         throw new OWFileNotFoundException("Not a file");      }   }   /**    * 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.    * <p>    * 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.    *    * @param      file   the file to be opened for reading.    * @exception  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.    * @see        com.dalsemi.onewire.application.file.OWFile#getPath()    */   public OWFileInputStream(OWFile file)      throws OWFileNotFoundException   {      // get the file descriptor      try      {         fd = file.getFD();      }      catch (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.isFile())      {         fd.free();         fd = null;         throw new OWFileNotFoundException("Not a file");      }   }   /**    * 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.    * <p>    * If <code>fdObj</code> is null then a <code>NullPointerException</code>    * is thrown.    *    * @param      fdObj   the file descriptor to be opened for reading.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -