Create a new data store. This tries to create a directory in the local file system. If the directory already exists and is non-empty, or is a file, or cannot be created, PersistenceException is thrown.
()
| 141 | * a file, or cannot be created, PersistenceException is thrown. |
| 142 | */ |
| 143 | @Override |
| 144 | public void create() |
| 145 | throws PersistenceException { |
| 146 | if(storageDir == null) |
| 147 | throw new PersistenceException("null storage directory: cannot create"); |
| 148 | |
| 149 | if(! storageDir.exists()) { // if doesn't exist create it |
| 150 | |
| 151 | if(! storageDir.mkdir()) |
| 152 | throw new |
| 153 | PersistenceException("cannot create directory " + storageDir); |
| 154 | } else { // must be empty |
| 155 | String[] existingFiles = filterIgnoredFileNames(storageDir.list()); |
| 156 | if(! (existingFiles == null || existingFiles.length == 0) ) |
| 157 | throw new PersistenceException( |
| 158 | "directory "+ storageDir +" is not empty: cannot use for data store" |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | // dump the version file |
| 163 | try { |
| 164 | File versionFile = getVersionFile(); |
| 165 | OutputStreamWriter osw = new OutputStreamWriter( |
| 166 | new FileOutputStream(versionFile) |
| 167 | ); |
| 168 | osw.write(versionNumber + Strings.getNl()); |
| 169 | osw.close(); |
| 170 | } catch(IOException e) { |
| 171 | throw new PersistenceException("couldn't write version file: " + e); |
| 172 | } |
| 173 | } // create() |
| 174 | |
| 175 | /** The name of the version file */ |
| 176 | private static String versionFileName = "__GATE_SerialDataStore__"; |