本文整理汇总了Golang中github.com/balzaczyy/golucene/core/util.Close函数的典型用法代码示例。如果您正苦于以下问题:Golang Close函数的具体用法?Golang Close怎么用?Golang Close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Close
/* Closes all resouces and writes the entry table */
func (w *CompoundFileWriter) Close() (err error) {
if w.closed {
fmt.Println("CompoundFileWriter is already closed.")
return nil
}
// TODO this code should clean up after itself (remove partial .cfs/.cfe)
if err = func() (err error) {
var success = false
defer func() {
if success {
util.Close(w.dataOut)
} else {
util.CloseWhileSuppressingError(w.dataOut)
}
}()
assert2(w.pendingEntries.Len() == 0 && !w.outputTaken.Get(),
"CFS has pending open files")
w.closed = true
// open the compound stream; we can safely use IO_CONTEXT_DEFAULT
// here because this will only open the output if no file was
// added to the CFS
_, err = w.output(IO_CONTEXT_DEFAULT)
if err != nil {
return
}
assert(w.dataOut != nil)
err = codec.WriteFooter(w.dataOut)
if err != nil {
return
}
success = true
return nil
}(); err != nil {
return
}
var entryTableOut IndexOutput
var success = false
defer func() {
if success {
util.Close(entryTableOut)
} else {
util.CloseWhileSuppressingError(entryTableOut)
}
}()
entryTableOut, err = w.directory.CreateOutput(w.entryTableName, IO_CONTEXT_DEFAULT)
if err != nil {
return
}
err = w.writeEntryTable(w.entries, entryTableOut)
if err != nil {
return
}
success = true
return
}
示例2: Close
func (w *PerFieldPostingsWriter) Close() error {
var subs []io.Closer
for _, v := range w.formats {
subs = append(subs, v)
}
return util.Close(subs...)
}
示例3: Close
func (r *CompressingTermVectorsReader) Close() (err error) {
if !r.closed {
err = util.Close(r.vectorsStream)
r.closed = true
}
return err
}
示例4: Close
func (w *CompressingStoredFieldsWriter) Close() error {
defer func() {
w.fieldsStream = nil
w.indexWriter = nil
}()
return util.Close(w.fieldsStream, w.indexWriter)
}
示例5: Copy
/*
Copies the file src to 'to' under the new file name dest.
If you want to copy the entire source directory to the destination
one, you can do so like this:
var to Directory // the directory to copy to
for _, file := range dir.ListAll() {
dir.Copy(to, file, newFile, IO_CONTEXT_DEFAULT)
// newFile can be either file, or a new name
}
NOTE: this method does not check whether dest exists and will
overwrite it if it does.
*/
func (d *DirectoryImpl) Copy(to Directory, src, dest string, ctx IOContext) (err error) {
var os IndexOutput
var is IndexInput
var success = false
defer func() {
if success {
err = util.Close(os, is)
} else {
util.CloseWhileSuppressingError(os, is)
}
defer func() {
recover() // ignore panic
}()
to.DeleteFile(dest) // ignore error
}()
os, err = to.CreateOutput(dest, ctx)
if err != nil {
return err
}
is, err = d.spi.OpenInput(src, ctx)
if err != nil {
return err
}
err = os.CopyBytes(is, is.Length())
if err != nil {
return err
}
success = true
return nil
}
示例6: Close
func (w *Lucene41PostingsWriter) Close() (err error) {
var success = false
defer func() {
if success {
err = util.Close(w.docOut, w.posOut, w.payOut)
} else {
util.CloseWhileSuppressingError(w.docOut, w.posOut, w.payOut)
}
w.docOut = nil
w.posOut = nil
w.payOut = nil
}()
if err == nil && w.docOut != nil {
err = codec.WriteFooter(w.docOut)
}
if err == nil && w.posOut != nil {
err = codec.WriteFooter(w.posOut)
}
if err == nil && w.payOut != nil {
err = codec.WriteFooter(w.payOut)
}
if err != nil {
return
}
success = true
return nil
}
示例7: flush
func (tvc *TermVectorsConsumer) flush(fieldsToFlush map[string]TermsHashPerField,
state *model.SegmentWriteState) (err error) {
if tvc.writer != nil {
numDocs := state.SegmentInfo.DocCount()
assert(numDocs > 0)
// At least one doc in this run had term vectors enabled
func() {
defer func() {
err = mergeError(err, util.Close(tvc.writer))
tvc.writer = nil
tvc.lastDocId = 0
tvc.hasVectors = false
}()
err = tvc.fill(numDocs)
if err == nil {
err = tvc.writer.Finish(state.FieldInfos, numDocs)
}
}()
if err != nil {
return err
}
}
return
}
示例8: Close
func (nc *NormsConsumer) Close() (err error) {
var success = false
defer func() {
if success {
err = util.Close(nc.data, nc.meta)
} else {
util.CloseWhileSuppressingError(nc.data, nc.meta)
}
}()
if nc.meta != nil {
if err = nc.meta.WriteVInt(-1); err != nil { // write EOF marker
return
}
if err = codec.WriteFooter(nc.meta); err != nil { // write checksum
return
}
}
if nc.data != nil {
if err = codec.WriteFooter(nc.data); err != nil { // write checksum
return
}
}
success = true
return nil
}
示例9: Close
// Close the underlying IndexInputs
func (r *CompressingStoredFieldsReader) Close() (err error) {
if !r.closed {
if err = util.Close(r.fieldsStream); err == nil {
r.closed = true
}
}
return
}
示例10: decRef
func (r *SegmentCoreReaders) decRef() {
if atomic.AddInt32(&r.refCount, -1) == 0 {
util.Close( /*self.termVectorsLocal, self.fieldsReaderLocal, docValuesLocal, r.normsLocal,*/
r.fields, r.dvProducer, r.termVectorsReaderOrig, r.fieldsReaderOrig,
r.cfsReader, r.normsProducer)
r.notifyListener <- r.owner
}
}
示例11: Close
func (r *BlockTreeTermsReader) Close() error {
defer func() {
// Clear so refs to terms index is GCable even if
// app hangs onto us:
r.fields = make(map[string]FieldReader)
}()
return util.Close(r.in, r.postingsReader)
}
示例12: Close
func (w *BlockTreeTermsWriter) Close() (err error) {
var success = false
defer func() {
if success {
util.Close(w.out, w.indexOut, w.postingsWriter)
} else {
util.CloseWhileSuppressingError(w.out, w.indexOut, w.postingsWriter)
}
}()
dirStart := w.out.FilePointer()
indexDirStart := w.indexOut.FilePointer()
if err = w.out.WriteVInt(int32(len(w.fields))); err != nil {
return
}
for _, field := range w.fields {
// fmt.Printf(" field %v %v terms\n", field.fieldInfo.Name, field.numTerms)
if err = w.out.WriteVInt(field.fieldInfo.Number); err == nil {
assert(field.numTerms > 0)
if err = w.out.WriteVLong(field.numTerms); err == nil {
if err = w.out.WriteVInt(int32(len(field.rootCode))); err == nil {
err = w.out.WriteBytes(field.rootCode)
if err == nil && field.fieldInfo.IndexOptions() != INDEX_OPT_DOCS_ONLY {
err = w.out.WriteVLong(field.sumTotalTermFreq)
}
if err == nil {
if err = w.out.WriteVLong(field.sumDocFreq); err == nil {
if err = w.out.WriteVInt(int32(field.docCount)); err == nil {
if err = w.out.WriteVInt(int32(field.longsSize)); err == nil {
if err = w.indexOut.WriteVLong(field.indexStartFP); err == nil {
if err = writeBytesRef(w.out, field.minTerm); err == nil {
err = writeBytesRef(w.out, field.maxTerm)
}
}
}
}
}
}
}
}
}
}
if err == nil {
if err = w.writeTrailer(w.out, dirStart); err == nil {
if err = codec.WriteFooter(w.out); err == nil {
if err = w.writeIndexTrailer(w.indexOut, indexDirStart); err == nil {
if err = codec.WriteFooter(w.indexOut); err == nil {
success = true
}
}
}
}
}
return
}
示例13: decRef
func (r *SegmentCoreReaders) decRef() {
if atomic.AddInt32(&r.refCount, -1) == 0 {
fmt.Println("--- closing core readers")
util.Close( /*self.termVectorsLocal, self.fieldsReaderLocal, r.normsLocal,*/
r.fields, r.termVectorsReaderOrig, r.fieldsReaderOrig,
r.cfsReader, r.normsProducer)
r.notifyListener <- true
}
}
示例14: Close
func (w *CompressingStoredFieldsWriter) Close() error {
assert(w != nil)
defer func() {
if w != nil {
w.fieldsStream = nil
w.indexWriter = nil
}
}()
return util.Close(w.fieldsStream, w.indexWriter)
}
示例15: Close
func (dvp *PerFieldDocValuesReader) Close() error {
fps := make([]DocValuesProducer, 0)
for _, v := range dvp.formats {
fps = append(fps, v)
}
items := make([]io.Closer, len(fps))
for i, v := range fps {
items[i] = v
}
return util.Close(items...)
}