Skip to content

Commit

Permalink
IGNITE-23114 Refactor 2 (with separate mem and file storage)
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkov committed Sep 24, 2024
1 parent c9fc008 commit f9e63d1
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ private static class MemoryStreamContext implements Context {
private int inBufPos;

public MemoryStreamContext(int idx, int inBufPos) {
set(idx, inBufPos);
}

public void set(int idx, int inBufPos) {
this.idx = idx;
this.inBufPos = inBufPos;
}
Expand Down Expand Up @@ -292,9 +296,7 @@ public MemoryStorage(byte[] arr) {

pos.setPos(pos.getPos() + step);

MemoryStreamContext context = (MemoryStreamContext)pos.context;
context.idx = idx;
context.inBufPos = inBufPos;
((MemoryStreamContext)pos.context).set(idx, inBufPos);
}

@Override public void truncate(long len) {
Expand Down Expand Up @@ -422,6 +424,13 @@ private static class FileStorage implements Storage {
}

@Override public void close() {
try {
tempFileChannel.close();
}
catch (IOException ignore) {
// No-op
}

tempFileCleaner.clean();
}

Expand Down Expand Up @@ -515,7 +524,7 @@ private BufferOutputStream(long pos) {

/** {@inheritDoc} */
@Override public void write(int b) throws IOException {
data.write(bufPos, new byte[] {(byte)b}, 0, 1);
data.write(bufPos, b);

totalCnt = Math.max(bufPos.getPos(), totalCnt);
}
Expand Down

0 comments on commit f9e63d1

Please sign in to comment.