/
indexio.go
108 lines (84 loc) · 3.12 KB
/
indexio.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package store
import "io"
// IndexInput Abstract base class for input from a file in a Directory. A random-access input stream. Used for
// all Lucene index input operations.
//
// IndexInput may only be used from one thread, because it is not thread safe (it keeps internal state like
// file pos). To allow multithreaded use, every IndexInput instance must be cloned before it is used in
// another thread. Subclasses must therefore implement clone(), returning a new IndexInput which operates on
// the same underlying resource, but positioned independently.
//
// Warning: Lucene never closes cloned IndexInputs, it will only call close() on the original object.
// If you access the cloned IndexInput after closing the original object, any readXXX methods will throw
// AlreadyClosedException.
// See Also: Directory
type IndexInput interface {
DataInput
io.Closer
// Seeker Sets current pos in this file, where the next read will occur. If this is beyond the end
// of the file then this will throw EOFException and then the stream is in an undetermined state.
// See Also: getFilePointer()
//Seek(pos int64, whence int) (int64, error)
io.Seeker
IndexInputSPI
//Clone() IndexInput
}
type IndexInputSPI interface {
// GetFilePointer Returns the current pos in this file, where the next read will occur.
// See Also: seek(long)
GetFilePointer() int64
// Slice Creates a slice of this index input, with the given description, offset, and length.
// The slice is sought to the beginning.
Slice(sliceDescription string, offset, length int64) (IndexInput, error)
// Length The number of bytes in the file.
Length() int64
// RandomAccessSlice Creates a random-access slice of this index input, with the given offset and length.
// The default implementation calls slice, and it doesn't support random access, it implements absolute
// reads as seek+read.
RandomAccessSlice(offset int64, length int64) (RandomAccessInput, error)
}
type BaseIndexInput struct {
*BaseDataInput
spi IndexInputSPI
}
func (i *BaseIndexInput) RandomAccessSlice(offset int64, length int64) (RandomAccessInput, error) {
slice, err := i.spi.Slice("randomaccess", offset, length)
if err != nil {
return nil, err
}
if random, ok := slice.(RandomAccessInput); ok {
return random, nil
}
return &randomAccessIndexInput{in: slice}, nil
}
func NewBaseIndexInput(input IndexInput) *BaseIndexInput {
return &BaseIndexInput{
BaseDataInput: NewBaseDataInput(input),
spi: input,
}
}
// IndexOutput A DataOutput for appending data to a file in a Directory.
// Instances of this class are not thread-safe.
// See Also: Directory, IndexInput
type IndexOutput interface {
io.Closer
DataOutput
GetName() string
// GetFilePointer Returns the current pos in this file,
// where the next write will occur.
GetFilePointer() int64
GetChecksum() (uint32, error)
}
type BaseIndexOutput struct {
*BaseDataOutput
name string
}
func NewBaseIndexOutput(name string, writer io.Writer) *BaseIndexOutput {
return &BaseIndexOutput{
BaseDataOutput: NewBaseDataOutput(writer),
name: name,
}
}
func (r *BaseIndexOutput) GetName() string {
return r.name
}