1 16 package org.apache.commons.vfs.provider.smb; 17 18 import jcifs.smb.SmbException; 19 import jcifs.smb.SmbFile; 20 import jcifs.smb.SmbRandomAccessFile; 21 import org.apache.commons.vfs.FileSystemException; 22 import org.apache.commons.vfs.provider.AbstractRandomAccessContent; 23 import org.apache.commons.vfs.util.RandomAccessMode; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.net.MalformedURLException ; 28 import java.net.UnknownHostException ; 29 30 35 class SmbFileRandomAccessContent extends AbstractRandomAccessContent 36 { 37 private final SmbRandomAccessFile raf; 38 private final InputStream rafis; 39 40 SmbFileRandomAccessContent(final SmbFile smbFile, final RandomAccessMode mode) throws FileSystemException 41 { 42 super(mode); 43 44 StringBuffer modes = new StringBuffer (2); 45 if (mode.requestRead()) 46 { 47 modes.append('r'); 48 } 49 if (mode.requestWrite()) 50 { 51 modes.append('w'); 52 } 53 54 try 55 { 56 raf = new SmbRandomAccessFile(smbFile, modes.toString()); 57 rafis = new InputStream () 58 { 59 public int read() throws IOException 60 { 61 return raf.readByte(); 62 } 63 64 public long skip(long n) throws IOException 65 { 66 raf.seek(raf.getFilePointer() + n); 67 return n; 68 } 69 70 public void close() throws IOException 71 { 72 raf.close(); 73 } 74 75 public int read(byte b[]) throws IOException 76 { 77 return raf.read(b); 78 } 79 80 public int read(byte b[], int off, int len) throws IOException 81 { 82 return raf.read(b, off, len); 83 } 84 }; 85 } 86 catch (MalformedURLException e) 87 { 88 throw new FileSystemException("vfs.provider/random-access-open-failed.error", smbFile, e); 89 } 90 catch (SmbException e) 91 { 92 throw new FileSystemException("vfs.provider/random-access-open-failed.error", smbFile, e); 93 } 94 catch (UnknownHostException e) 95 { 96 throw new FileSystemException("vfs.provider/random-access-open-failed.error", smbFile, e); 97 } 98 } 99 100 public long getFilePointer() throws IOException 101 { 102 return raf.getFilePointer(); 103 } 104 105 public void seek(long pos) throws IOException 106 { 107 raf.seek(pos); 108 } 109 110 public long length() throws IOException 111 { 112 return raf.length(); 113 } 114 115 public void close() throws IOException 116 { 117 raf.close(); 118 } 119 120 public byte readByte() throws IOException 121 { 122 return raf.readByte(); 123 } 124 125 public char readChar() throws IOException 126 { 127 return raf.readChar(); 128 } 129 130 public double readDouble() throws IOException 131 { 132 return raf.readDouble(); 133 } 134 135 public float readFloat() throws IOException 136 { 137 return raf.readFloat(); 138 } 139 140 public int readInt() throws IOException 141 { 142 return raf.readInt(); 143 } 144 145 public int readUnsignedByte() throws IOException 146 { 147 return raf.readUnsignedByte(); 148 } 149 150 public int readUnsignedShort() throws IOException 151 { 152 return raf.readUnsignedShort(); 153 } 154 155 public long readLong() throws IOException 156 { 157 return raf.readLong(); 158 } 159 160 public short readShort() throws IOException 161 { 162 return raf.readShort(); 163 } 164 165 public boolean readBoolean() throws IOException 166 { 167 return raf.readBoolean(); 168 } 169 170 public int skipBytes(int n) throws IOException 171 { 172 return raf.skipBytes(n); 173 } 174 175 public void readFully(byte b[]) throws IOException 176 { 177 raf.readFully(b); 178 } 179 180 public void readFully(byte b[], int off, int len) throws IOException 181 { 182 raf.readFully(b, off, len); 183 } 184 185 public String readUTF() throws IOException 186 { 187 return raf.readUTF(); 188 } 189 190 public void writeDouble(double v) throws IOException 191 { 192 raf.writeDouble(v); 193 } 194 195 public void writeFloat(float v) throws IOException 196 { 197 raf.writeFloat(v); 198 } 199 200 public void write(int b) throws IOException 201 { 202 raf.write(b); 203 } 204 205 public void writeByte(int v) throws IOException 206 { 207 raf.writeByte(v); 208 } 209 210 public void writeChar(int v) throws IOException 211 { 212 raf.writeChar(v); 213 } 214 215 public void writeInt(int v) throws IOException 216 { 217 raf.writeInt(v); 218 } 219 220 public void writeShort(int v) throws IOException 221 { 222 raf.writeShort(v); 223 } 224 225 public void writeLong(long v) throws IOException 226 { 227 raf.writeLong(v); 228 } 229 230 public void writeBoolean(boolean v) throws IOException 231 { 232 raf.writeBoolean(v); 233 } 234 235 public void write(byte b[]) throws IOException 236 { 237 raf.write(b); 238 } 239 240 public void write(byte b[], int off, int len) throws IOException 241 { 242 raf.write(b, off, len); 243 } 244 245 public void writeBytes(String s) throws IOException 246 { 247 raf.writeBytes(s); 248 } 249 250 public void writeChars(String s) throws IOException 251 { 252 raf.writeChars(s); 253 } 254 255 public void writeUTF(String str) throws IOException 256 { 257 raf.writeUTF(str); 258 } 259 260 public InputStream getInputStream() throws IOException 261 { 262 return rafis; 263 } 264 } 265 | Popular Tags |