本文整理汇总了Golang中github.com/balzaczyy/golucene/core/store.IndexInput.Length方法的典型用法代码示例。如果您正苦于以下问题:Golang IndexInput.Length方法的具体用法?Golang IndexInput.Length怎么用?Golang IndexInput.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/balzaczyy/golucene/core/store.IndexInput
的用法示例。
在下文中一共展示了IndexInput.Length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: seekDir
func (r *BlockTreeTermsReader) seekDir(input store.IndexInput, dirOffset int64) (err error) {
log.Printf("Seeking to: %v", dirOffset)
if r.version >= BTT_INDEX_VERSION_APPEND_ONLY {
input.Seek(input.Length() - 8)
if dirOffset, err = input.ReadLong(); err != nil {
return err
}
}
input.Seek(dirOffset)
return nil
}
示例2: seekDir
func (r *BlockTreeTermsReader) seekDir(input store.IndexInput, dirOffset int64) (err error) {
// log.Printf("Seeking to: %v", dirOffset)
if r.version >= TERMS_VERSION_CHECKSUM {
if err = input.Seek(input.Length() - codec.FOOTER_LENGTH - 8); err != nil {
return
}
if dirOffset, err = input.ReadLong(); err != nil {
return
}
} else if r.version >= TERMS_VERSION_APPEND_ONLY {
if err = input.Seek(input.Length() - 8); err != nil {
return
}
if dirOffset, err = input.ReadLong(); err != nil {
return
}
}
return input.Seek(dirOffset)
}
示例3: _crash
func (w *MockDirectoryWrapper) _crash() error {
w.crashed = true
w.openFiles = make(map[string]int)
w.openFilesForWrite = make(map[string]bool)
w.openFilesDeleted = make(map[string]bool)
files := w.unSyncedFiles
w.unSyncedFiles = make(map[string]bool)
// first force-close all files, so we can corrupt on windows etc.
// clone the file map, as these guys want to remove themselves on close.
m := make(map[io.Closer]error)
for k, v := range w.openFileHandles {
m[k] = v
}
for f, _ := range m {
f.Close() // ignore error
}
for name, _ := range files {
var action string
var err error
switch w.randomState.Intn(5) {
case 0:
action = "deleted"
err = w.deleteFile(name, true)
case 1:
action = "zeroes"
// Zero out file entirely
var length int64
length, err = w.FileLength(name)
if err == nil {
zeroes := make([]byte, 256)
var upto int64 = 0
var out store.IndexOutput
out, err = w.BaseDirectoryWrapperImpl.CreateOutput(name, NewDefaultIOContext(w.randomState))
if err == nil {
for upto < length && err == nil {
limit := length - upto
if int64(len(zeroes)) < limit {
limit = int64(len(zeroes))
}
err = out.WriteBytes(zeroes[:limit])
upto += limit
}
if err == nil {
err = out.Close()
}
}
}
case 2:
action = "partially truncated"
// Partially Truncate the file:
// First, make temp file and copy only half this file over:
var tempFilename string
for {
tempFilename = fmt.Sprintf("%v", w.randomState.Int())
if !w.BaseDirectoryWrapperImpl.FileExists(tempFilename) {
break
}
}
var tempOut store.IndexOutput
if tempOut, err = w.BaseDirectoryWrapperImpl.CreateOutput(tempFilename, NewDefaultIOContext(w.randomState)); err == nil {
var ii store.IndexInput
if ii, err = w.BaseDirectoryWrapperImpl.OpenInput(name, NewDefaultIOContext(w.randomState)); err == nil {
if err = tempOut.CopyBytes(ii, ii.Length()/2); err == nil {
if err = tempOut.Close(); err == nil {
if err = ii.Close(); err == nil {
// Delete original and copy bytes back:
if err = w.deleteFile(name, true); err == nil {
var out store.IndexOutput
if out, err = w.BaseDirectoryWrapperImpl.CreateOutput(name, NewDefaultIOContext(w.randomState)); err == nil {
if ii, err = w.BaseDirectoryWrapperImpl.OpenInput(tempFilename, NewDefaultIOContext(w.randomState)); err == nil {
if err = out.CopyBytes(ii, ii.Length()); err == nil {
if err = out.Close(); err == nil {
if err = ii.Close(); err == nil {
err = w.deleteFile(tempFilename, true)
}
}
}
}
}
}
}
}
}
}
}
case 3:
// the file survived intact:
action = "didn't change"
default:
action = "fully truncated"
// totally truncate the file to zero bytes
if err = w.deleteFile(name, true); err == nil {
var out store.IndexOutput
if out, err = w.BaseDirectoryWrapperImpl.CreateOutput(name, NewDefaultIOContext(w.randomState)); err == nil {
if err = out.SetLength(0); err == nil {
err = out.Close()
}
}
//.........这里部分代码省略.........