@@ -81,15 +81,16 @@ public List<CharSequence> getDeliveredTo() {
8181 this (storage , uri , era , null );
8282 }
8383
84- ASAPInternalChunkFS (ASAPChunkStorageFS storage , String targetUri , int era , String sender ) throws IOException {
84+ ASAPInternalChunkFS (ASAPChunkStorageFS storage , String uri , int era , String sender ) throws IOException {
8585 this .storage = storage ;
86- if (targetUri != null ) {
87- this .uri = targetUri ;
86+ if (uri != null ) {
87+ this .uri = uri ;
8888 }
8989 this .era = era ;
9090 this .sender = sender ;
91-
92- String trunkName = this .storage .setupChunkFolder (era , targetUri );
91+
92+ //Log.writeLog(this, this.toString(), "construct chunkFS");
93+ String trunkName = this .storage .setupChunkFolder (era , uri );
9394
9495 // init
9596 this .initFiles (trunkName );
@@ -105,12 +106,16 @@ public ASAPInternalChunkFS(ASAPChunkStorageFS storage, String trunkName) throws
105106 private void initFiles (String trunkName ) throws IOException {
106107 String messageFileName = trunkName + "." + DATA_EXTENSION ;
107108 String metaFileName = trunkName + "." + META_DATA_EXTENSION ;
108-
109+
109110 this .messageFile = new File (messageFileName );
110111 this .metaFile = new File (metaFileName );
111112
112113 // init meta file - message file keeps untouched (good idea?)
113114 if (!this .metaFile .exists ()) {
115+ if (!this .metaFile .getParentFile ().exists ()) {
116+ this .metaFile .getParentFile ().mkdirs ();
117+ Log .writeLog (this , "parent folder created: " + this .messageFile .getParentFile ().exists ());
118+ }
114119 this .metaFile .createNewFile ();
115120 }
116121
@@ -181,32 +186,32 @@ public void addMessage(byte[] messageAsBytes) throws IOException {
181186 }
182187
183188 public void addMessage (InputStream messageByteIS , long length ) throws IOException {
184- Log .writeLog (this , "going to add message to chunkFS" );
189+ // Log.writeLog(this, "going to add message to chunkFS" );
185190 if (length > Integer .MAX_VALUE ) {
186191 throw new IOException ("message must not be longer than Integer.MAXVALUE" );
187192 }
188193
189194 long offset = 0 ;
190195 if (!this .messageFile .exists ()) {
191- Log . writeLog ( this , "content file does not exist yet - create: " + this .messageFile .getName ());
192- Log . writeLog ( this , "apath " + this .messageFile .getAbsolutePath () );
193- Log .writeLog (this , "cpath " + this .messageFile .getCanonicalPath ());
194- Log . writeLog ( this , "path " + this . messageFile . getPath ());
196+ if (! this .messageFile .getParentFile (). exists ()) {
197+ this .messageFile .getParentFile (). mkdirs ( );
198+ Log .writeLog (this , "parent folder created: " + this .messageFile .getParentFile (). exists ());
199+ }
195200 this .messageFile .createNewFile ();
196201 } else {
197202 offset = this .messageFile .length ();
198203 }
199- Log .writeLog (this , "got chunk content file length: " + offset );
204+ // Log.writeLog(this, "got chunk content file length: " + offset);
200205
201206 OutputStream os = new FileOutputStream (this .messageFile , true );
202- Log .writeLog (this , "opened chunk content file to append data" );
207+ // Log.writeLog(this, "opened chunk content file to append data");
203208
204- Log .writeLog (this , "write message to the end of chunk file" );
209+ // Log.writeLog(this, "write message to the end of chunk file");
205210 while (length -- > 0 ) {
206211 os .write (messageByteIS .read ());
207212 }
208213
209- Log .writeLog (this , "closing" );
214+ // Log.writeLog(this, "closing");
210215 os .close ();
211216
212217 // remember offset if not 0
@@ -454,4 +459,7 @@ public int getEra() throws IOException {
454459 return this .era ;
455460 }
456461
462+ public String toString () {
463+ return "sender: " + this .sender + " | era: " + era + " | metafile: " + this .metaFile ;
464+ }
457465}
0 commit comments