Fix downloading/exporting when overwriting file would not truncate

This commit is contained in:
Stypox 2024-11-24 18:34:22 +01:00
parent 8af786f26d
commit c80c378398
3 changed files with 15 additions and 3 deletions

View file

@ -189,6 +189,19 @@ public class StoredFileHelper implements Serializable {
}
}
public SharpStream openAndTruncateStream() throws IOException {
final SharpStream sharpStream = getStream();
try {
sharpStream.setLength(0);
} catch (final Throwable e) {
// we can't use try-with-resources here, since we only want to close the stream if an
// exception occurs, but leave it open if everything goes well
sharpStream.close();
throw e;
}
return sharpStream;
}
/**
* Indicates whether it's using the {@code java.io} API.
*