1 29 30 package com.caucho.vfs; 31 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 36 39 public class FileReadStream extends StreamImpl { 40 private FileInputStream _is; 41 42 45 public FileReadStream() 46 { 47 } 48 49 54 public FileReadStream(FileInputStream is) 55 { 56 init(is); 57 } 58 59 65 public FileReadStream(FileInputStream is, Path path) 66 { 67 init(is); 68 setPath(path); 69 } 70 71 78 public void init(FileInputStream is) 79 { 80 _is = is; 81 setPath(null); 82 } 83 84 87 public boolean canSkip() 88 { 89 return _is != null; 90 } 91 92 99 public long skip(long n) 100 throws IOException 101 { 102 if (_is != null) 103 return _is.skip(n); 104 else 105 return -1; 106 } 107 108 111 public void seekStart(long offset) 112 throws IOException 113 { 114 if (_is != null) 115 _is.getChannel().position(offset); 116 } 117 118 121 public boolean canRead() 122 { 123 return _is != null; 124 } 125 126 135 public int read(byte []buf, int offset, int length) throws IOException 136 { 137 if (_is == null) 138 return -1; 139 140 int len = _is.read(buf, offset, length); 141 142 return len; 143 } 144 145 148 public int getAvailable() throws IOException 149 { 150 if (_is == null) 151 return -1; 152 else { 153 return _is.available(); 154 } 155 } 156 157 160 public void close() throws IOException 161 { 162 InputStream is = _is; 163 _is = null; 164 165 if (is != null) 166 is.close(); 167 } 168 } 169 | Popular Tags |