+
+ void _setFileLength(RandomAccessFile f, int length) throws IOException{
+ InputStream in = new FileInputStream(f.getFD());
+ OutputStream out = new FileOutputStream(f.getFD());
+
+ byte[] buf = new byte[1024];
+ for (int len; length > 0; length -= len) {
+ len = in.read(buf, 0, Math.min(length, buf.length));
+ if (len == -1) break;
+ out.write(buf, 0, len);
+ }
+ if (length == 0) return;
+
+ // fill the rest of the space with zeros
+ for (int i=0; i < buf.length; i++) buf[i] = 0;
+ while (length > 0) {
+ out.write(buf, 0, Math.min(length, buf.length));
+ length -= buf.length;
+ }
+ }
+
+ RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException {
+ new FileOutputStream(f).close();
+ return new RandomAccessFile(f,mode);
+ }
+
+ File[] _listRoots() {
+ String[] rootProps = new String[]{"java.home","java.class.path","java.library.path","java.io.tmpdir","java.ext.dirs","user.home","user.dir" };
+ Hashtable known = new Hashtable();
+ for(int i=0;i<rootProps.length;i++) {
+ String prop = getProperty(rootProps[i]);
+ if(prop == null) continue;
+ for(;;) {
+ String path = prop;
+ int p;
+ if((p = prop.indexOf(File.pathSeparatorChar)) != -1) {
+ path = prop.substring(0,p);
+ prop = prop.substring(p+1);
+ }
+ File root = getRoot(new File(path));
+ //System.err.println(rootProps[i] + ": " + path + " -> " + root);
+ known.put(root,Boolean.TRUE);
+ if(p == -1) break;
+ }
+ }
+ File[] ret = new File[known.size()];
+ int i=0;
+ for(Enumeration e = known.keys();e.hasMoreElements();)
+ ret[i++] = (File) e.nextElement();
+ return ret;
+ }
+
+ File _getRoot(File f) {
+ if(!f.isAbsolute()) f = new File(f.getAbsolutePath());
+ String p;
+ while((p = f.getParent()) != null) f = new File(p);
+ if(f.getPath().length() == 0) f = new File("/"); // work around a classpath bug
+ return f;
+ }