@@ -105,22 +105,31 @@ private void saveMemento() throws IOException {
105105 this .getMemento (this .rootDirectory ).save (this );
106106 }
107107
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- */
117108 static ASAPEngineFS getASAPEngineFS (String owner , String rootDirectory , CharSequence format )
118109 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 {
119124
120125 // root directory must exist when setting up an engine
121126 File root = new File (rootDirectory );
122127 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+ }
124133 }
125134
126135 if (format == null || format .toString ().equalsIgnoreCase (ASAP_1_0 .ANY_FORMAT )) {
@@ -221,11 +230,16 @@ public ASAPChunkStorage getReceivedChunksStorage(CharSequence sender) {
221230 return new ASAPChunkStorageFS (dir , this .format , this .era );
222231 }
223232
224- public ASAPInternalStorage getExistingIncomingStorage (CharSequence sender ) throws IOException , ASAPException {
233+ public ASAPInternalStorage getIncomingStorage (CharSequence sender , boolean create ) throws IOException , ASAPException {
225234 return ASAPEngineFS .getASAPEngineFS (
226235 sender .toString (), // becomes owner
227236 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 );
229243 }
230244
231245 /**
@@ -236,6 +250,8 @@ public ASAPInternalStorage getExistingIncomingStorage(CharSequence sender) throw
236250 * @throws ASAPException
237251 */
238252 public ASAPInternalStorage getIncomingStorage (CharSequence sender ) throws IOException , ASAPException {
253+ return this .getIncomingStorage (sender , true );
254+ /*
239255 String folderName = this.rootDirectory + "/" + sender;
240256 File folder = new File(folderName);
241257 if(!folder.exists()) {
@@ -246,6 +262,7 @@ public ASAPInternalStorage getIncomingStorage(CharSequence sender) throws IOExce
246262 sender.toString(), // becomes owner
247263 folderName, // folder
248264 this.getFormat()); // format taken from superior storage
265+ */
249266 }
250267
251268 @ Override
0 commit comments