From 89aba400dfc33570c8ac7e20203a2f3d6f588268 Mon Sep 17 00:00:00 2001
From: Robert Muir
Date: Thu, 24 May 2012 12:25:33 +0000
Subject: [PATCH] LUCENE-4055: add codecHeader
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1342223 13f79535-47bb-0310-9956-ffa450edef68
---
.../lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java | 6 +++++-
.../lucene/codecs/lucene40/Lucene40SegmentInfoReader.java | 4 ++++
.../lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java | 2 ++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java
index 501856b674e..4f9b485d147 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java
@@ -29,12 +29,13 @@ import org.apache.lucene.store.DataOutput; // javadocs
*
* Files:
*
- * - .si: SegVersion, SegSize, IsCompoundFile, Diagnostics, Attributes, Files
+ *
- .si: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Attributes, Files
*
*
* Data types:
*
*
+ * - Header --> {@link CodecUtil#writeHeader CodecHeader}
* - SegSize --> {@link DataOutput#writeInt Int32}
* - SegVersion --> {@link DataOutput#writeString String}
* - Files --> {@link DataOutput#writeStringSet Set<String>}
@@ -80,4 +81,7 @@ public class Lucene40SegmentInfoFormat extends SegmentInfoFormat {
}
public final static String SI_EXTENSION = "si";
+ static final String CODEC_NAME = "Lucene40SegmentInfo";
+ static final int VERSION_START = 0;
+ static final int VERSION_CURRENT = VERSION_START;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java
index 90f5347ac1f..b7b25070099 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java
@@ -28,6 +28,7 @@ import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.CodecUtil;
import org.apache.lucene.util.IOUtils;
/**
@@ -44,6 +45,9 @@ public class Lucene40SegmentInfoReader extends SegmentInfoReader {
final IndexInput input = dir.openInput(fileName, context);
boolean success = false;
try {
+ CodecUtil.checkHeader(input, Lucene40SegmentInfoFormat.CODEC_NAME,
+ Lucene40SegmentInfoFormat.VERSION_START,
+ Lucene40SegmentInfoFormat.VERSION_CURRENT);
final String version = input.readString();
final int docCount = input.readInt();
final Map normGen = null;
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java
index ed2cc077575..6c323d3a884 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java
@@ -26,6 +26,7 @@ import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.CodecUtil;
import org.apache.lucene.util.IOUtils;
/**
@@ -46,6 +47,7 @@ public class Lucene40SegmentInfoWriter extends SegmentInfoWriter {
boolean success = false;
try {
+ CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);
// Write the Lucene version that created this segment, since 3.1
output.writeString(si.getVersion());
output.writeInt(si.getDocCount());