home *** CD-ROM | disk | FTP | other *** search
- package opera;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InterruptedIOException;
- import java.util.Hashtable;
-
- public class OperaInputStream extends InputStream {
- private static final int BUFFER_SIZE = 32768;
- private static Hashtable stream_map = new Hashtable();
- private static int next_stream_id = 0;
- private int protocol_response = -1;
- private byte[] buffer = new byte['ΦÇÇ'];
- private int next_read = 0;
- private int last_avail = -1;
- private int available = 0;
- private int total_input = 0;
- private int content_len = -1;
- private int stream_id = -1;
- private boolean eof_state = false;
- private OperaURLConnection connection = null;
-
- protected OperaInputStream(OperaURLConnection var1) {
- this.connection = var1;
- }
-
- public int getResponse() {
- return this.protocol_response;
- }
-
- public int available() {
- return this.available;
- }
-
- public int read() throws IOException {
- if (this.available() == 0 && this.eof_state) {
- this.buffer = null;
- return -1;
- } else {
- while(this.available() == 0 && !this.eof_state) {
- this.starving();
-
- try {
- synchronized(this) {
- this.wait();
- }
- } catch (InterruptedException var6) {
- this.eof_state = true;
- this.available = 0;
- Thread.currentThread().interrupt();
- throw new InterruptedIOException();
- }
- }
-
- synchronized(this) {
- if (this.available() == 0 && this.eof_state) {
- this.connection = null;
- this.buffer = null;
- byte var7 = -1;
- return var7;
- } else {
- --this.available;
- if (this.next_read == 32768) {
- this.next_read = 0;
- }
-
- int var2 = 255 & this.buffer[this.next_read++];
- return var2;
- }
- }
- }
- }
-
- public void headerLoaded(int var1, int var2) {
- synchronized(this) {
- if (var1 == 0) {
- var1 = -1;
- }
-
- this.content_len = var1;
- this.protocol_response = var2;
- this.notifyAll();
- }
- }
-
- public int getContentLength() {
- return this.content_len;
- }
-
- public void setEOF() {
- synchronized(this) {
- this.eof_state = true;
- this.notifyAll();
- }
- }
-
- public int addInput(byte[] var1) {
- int var2 = 0;
- int var3 = 0;
- synchronized(this) {
- try {
- if (this.eof_state) {
- byte var11 = -1;
- return var11;
- }
-
- if (var1.length > 0) {
- if (this.available < 32768) {
- int var5 = 'ΦÇÇ' - this.available;
- if (this.last_avail < 32767) {
- if (var1.length < 'ΦÇÇ' - this.last_avail) {
- var2 = var1.length;
- } else {
- var2 = 'ΦÇÇ' - this.last_avail - 1;
- }
-
- if (var2 > var5) {
- var2 = var5;
- }
-
- System.arraycopy(var1, 0, this.buffer, this.last_avail + 1, var2);
- }
-
- var5 -= var2;
- if (var5 > 0) {
- if (var1.length - var2 > var5) {
- var3 = var5;
- } else {
- var3 = var1.length - var2;
- }
-
- System.arraycopy(var1, var2, this.buffer, 0, var3);
- }
-
- this.last_avail = (this.last_avail + var2 + var3) % 'ΦÇÇ';
- }
-
- this.notifyAll();
- }
- } catch (ArrayIndexOutOfBoundsException var7) {
- ((Throwable)var7).printStackTrace(System.err);
- }
-
- this.available += var2 + var3;
- this.total_input += var2 + var3;
- int var10 = var2 + var3;
- return var10;
- }
- }
-
- protected static int addStream(OperaInputStream var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- stream_map.put(new Integer(next_stream_id), var0);
- var0.stream_id = next_stream_id++;
- }
-
- return var0.stream_id;
- }
-
- protected static void removeStream(int var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- stream_map.remove(new Integer(var0));
- }
- }
-
- protected static OperaInputStream getStream(int var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- OperaInputStream var2 = (OperaInputStream)stream_map.get(new Integer(var0));
- return var2;
- }
- }
-
- private native void starving();
- }
-