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

📄 napletinputstream.java

📁 移动Agent编程工具Naplet
💻 JAVA
字号:
/*
 * @<#> NapletInputStream.java version 0.0.1 1/1/2001
 *
 * THIS PROGRAM IS FREE SOFTWARE; YOU CAN DISTRIBUTE IT AND/OR
 * MODIFY IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE 
 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.
 *
 * THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
 * BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE 
 * GNU GENERAL PUBLIC LICENSE FOR MORE DETAILS.
 *
 * Copyright (c) 2000 Wayne State University. All Rights Reserved.
 */
package naplet.serviceChannel;

import java.io.InputStream;
import java.io.IOException;

import naplet.*;
import naplet.serviceChannel.*;

/**
 * Piped byte-input streams from naplets to priviledged services .
 *
 * @version 0.0.1, 1/1/2001
 * @author C. Xu (czxu@yahoo.com)
 */

public class NapletInputStream extends InputStream 
{
      ServiceOutputStream source = null;
   
      /**
       * Creates a <code>NapletInputStream</code> and connects it to a 
       * <code>SerivceWriter</code> in a piped stream. 
       * Data written to <code>src</code> 
       * will then be  available as input from this stream.
       *
       * @param      src   the stream to connect to.
       * @exception  IOException  if an I/O error occurs.
       */
      public NapletInputStream( ServiceOutputStream src )
	 throws IOException 
      {
	 if ( src == null )
	 {
	    throw new IOException( "Service writer doesn't exist" );
	 }

	 src.connect( this );
      }

      /**
       * Creates a <code>NapletInputStream</code>. It must be
       * connected to a <code>ServiceWriter</code>
       * before being used.
       *
       */
      public NapletInputStream( )
      {
      }
 
      /**
       * Closes this piped stream and releases any system resources 
       * associated with the stream. 
       *
       * @exception  IOException  if an I/O error occurs.
       */
      public void close( )
	 throws IOException 
      {
	 synchronized ( source )
	 {
	    source.in = -1;
	    source.out = 0;
	    source.closedByNaplet = true;
	    source.connected = false;
	 }
      }

    
      /**
       * Reads the next byte of data from this piped stream.
       * If no byte is available because the end of the stream 
       * has been reached, the value <code>-1</code> is returned. 
       * This method blocks until input data is available, the end of
       * the stream is detected, or an exception is thrown. 
       *
       * If a thread was providing data bytes
       * to the connected piped writer, but
       * the  thread is no longer alive, then an
       * <code>IOException</code> is thrown.
       *
       * @return     the next byte of data, or <code>-1</code> if the 
       *             end of the stream is reached.
       * @exception  IOException  if the pipe is broken.
       */
      public int read( )
	 throws IOException
      {
 	 return source.get( );
      }
	

      /**
       * Reads up to <code>len</code> bytes of data from this piped
       * stream into an array of bytes. Less than <code>len</code> 
       * bytes will be read if the end of the data stream is reached. 
       * This method blocks until at least one byte of input is 
       * available. If a thread was providing data bytes to the connected
       * piped output, but the thread is no longer alive, then an 
       * <code>IOException</code> is thrown.
       *
       * @param      cbuf     the buffer into which the data is read.
       * @param      off   the start offset of the data.
       * @param      len   the maximum number of bytes read.
       * @return     the total number of bytes read into the buffer, or
       *             <code>-1</code> if there is no more data because the end 
       *             of the stream has been reached.
       * @exception  IOException  if an I/O error occurs.
       */
      public int read( byte cbuf[], int off, int len )
	 throws IOException
      {
	 return source.get( cbuf, off, len );
      }
}

⌨️ 快捷键说明

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