home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 November / APCD25112k.iso / feature / webserv / SAMBAR43.ZIP / _SETUP.1 / javaeng.jar / com / sambar / javaeng / SambarInputStream.java < prev    next >
Encoding:
Java Source  |  2000-04-03  |  1.7 KB  |  93 lines

  1. /*
  2. **         Sambar Server JAVA Engine Implementation
  3. **
  4. **        Confidential Property of Tod Sambar
  5. **        (c) Copyright Tod Sambar 1999
  6. **        All rights reserved.
  7. */
  8. package com.sambar.javaeng;
  9.  
  10. import java.io.*;
  11. import java.net.*;
  12. import java.util.*;
  13. import javax.servlet.*;
  14. import javax.servlet.http.*;
  15. import com.sambar.javaeng.SambarAPI;
  16.  
  17. class SambarInputStream extends ServletInputStream 
  18. {
  19.     private int                    head;
  20.     private long                 req;
  21.     private SambarConnection     sconn;
  22.     private byte                data[] = null;
  23.   
  24.     public SambarInputStream(long req, SambarConnection sconn)
  25.     {
  26.         this.req = req;
  27.         this.sconn = sconn;
  28.  
  29.         // Get the input content
  30.         this.data = SambarAPI.getContent(req);
  31.  
  32.         this.head = -1;
  33.         if (this.data != null)
  34.             this.head = 0;
  35.     }
  36.   
  37.     public int read() throws IOException 
  38.     {
  39.         if ((this.data == null) || (head >= this.data.length))
  40.             return -1;
  41.  
  42.         head++;
  43.         return (int)data[head - 1];
  44.     }
  45.   
  46.     public int read(byte b[]) throws IOException 
  47.     {
  48.         return read(b, 0, b.length);
  49.     }
  50.   
  51.     public int read(byte b[], int off, int len) throws IOException 
  52.     {
  53.         if (head >= this.data.length)
  54.             return -1;
  55.         
  56.         if (this.data.length - head < len)
  57.             len = this.data.length - head;
  58.  
  59.         for (int i = 0; i < len; i++)
  60.             b[off + i] = data[head + i];
  61.  
  62.         head += len;
  63.  
  64.         return len;
  65.     }
  66.   
  67.     public long skip(long n) throws IOException 
  68.     {
  69.         long    len;
  70.         
  71.         if (head >= this.data.length)
  72.         {
  73.             len = 0;
  74.         }
  75.         if (head + n > this.data.length)
  76.         {
  77.             len = this.data.length - head;
  78.             head = this.data.length;
  79.         }
  80.         else
  81.         {
  82.             len = n;
  83.             head += (int)n;
  84.         }
  85.  
  86.         return len;
  87.     }
  88.  
  89.     public void close() throws IOException 
  90.     {
  91.     }
  92. }
  93.