1 16 17 18 package org.apache.xmlrpc; 19 20 import java.io.BufferedInputStream ; 21 import java.io.InputStream ; 22 import java.io.IOException ; 23 24 29 class ServerInputStream extends InputStream 30 { 31 private long available = -1; 37 private long markedAvailable; 38 39 private BufferedInputStream in; 40 41 46 public ServerInputStream(BufferedInputStream in, int available) 47 { 48 this.in = in; 49 this.available = available; 50 } 51 52 57 public int read() throws IOException 58 { 59 if (available > 0) 60 { 61 available--; 62 return in.read(); 63 } 64 else if (available == -1) 65 { 66 return in.read (); 67 } 68 return -1; 69 } 70 71 77 public int read(byte b[]) throws IOException 78 { 79 return read(b, 0, b.length); 80 } 81 82 90 public int read(byte b[], int off, int len) throws IOException 91 { 92 if (available > 0) 93 { 94 if (len > available) 95 { 96 len = (int) available; 98 } 99 int read = in.read(b, off, len); 100 if (read != -1) 101 { 102 available -= read; 103 } 104 else 105 { 106 available = -1; 107 } 108 return read; 109 } 110 else if (available == -1) 111 { 112 return in.read(b, off, len); 113 } 114 return -1; 115 } 116 117 123 public long skip(long n) throws IOException 124 { 125 long skip = in.skip(n); 126 if (available > 0) 127 { 128 available -= skip; 129 } 130 return skip; 131 } 132 133 137 public void mark(int readlimit) 138 { 139 in.mark(readlimit); 140 markedAvailable = available; 141 } 142 143 147 public void reset() throws IOException 148 { 149 in.reset(); 150 available = markedAvailable; 151 } 152 153 157 public boolean markSupported() 158 { 159 return true; 160 } 161 } 162 | Popular Tags |