home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-04-03 | 1.7 KB | 93 lines |
- /*
- ** Sambar Server JAVA Engine Implementation
- **
- ** Confidential Property of Tod Sambar
- ** (c) Copyright Tod Sambar 1999
- ** All rights reserved.
- */
- package com.sambar.javaeng;
-
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import com.sambar.javaeng.SambarAPI;
-
- class SambarInputStream extends ServletInputStream
- {
- private int head;
- private long req;
- private SambarConnection sconn;
- private byte data[] = null;
-
- public SambarInputStream(long req, SambarConnection sconn)
- {
- this.req = req;
- this.sconn = sconn;
-
- // Get the input content
- this.data = SambarAPI.getContent(req);
-
- this.head = -1;
- if (this.data != null)
- this.head = 0;
- }
-
- public int read() throws IOException
- {
- if ((this.data == null) || (head >= this.data.length))
- return -1;
-
- head++;
- return (int)data[head - 1];
- }
-
- public int read(byte b[]) throws IOException
- {
- return read(b, 0, b.length);
- }
-
- public int read(byte b[], int off, int len) throws IOException
- {
- if (head >= this.data.length)
- return -1;
-
- if (this.data.length - head < len)
- len = this.data.length - head;
-
- for (int i = 0; i < len; i++)
- b[off + i] = data[head + i];
-
- head += len;
-
- return len;
- }
-
- public long skip(long n) throws IOException
- {
- long len;
-
- if (head >= this.data.length)
- {
- len = 0;
- }
- if (head + n > this.data.length)
- {
- len = this.data.length - head;
- head = this.data.length;
- }
- else
- {
- len = n;
- head += (int)n;
- }
-
- return len;
- }
-
- public void close() throws IOException
- {
- }
- }
-