本文整理汇总了Java中org.apache.lucene.store.IndexOutput.writeInt方法的典型用法代码示例。如果您正苦于以下问题:Java IndexOutput.writeInt方法的具体用法?Java IndexOutput.writeInt怎么用?Java IndexOutput.writeInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.store.IndexOutput
的用法示例。
在下文中一共展示了IndexOutput.writeInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeSegmentsGen
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/**
* A utility for writing the {@link IndexFileNames#SEGMENTS_GEN} file to a
* {@link Directory}.
*
* <p>
* <b>NOTE:</b> this is an internal utility which is kept public so that it's
* accessible by code from other packages. You should avoid calling this
* method unless you're absolutely sure what you're doing!
*
* @lucene.internal
*/
public static void writeSegmentsGen(Directory dir, long generation) {
try {
IndexOutput genOutput = dir.createOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
try {
genOutput.writeInt(FORMAT_SEGMENTS_GEN_CURRENT);
genOutput.writeLong(generation);
genOutput.writeLong(generation);
CodecUtil.writeFooter(genOutput);
} finally {
genOutput.close();
dir.sync(Collections.singleton(IndexFileNames.SEGMENTS_GEN));
}
} catch (Throwable t) {
// It's OK if we fail to write this file since it's
// used only as one of the retry fallbacks.
IOUtils.deleteFilesIgnoringExceptions(dir, IndexFileNames.SEGMENTS_GEN);
}
}
示例2: testMixedDirectoryAndPolicy
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
public void testMixedDirectoryAndPolicy() throws IOException {
Directory readDir = new RAMDirectory();
updateIndex(readDir, 0, numDocsPerUpdate,
new KeepOnlyLastCommitDeletionPolicy());
verify(readDir, numDocsPerUpdate);
IndexOutput out =
readDir.createOutput("_" + (numDocsPerUpdate / maxBufferedDocs + 2)
+ ".cfs");
out.writeInt(0);
out.close();
Directory writeDir = new RAMDirectory();
Directory mixedDir = new MixedDirectory(readDir, writeDir);
updateIndex(mixedDir, numDocsPerUpdate, numDocsPerUpdate,
new MixedDeletionPolicy());
verify(readDir, numDocsPerUpdate);
verify(mixedDir, 2 * numDocsPerUpdate);
}
示例3: writeDgaps
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Write as a d-gaps list */
private void writeDgaps(IndexOutput output) throws IOException {
output.writeInt(-1); // mark using d-gaps
output.writeInt(size()); // write size
output.writeInt(count()); // write count
int last=0;
int n = count();
int m = bits.length;
for (int i=0; i<m && n>0; i++) {
if (bits[i]!=0) {
output.writeVInt(i-last);
output.writeByte(bits[i]);
last = i;
n -= BYTE_COUNTS[bits[i] & 0xFF];
}
}
}
示例4: write
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);
si.addFile(fileName);
final IndexOutput output = dir.createOutput(fileName, ioContext);
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().toString());
output.writeInt(si.getDocCount());
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeStringStringMap(si.getDiagnostics());
output.writeStringStringMap(Collections.<String,String>emptyMap());
output.writeStringSet(si.files());
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
// TODO: why must we do this? do we not get tracking dir wrapper?
IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
} else {
output.close();
}
}
}
示例5: write
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Save a single segment's info. */
@Override
public void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
si.addFile(fileName);
final IndexOutput output = dir.createOutput(fileName, ioContext);
boolean success = false;
try {
CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);
Version version = si.getVersion();
if (version.major < 3 || version.major > 4) {
throw new IllegalArgumentException("invalid major version: should be 3 or 4 but got: " + version.major + " segment=" + si);
}
// Write the Lucene version that created this segment, since 3.1
output.writeString(version.toString());
output.writeInt(si.getDocCount());
output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));
output.writeStringStringMap(si.getDiagnostics());
output.writeStringSet(si.files());
CodecUtil.writeFooter(output);
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(output);
// TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?
IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);
} else {
output.close();
}
}
}
示例6: writeToLuceneStream
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Override
/**
* Transforms vector to cartesian form and writes vector out in dense format.
*/
public void writeToLuceneStream(IndexOutput outputStream) {
toCartesian();
for (int i = 0; i < dimension * 2; ++i) {
try {
outputStream.writeInt(Float.floatToIntBits(coordinates[i]));
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例7: init
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Override
public void init(IndexOutput termsOut) throws IOException {
CodecUtil.writeHeader(termsOut, CODEC, VERSION_CURRENT);
// TODO: -- just ask skipper to "start" here
termsOut.writeInt(skipInterval); // write skipInterval
termsOut.writeInt(maxSkipLevels); // write maxSkipLevels
termsOut.writeInt(skipMinimum); // write skipMinimum
}
示例8: addShortsField
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
private void addShortsField(FieldInfo field, IndexOutput output, Iterable<Number> values) throws IOException {
field.putAttribute(legacyKey, LegacyDocValuesType.FIXED_INTS_16.name());
CodecUtil.writeHeader(output,
Lucene40DocValuesFormat.INTS_CODEC_NAME,
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
output.writeInt(2); // size
for (Number n : values) {
output.writeShort(n == null ? 0 : n.shortValue());
}
}
示例9: addIntsField
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
private void addIntsField(FieldInfo field, IndexOutput output, Iterable<Number> values) throws IOException {
field.putAttribute(legacyKey, LegacyDocValuesType.FIXED_INTS_32.name());
CodecUtil.writeHeader(output,
Lucene40DocValuesFormat.INTS_CODEC_NAME,
Lucene40DocValuesFormat.INTS_VERSION_CURRENT);
output.writeInt(4); // size
for (Number n : values) {
output.writeInt(n == null ? 0 : n.intValue());
}
}
示例10: addFixedStraightBytesField
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
private void addFixedStraightBytesField(FieldInfo field, IndexOutput output, Iterable<BytesRef> values, int length) throws IOException {
field.putAttribute(legacyKey, LegacyDocValuesType.BYTES_FIXED_STRAIGHT.name());
CodecUtil.writeHeader(output,
Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_CODEC_NAME,
Lucene40DocValuesFormat.BYTES_FIXED_STRAIGHT_VERSION_CURRENT);
output.writeInt(length);
for (BytesRef v : values) {
if (v != null) {
output.writeBytes(v.bytes, v.offset, v.length);
}
}
}
示例11: init
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Override
public void init(IndexOutput termsOut) throws IOException {
CodecUtil.writeHeader(termsOut, Lucene40PostingsReader.TERMS_CODEC, Lucene40PostingsReader.VERSION_CURRENT);
termsOut.writeInt(skipInterval); // write skipInterval
termsOut.writeInt(maxSkipLevels); // write maxSkipLevels
termsOut.writeInt(skipMinimum); // write skipMinimum
}
示例12: createOutput
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Override
public IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {
final IndexOutput out = dir.createOutput(fileName, context);
boolean success = false;
try {
out.writeInt(baseBlockSize);
VariableIntBlockIndexOutput ret = new VariableIntBlockIndexOutput(out, 2*baseBlockSize) {
int pendingCount;
final int[] buffer = new int[2+2*baseBlockSize];
@Override
protected int add(int value) throws IOException {
buffer[pendingCount++] = value;
// silly variable block length int encoder: if
// first value <= 3, we write N vints at once;
// else, 2*N
final int flushAt = buffer[0] <= 3 ? baseBlockSize : 2*baseBlockSize;
// intentionally be non-causal here:
if (pendingCount == flushAt+1) {
for(int i=0;i<flushAt;i++) {
out.writeVInt(buffer[i]);
}
buffer[0] = buffer[flushAt];
pendingCount = 1;
return flushAt;
} else {
return 0;
}
}
};
success = true;
return ret;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(out);
}
}
}
示例13: testWritingAndReadingAFile
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
@Test
public void testWritingAndReadingAFile() throws IOException {
String[] listAll = directory.listAll();
for (String file : listAll) {
directory.deleteFile(file);
}
IndexOutput output = directory.createOutput("testing.test", new IOContext());
output.writeInt(12345);
output.flush();
output.close();
IndexInput input = directory.openInput("testing.test", new IOContext());
assertEquals(12345, input.readInt());
input.close();
listAll = directory.listAll();
assertEquals(1, listAll.length);
assertEquals("testing.test", listAll[0]);
assertEquals(4, directory.fileLength("testing.test"));
IndexInput input1 = directory.openInput("testing.test", new IOContext());
IndexInput input2 = (IndexInput) input1.clone();
assertEquals(12345, input2.readInt());
input2.close();
assertEquals(12345, input1.readInt());
input1.close();
assertFalse(slowFileExists(directory, "testing.test.other"));
assertTrue(slowFileExists(directory, "testing.test"));
directory.deleteFile("testing.test");
assertFalse(slowFileExists(directory, "testing.test"));
}
示例14: insertData
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
private void insertData() throws IOException {
final byte[] test = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
final IndexOutput indexOutput = jdbcDirectory.createOutput("value1", new IOContext());
indexOutput.writeInt(-1);
indexOutput.writeLong(10);
indexOutput.writeInt(0);
indexOutput.writeInt(0);
indexOutput.writeBytes(test, 8);
indexOutput.writeBytes(test, 5);
indexOutput.writeByte((byte) 8);
indexOutput.writeBytes(new byte[] { 1, 2 }, 2);
indexOutput.close();
}
示例15: writeBits
import org.apache.lucene.store.IndexOutput; //导入方法依赖的package包/类
/** Write as a bit set */
private void writeBits(IndexOutput output) throws IOException {
output.writeInt(size()); // write size
output.writeInt(count()); // write count
output.writeBytes(bits, bits.length);
}