com.microsoft.azure.kusto.ingest.ResettableFileInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kusto-ingest Show documentation
Show all versions of kusto-ingest Show documentation
Kusto client library for ingesting data
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
package com.microsoft.azure.kusto.ingest;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class ResettableFileInputStream extends FilterInputStream {
private final FileChannel myFileChannel;
private long mark = -1;
public ResettableFileInputStream(FileInputStream fis) {
super(fis);
myFileChannel = fis.getChannel();
mark(0);
}
@Override
public boolean markSupported() {
return true;
}
@Override
public synchronized void mark(int ignored) {
try {
mark = myFileChannel.position();
} catch (IOException ex) {
mark = -1;
}
}
@Override
public synchronized void reset() throws IOException {
if (mark == -1) {
throw new IOException("not marked");
}
myFileChannel.position(mark);
}
}