|
5 | 5 | import net.sharksystem.asap.ASAPHop; |
6 | 6 | import net.sharksystem.asap.utils.ASAPSerialization; |
7 | 7 | import net.sharksystem.asap.utils.Helper; |
| 8 | +import net.sharksystem.utils.Log; |
8 | 9 |
|
9 | 10 | import java.io.*; |
10 | 11 | import java.util.*; |
@@ -115,7 +116,7 @@ private void initFiles(String trunkName) throws IOException { |
115 | 116 |
|
116 | 117 | // try to read existing meta data |
117 | 118 | if(!this.readMetaData(this.metaFile)) { |
118 | | - // no metadate to be read - set defaults |
| 119 | + // no meta date to be read - set defaults |
119 | 120 | this.writeMetaData(this.metaFile); |
120 | 121 | this.recipients = new HashSet<>(); |
121 | 122 | this.deliveredTo = new ArrayList<>(); |
@@ -180,21 +181,32 @@ public void addMessage(byte[] messageAsBytes) throws IOException { |
180 | 181 | } |
181 | 182 |
|
182 | 183 | public void addMessage(InputStream messageByteIS, long length) throws IOException { |
| 184 | + Log.writeLog(this, "going to add message to chunkFS" ); |
183 | 185 | if(length > Integer.MAX_VALUE) { |
184 | 186 | throw new IOException("message must not be longer than Integer.MAXVALUE"); |
185 | 187 | } |
186 | 188 |
|
187 | | - long offset = this.messageFile.length(); |
| 189 | + long offset = 0; |
| 190 | + 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()); |
| 195 | + this.messageFile.createNewFile(); |
| 196 | + } else { |
| 197 | + offset = this.messageFile.length(); |
| 198 | + } |
| 199 | + Log.writeLog(this, "got chunk content file length: " + offset); |
188 | 200 |
|
189 | | -// Log.writeLog(this, "chunk file offset == " + offset); |
190 | 201 | OutputStream os = new FileOutputStream(this.messageFile, true); |
| 202 | + Log.writeLog(this, "opened chunk content file to append data"); |
191 | 203 |
|
192 | | -// Log.writeLog(this, "write message to the end of chunk file"); |
| 204 | + Log.writeLog(this, "write message to the end of chunk file"); |
193 | 205 | while(length-- > 0) { |
194 | 206 | os.write(messageByteIS.read()); |
195 | 207 | } |
196 | 208 |
|
197 | | -// Log.writeLog(this, "closing"); |
| 209 | + Log.writeLog(this, "closing"); |
198 | 210 | os.close(); |
199 | 211 |
|
200 | 212 | // remember offset if not 0 |
|
0 commit comments