1 5 package ve.luz.ica.remoteio; 6 7 import java.io.BufferedInputStream ; 8 import java.io.IOException ; 9 import java.io.InputStream ; 10 11 14 18 public class RemoteInputStreamAdapter extends InputStream 19 { 20 22 private RemoteInputStream remoteInputStream = null; 23 private BufferedInputStream bufferedInputStream = null; 24 private RawInputStream rawInputStream = null; 25 private OctetSequenceHolder bufferHolder = null; 26 27 31 public RemoteInputStreamAdapter(RemoteInputStream remoteStream) 32 { 33 this.remoteInputStream = remoteStream; 34 this.rawInputStream = new RawInputStream(); 35 this.bufferedInputStream = new BufferedInputStream (rawInputStream); 36 bufferHolder = new OctetSequenceHolder(); 37 } 38 39 42 public int read() throws IOException 43 { 44 return this.bufferedInputStream.read(); 45 } 46 47 50 public int read(byte[] b, int off, int len) throws IOException 51 { 52 return this.bufferedInputStream.read(b, off, len); 53 } 54 55 58 public void close() throws IOException 59 { 60 this.bufferedInputStream.close(); 61 } 62 63 66 public int available() throws IOException 67 { 68 return this.bufferedInputStream.available(); 69 } 70 71 74 public void mark(int readlimit) 75 { 76 this.bufferedInputStream.mark(readlimit); 77 } 78 79 82 public boolean markSupported() 83 { 84 return this.bufferedInputStream.markSupported(); 85 } 86 87 90 public void reset() throws IOException 91 { 92 this.bufferedInputStream.reset(); 93 } 94 95 98 public long skip(long n) throws IOException 99 { 100 return this.bufferedInputStream.skip(n); 101 } 102 103 107 class RawInputStream extends InputStream 108 { 109 112 public int read() throws IOException 113 { 114 byte[] b = {0}; 115 if (this.read(b, 0, 1) == -1) 116 { 117 return -1; 118 } 119 return b[0]; 120 } 121 122 125 public int read(byte[] b, int off, int len) throws IOException 126 { 127 try 128 { 129 int bytesRead = remoteInputStream.read(bufferHolder, len); 130 System.arraycopy(bufferHolder.value, 0, b, off, len); 131 return bytesRead; 132 } 133 catch (RemoteIOException e) 134 { 135 e.printStackTrace(); 136 throw new IOException (e.getMessage()); 137 } 138 } 139 140 143 public void close() throws IOException 144 { 145 try 146 { 147 remoteInputStream.close(); 148 } 149 catch (RemoteIOException e) 150 { 151 throw new IOException (e.getMessage()); 152 } 153 } 154 155 158 public int available() throws IOException 159 { 160 try 161 { 162 return remoteInputStream.available(); 163 } 164 catch (RemoteIOException e) 165 { 166 throw new IOException (e.getMessage()); 167 } 168 } 169 170 173 public void mark(int readlimit) 174 { 175 remoteInputStream.mark(readlimit); 176 } 177 178 181 public boolean markSupported() 182 { 183 return remoteInputStream.markSupported(); 184 } 185 186 189 public void reset() throws IOException 190 { 191 try 192 { 193 remoteInputStream.reset(); 194 } 195 catch (RemoteIOException e) 196 { 197 throw new IOException (e.getMessage()); 198 } 199 } 200 201 204 public long skip(long n) throws IOException 205 { 206 try 207 { 208 return remoteInputStream.skip(n); 209 } 210 catch (RemoteIOException e) 211 { 212 throw new IOException (e.getMessage()); 213 } 214 } 215 } 216 217 } 218 | Popular Tags |