Index: src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java (revision 1633283) +++ src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/OakDirectory.java (working copy) @@ -154,6 +154,8 @@ private static class OakIndexFile { + private final boolean isReadOnly; + private final String name; private final NodeBuilder file; @@ -174,7 +176,10 @@ private boolean blobModified = false; - public OakIndexFile(String name, NodeBuilder file) { + private volatile boolean isOpen = true; + + public OakIndexFile(String name, NodeBuilder file, boolean isReadOnly) { + this.isReadOnly = isReadOnly; this.name = name; this.file = file; this.blobSize = determineBlobSize(file); @@ -195,6 +200,7 @@ } private OakIndexFile(OakIndexFile that) { + this.isReadOnly = that.isReadOnly; this.name = that.name; this.file = that.file; this.blobSize = that.blobSize; @@ -225,6 +231,7 @@ private void flushBlob() throws IOException { if (blobModified) { + checkState(!isReadOnly); int n = (int) Math.min(blobSize, length - index * blobSize); Blob b = file.createBlob(new ByteArrayInputStream(blob, 0, n)); if (index < data.size()) { @@ -317,6 +324,16 @@ } } + void close() throws IOException { + if (isOpen) { + if (!isReadOnly) { + flush(); + } + data.clear(); + isOpen = false; + } + } + @Override public String toString() { return name; @@ -330,7 +347,7 @@ public OakIndexInput(String name, NodeBuilder file) { super(name); - this.file = new OakIndexFile(name, file); + this.file = new OakIndexFile(name, file, true); } private OakIndexInput(OakIndexInput that) { @@ -371,8 +388,8 @@ } @Override - public void close() { - // do nothing + public void close() throws IOException { + file.close(); } } @@ -381,8 +398,8 @@ private final OakIndexFile file; - public OakIndexOutput(String name, NodeBuilder file) throws IOException { - this.file = new OakIndexFile(name, file); + public OakIndexOutput(String name, NodeBuilder file) { + this.file = new OakIndexFile(name, file, false); } @Override @@ -418,9 +435,8 @@ @Override public void close() throws IOException { - flush(); + file.close(); } - } }