@@ -22,6 +22,7 @@ import ru.soune.nocopy.repository.UserRepository;
|
||||
import ru.soune.nocopy.service.file.cloud.CloudStorageService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -240,11 +241,18 @@ public class FileEntityService {
|
||||
String extension = determineFileExtension(fileExt, fileEntity);
|
||||
Path protectedFilePath = prepareProtectedPath(fileEntity, extension);
|
||||
|
||||
if (Files.exists(protectedFilePath)) {
|
||||
Files.delete(protectedFilePath);
|
||||
}
|
||||
Files.createDirectories(protectedFilePath.getParent());
|
||||
|
||||
try (FileChannel channel = FileChannel.open(protectedFilePath, StandardOpenOption.WRITE)) {
|
||||
Files.deleteIfExists(protectedFilePath);
|
||||
|
||||
try (FileChannel channel = FileChannel.open(protectedFilePath,
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.WRITE)) {
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
while (buffer.hasRemaining()) {
|
||||
channel.write(buffer);
|
||||
}
|
||||
channel.force(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user