-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
214 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Lucene.Net.Store; | ||
|
||
namespace DotJEM.Json.Index2.Snapshots | ||
{ | ||
public interface ISnapshotWriter : IDisposable | ||
{ | ||
ISnapshot Snapshot { get; } | ||
|
||
void WriteFile(string fileName, Directory dir); | ||
void WriteSegmentsFile(string segmentsFile, Directory dir); | ||
Task WriteFileAsync(string fileName, Directory dir); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
namespace DotJEM.Json.Index2.Snapshots | ||
using System; | ||
using System.IO; | ||
|
||
namespace DotJEM.Json.Index2.Snapshots | ||
{ | ||
|
||
public interface ILuceneFile | ||
{ | ||
string Name { get; } | ||
byte[] Bytes { get; } | ||
int Length { get; } | ||
long Length { get; } | ||
Stream Open(); | ||
} | ||
|
||
public class LuceneFile : ILuceneFile | ||
{ | ||
public byte[] Bytes { get; } | ||
public int Length { get; } | ||
private readonly Func<Stream> streamProvider; | ||
public string Name { get; } | ||
public long Length { get; } | ||
|
||
|
||
public LuceneFile(string name, byte[] bytes) | ||
public LuceneFile(string name, Func<Stream> streamProvider) | ||
{ | ||
Bytes = bytes; | ||
this.streamProvider = streamProvider; | ||
Name = name; | ||
Length = bytes.Length; | ||
} | ||
public Stream Open() | ||
=> streamProvider.Invoke(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/DotJEM.Json.Index2.Snapshots/Streams/IndexInputStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Lucene.Net.Store; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace DotJEM.Json.Index2.Snapshots.Streams; | ||
|
||
public class IndexInputStream : Stream | ||
{ | ||
public string FileName { get; } | ||
public IndexInput IndexInput { get; } | ||
|
||
public IndexInputStream(string fileName, IndexInput indexInput) | ||
{ | ||
FileName = fileName; | ||
IndexInput = indexInput; | ||
} | ||
|
||
public override void Flush() | ||
{ | ||
throw new InvalidOperationException("Cannot flush a readonly stream."); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
switch (origin) | ||
{ | ||
case SeekOrigin.Begin: | ||
Position = offset; | ||
break; | ||
case SeekOrigin.Current: | ||
Position += offset; | ||
break; | ||
case SeekOrigin.End: | ||
Position = Length - offset; | ||
break; | ||
} | ||
return Position; | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
throw new InvalidOperationException("Cannot change length of a readonly stream."); | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
long remaining = IndexInput.Length - IndexInput.Position; | ||
int readCount = (int)Math.Min(remaining, count); | ||
IndexInput.ReadBytes(buffer, offset, readCount); | ||
return readCount; | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
throw new InvalidCastException("Cannot write to a readonly stream."); | ||
} | ||
|
||
public override bool CanRead => true; | ||
public override bool CanSeek => true; | ||
public override bool CanWrite => false; | ||
public override long Length => IndexInput.Length; | ||
|
||
public override long Position | ||
{ | ||
get => IndexInput.Position; | ||
set => IndexInput.Seek(value); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
IndexInput.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/DotJEM.Json.Index2.Snapshots/Streams/IndexOutputStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.IO; | ||
using Lucene.Net.Store; | ||
|
||
namespace DotJEM.Json.Index2.Snapshots.Streams; | ||
|
||
public class IndexOutputStream : Stream | ||
{ | ||
public string FileName { get; } | ||
public IndexOutput IndexOutput { get; } | ||
|
||
public IndexOutputStream(string fileName, IndexOutput indexOutput) | ||
{ | ||
FileName = fileName; | ||
IndexOutput = indexOutput; | ||
} | ||
|
||
public override void Flush() | ||
{ | ||
IndexOutput.Flush(); | ||
} | ||
|
||
public override long Seek(long offset, SeekOrigin origin) | ||
{ | ||
switch (origin) | ||
{ | ||
case SeekOrigin.Begin: | ||
Position = offset; | ||
break; | ||
case SeekOrigin.Current: | ||
Position += offset; | ||
break; | ||
case SeekOrigin.End: | ||
Position = Length - offset; | ||
break; | ||
} | ||
return Position; | ||
} | ||
|
||
public override void SetLength(long value) | ||
{ | ||
IndexOutput.Length = Length; | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
throw new InvalidOperationException("Cannot read from a writeonly stream."); | ||
} | ||
|
||
public override void Write(byte[] buffer, int offset, int count) | ||
{ | ||
IndexOutput.WriteBytes(buffer, offset, count); | ||
} | ||
|
||
public override bool CanRead => false; | ||
public override bool CanSeek => true; | ||
public override bool CanWrite => true; | ||
public override long Length => IndexOutput.Length; | ||
|
||
public override long Position | ||
{ | ||
get => IndexOutput.Position; | ||
set => IndexOutput.Seek(value); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
IndexOutput.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
} |
Oops, something went wrong.