1 17 package com.sslexplorer.vfs; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 23 import com.sslexplorer.vfs.webdav.DAVException; 24 25 26 35 public class VFSInputStream extends InputStream { 36 37 38 private InputStream input = null; 39 40 private VFSResource resource = null; 41 42 45 protected VFSInputStream(VFSResource resource) { 46 if (resource == null) throw new NullPointerException (); 47 try { 48 49 if(resource instanceof FileObjectVFSResource) { 50 this.input = ((FileObjectVFSResource)resource).getFile().getContent().getInputStream(); 51 } 52 else { 53 throw new IOException ("DAV resource is not a true file."); 54 } 55 } catch (IOException e) { 56 String message = "Unable to read from resource"; 57 throw new DAVException (403, message, e, resource); 58 } 59 } 60 61 64 public int read() { 65 if (this.input == null) throw new IllegalStateException ("Closed"); 66 try { 67 return input.read(); 68 } catch (IOException e) { 69 throw new DAVException(403, "Can't read data", e, this.resource); 70 } 71 } 72 73 76 public int read(byte b[]) { 77 if (this.input == null) throw new IllegalStateException ("Closed"); 78 try { 79 return input.read(b); 80 } catch (IOException e) { 81 throw new DAVException(403, "Can't read data", e, this.resource); 82 } 83 } 84 85 88 public int read(byte b[], int off, int len) { 89 if (this.input == null) throw new IllegalStateException ("Closed"); 90 try { 91 return input.read(b, off, len); 92 } catch (IOException e) { 93 throw new DAVException(403, "Can't read data", e, this.resource); 94 } 95 } 96 97 101 public long skip(long n) { 102 if (this.input == null) throw new IllegalStateException ("Closed"); 103 try { 104 return input.skip(n); 105 } catch (IOException e) { 106 throw new DAVException(403, "Can't skip over", e, this.resource); 107 } 108 } 109 110 114 public int available() { 115 if (this.input == null) throw new IllegalStateException ("Closed"); 116 try { 117 return input.available(); 118 } catch (IOException e) { 119 throw new DAVException(403, "Can't skip over", e, this.resource); 120 } 121 } 122 123 127 public void close() { 128 if (this.input == null) return; 129 try { 130 this.input.close(); 131 } catch (IOException e) { 132 throw new DAVException(403, "Can't close", e, this.resource); 133 } finally { 134 this.input = null; 135 } 136 } 137 138 141 public void mark(int readlimit) { 142 if (this.input == null) throw new IllegalStateException ("Closed"); 143 this.input.mark(readlimit); 144 } 145 146 151 public void reset() { 152 if (this.input == null) throw new IllegalStateException ("Closed"); 153 try { 154 input.reset(); 155 } catch (IOException e) { 156 throw new DAVException(403, "Can't reset", e, this.resource); 157 } 158 } 159 160 164 public boolean markSupported() { 165 if (this.input == null) throw new IllegalStateException ("Closed"); 166 return this.input.markSupported(); 167 } 168 } 169 | Popular Tags |