github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/store/output.go (about) 1 package store 2 3 import ( 4 "github.com/balzaczyy/golucene/core/util" 5 "io" 6 ) 7 8 /* 9 Wrap IndexOutput to allow coding in flow style without worrying about 10 error check. If error happens in the middle, following calls are just 11 ignored. 12 */ 13 type IndexOutputStream struct { 14 err error 15 out IndexOutput 16 } 17 18 func Stream(out IndexOutput) *IndexOutputStream { 19 return &IndexOutputStream{out: out} 20 } 21 22 func (ios *IndexOutputStream) WriteString(s string) *IndexOutputStream { 23 if ios.err == nil { 24 ios.err = ios.out.WriteString(s) 25 } 26 return ios 27 } 28 29 func (ios *IndexOutputStream) WriteInt(i int32) *IndexOutputStream { 30 if ios.err == nil { 31 ios.err = ios.out.WriteInt(i) 32 } 33 return ios 34 } 35 36 func (ios *IndexOutputStream) WriteVInt(i int32) *IndexOutputStream { 37 if ios.err == nil { 38 ios.err = ios.out.WriteVInt(i) 39 } 40 return ios 41 } 42 43 func (ios *IndexOutputStream) WriteLong(l int64) *IndexOutputStream { 44 if ios.err == nil { 45 ios.err = ios.out.WriteLong(l) 46 } 47 return ios 48 } 49 50 func (ios *IndexOutputStream) WriteByte(b byte) *IndexOutputStream { 51 if ios.err == nil { 52 ios.err = ios.out.WriteByte(b) 53 } 54 return ios 55 } 56 57 func (ios *IndexOutputStream) WriteBytes(b []byte) *IndexOutputStream { 58 if ios.err == nil { 59 ios.err = ios.out.WriteBytes(b) 60 } 61 return ios 62 } 63 64 func (ios *IndexOutputStream) WriteStringStringMap(m map[string]string) *IndexOutputStream { 65 if ios.err == nil { 66 ios.err = ios.out.WriteStringStringMap(m) 67 } 68 return ios 69 } 70 71 func (ios *IndexOutputStream) WriteStringSet(m map[string]bool) *IndexOutputStream { 72 if ios.err == nil { 73 ios.err = ios.out.WriteStringSet(m) 74 } 75 return ios 76 } 77 78 func (ios *IndexOutputStream) Close() error { 79 return ios.err 80 } 81 82 // store/IndexOutput.java 83 84 type IndexOutput interface { 85 io.Closer 86 util.DataOutput 87 // Forces any buffered output to be written. 88 // Flush() error 89 // Returns the current position in this file, where the next write will occur. 90 FilePointer() int64 91 // Returns the current checksum of bytes written so far 92 Checksum() int64 93 } 94 95 type IndexOutputImpl struct { 96 *util.DataOutputImpl 97 } 98 99 func NewIndexOutput(part util.DataWriter) *IndexOutputImpl { 100 return &IndexOutputImpl{util.NewDataOutput(part)} 101 } 102 103 // func (out *IndexOutputImpl) SetLength(length int64) error { 104 // return nil 105 // }