1 29 30 package com.caucho.quercus.lib.file; 31 32 import com.caucho.quercus.env.BooleanValue; 33 import com.caucho.quercus.env.Env; 34 import com.caucho.quercus.env.ResourceValue; 35 import com.caucho.quercus.env.StringValueImpl; 36 import com.caucho.quercus.env.Value; 37 import com.caucho.vfs.Path; 38 39 import java.io.IOException ; 40 41 44 public class DirectoryValue extends ResourceValue { 45 private Path _path; 46 private String []_list; 47 private int _index; 48 49 protected DirectoryValue() 50 { 51 } 52 53 public DirectoryValue(Path path) 54 throws IOException  55 { 56 _path = path; 57 58 _list = path.list(); 59 } 60 61 64 public Value readdir() 65 { 66 if (_index < _list.length) 67 return new StringValueImpl(_list[_index++]); 68 else 69 return BooleanValue.FALSE; 70 } 71 72 75 public void rewinddir() 76 { 77 _index = 0; 78 } 79 80 83 public Value callMethod(Env env, String method) 84 { 85 if ("read".equals(method)) 86 return readdir(); 87 else if ("rewind".equals(method)) { 88 rewinddir(); 89 90 return BooleanValue.TRUE; 91 } 92 else if ("close".equals(method)) { 93 close(); 94 95 return BooleanValue.TRUE; 96 } 97 else 98 return super.callMethod(env, method); 99 } 100 101 105 public String toString() 106 { 107 return "Directory[" + _path + "]"; 108 } 109 } 110 111 | Popular Tags |