[WICKET-6936] allow to over-ride write channel creation
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/FilePageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/FilePageStore.java
index 4462b1b..173e63c 100644
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/FilePageStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/FilePageStore.java
@@ -23,6 +23,7 @@
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
+import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.util.ArrayList;
@@ -185,8 +186,7 @@
File file = getPageFile(sessionIdentifier, pageId, true);
try
{
- FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
+ FileChannel channel = createWriteFileChannel(file.toPath());
try
{
ByteBuffer buffer = ByteBuffer.wrap(data);
@@ -205,6 +205,21 @@
setPageType(file, pageType);
}
+ /**
+ * Factory method that allows to override creation write channels. Mind StandardOpenOption.TRUNCATE_EXISTING may produce problems in
+ * Windows operating system. If removed default java serialization will still work but files will not shrink.
+ * Please be careful if you use another serialization method.
+ *
+ * @param path The Path of the file.
+ * @return FileChannel
+ * @throws IOException
+ */
+ protected FileChannel createWriteFileChannel(Path path) throws IOException
+ {
+ return FileChannel.open(path, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
+ }
+
private void checkMaxSize(String sessionIdentifier)
{
File[] files = folders.get(sessionIdentifier, true).listFiles();