@@ -105,22 +105,31 @@ private void saveMemento() throws IOException {
105
105
this .getMemento (this .rootDirectory ).save (this );
106
106
}
107
107
108
- /**
109
- *
110
- * @param owner can be null - restored
111
- * @param rootDirectory must not be null
112
- * @param format can be null - restored
113
- * @return
114
- * @throws IOException
115
- * @throws ASAPException
116
- */
117
108
static ASAPEngineFS getASAPEngineFS (String owner , String rootDirectory , CharSequence format )
118
109
throws IOException , ASAPException {
110
+ return ASAPEngineFS .getASAPEngineFS (owner , rootDirectory , format , false );
111
+ }
112
+
113
+ /**
114
+ *
115
+ * @param owner can be null - restored
116
+ * @param rootDirectory must not be null
117
+ * @param format can be null - restored
118
+ * @return
119
+ * @throws IOException
120
+ * @throws ASAPException
121
+ */
122
+ static ASAPEngineFS getASAPEngineFS (String owner , String rootDirectory , CharSequence format , boolean createFolder )
123
+ throws IOException , ASAPException {
119
124
120
125
// root directory must exist when setting up an engine
121
126
File root = new File (rootDirectory );
122
127
if (!root .exists () || !root .isDirectory ()) {
123
- throw new ASAPException ("chunk root directory must exist when creating an ASAPEngine: " + rootDirectory );
128
+ if (!createFolder ) {
129
+ throw new ASAPException ("chunk root directory must exist when creating an ASAPEngine: " + rootDirectory );
130
+ } else {
131
+ root .mkdirs ();
132
+ }
124
133
}
125
134
126
135
if (format == null || format .toString ().equalsIgnoreCase (ASAP_1_0 .ANY_FORMAT )) {
@@ -221,11 +230,16 @@ public ASAPChunkStorage getReceivedChunksStorage(CharSequence sender) {
221
230
return new ASAPChunkStorageFS (dir , this .format , this .era );
222
231
}
223
232
224
- public ASAPInternalStorage getExistingIncomingStorage (CharSequence sender ) throws IOException , ASAPException {
233
+ public ASAPInternalStorage getIncomingStorage (CharSequence sender , boolean create ) throws IOException , ASAPException {
225
234
return ASAPEngineFS .getASAPEngineFS (
226
235
sender .toString (), // becomes owner
227
236
this .rootDirectory + "/" + sender , // folder
228
- this .getFormat ()); // format taken from superior storage
237
+ this .getFormat (), // format taken from superior storage
238
+ create );
239
+ }
240
+
241
+ public ASAPInternalStorage getExistingIncomingStorage (CharSequence sender ) throws IOException , ASAPException {
242
+ return this .getIncomingStorage (sender , true );
229
243
}
230
244
231
245
/**
@@ -236,6 +250,8 @@ public ASAPInternalStorage getExistingIncomingStorage(CharSequence sender) throw
236
250
* @throws ASAPException
237
251
*/
238
252
public ASAPInternalStorage getIncomingStorage (CharSequence sender ) throws IOException , ASAPException {
253
+ return this .getIncomingStorage (sender , true );
254
+ /*
239
255
String folderName = this.rootDirectory + "/" + sender;
240
256
File folder = new File(folderName);
241
257
if(!folder.exists()) {
@@ -246,6 +262,7 @@ public ASAPInternalStorage getIncomingStorage(CharSequence sender) throws IOExce
246
262
sender.toString(), // becomes owner
247
263
folderName, // folder
248
264
this.getFormat()); // format taken from superior storage
265
+ */
249
266
}
250
267
251
268
@ Override
0 commit comments