| 1 21 package com.db4o.util.io.win32; 22 23 import java.io.File ; 24 import java.io.IOException ; 25 26 import com.db4o.io.IoAdapter; 27 28 31 public class Win32IoAdapter extends IoAdapter { 32 33 static { 34 System.loadLibrary("Win32IoAdapter"); 35 } 36 37 private long _handle; 38 39 public Win32IoAdapter(String path, boolean lockFile, long initialLength) { 40 _handle = openFile(path, lockFile, initialLength); 41 } 42 43 public Win32IoAdapter() { 44 } 45 46 public void close() throws IOException { 47 closeFile(getHandle()); 48 _handle = 0; 49 } 50 51 public void delete(String path) { 52 new File (path).delete(); 53 } 54 55 public boolean exists(String path){ 56 File existingFile = new File (path); 57 return existingFile.exists() && existingFile.length() > 0; 58 } 59 60 public long getLength() throws IOException { 61 return getLength(getHandle()); 62 } 63 64 public IoAdapter open(String path, boolean lockFile, long initialLength) 65 throws IOException { 66 return new Win32IoAdapter(path, lockFile, initialLength); 67 } 68 69 public int read(byte[] bytes, int length) throws IOException { 70 return read(getHandle(), bytes, length); 71 } 72 73 public void seek(long pos) throws IOException { 74 seek(getHandle(), pos); 75 } 76 77 public void sync() throws IOException { 78 sync(getHandle()); 79 } 80 81 public void write(byte[] bytes, int length) throws IOException { 82 write(getHandle(), bytes, length); 83 } 84 85 public void copy(long oldAddress, long newAddress, int length) 86 throws IOException { 87 copy(getHandle(), oldAddress, newAddress, length); 88 } 89 90 private long getHandle() { 91 if (0 == _handle) { 92 throw new IllegalStateException ("File is not open."); 93 } 94 return _handle; 95 } 96 97 private static native long openFile(String path, boolean lockFile, long initialLength); 98 99 private static native void closeFile(long handle); 100 101 private static native long getLength(long handle); 102 103 private static native int read(long handle, byte[] bytes, int length); 104 105 private static native void seek(long handle, long pos); 106 107 private static native void sync(long handle); 108 109 private static native void write(long handle, byte[] bytes, int lenght); 110 111 private static native void copy(long handle, long oldAddress, long newAddress, int length); 112 } 113 | Popular Tags |