MCPcopy Create free account
hub / github.com/GateNLP/gate-core / create

Method create

src/main/java/gate/persist/SerialDataStore.java:143–173  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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__";

Callers 4

testSaveRestoreMethod · 0.95
testMultipleLrsMethod · 0.95
testDeleteMethod · 0.95
generateCorpusMethod · 0.95

Calls 6

getVersionFileMethod · 0.95
getNlMethod · 0.95
closeMethod · 0.65
listMethod · 0.45
writeMethod · 0.45

Tested by 3

testSaveRestoreMethod · 0.76
testMultipleLrsMethod · 0.76
testDeleteMethod · 0.76