- } else {
- String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
- mFile.setStoragePath(temporalPath);
- temporalFile = new File(temporalPath);
- if (!originalStoragePath.equals(temporalPath)) { // preventing weird but possible situation
- InputStream in = new FileInputStream(originalFile);
- OutputStream out = new FileOutputStream(temporalFile);
+ } else {
+ String temporalPath = FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath();
+ mFile.setStoragePath(temporalPath);
+ temporalFile = new File(temporalPath);
+ if (!mOriginalStoragePath.equals(temporalPath)) { // preventing weird but possible situation
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ File temporalParent = temporalFile.getParentFile();
+ temporalParent.mkdirs();
+ if (!temporalParent.isDirectory()) {
+ throw new IOException("Unexpected error: parent directory could not be created");
+ }
+ temporalFile.createNewFile();
+ if (!temporalFile.isFile()) {
+ throw new IOException("Unexpected error: target file could not be created");
+ }
+ in = new FileInputStream(originalFile);
+ out = new FileOutputStream(temporalFile);