public PointerReadableByteBufferFile(long maxBufferSegmentSize,
File file, boolean writeable) throws IOException {
this.maxBufferSegmentSize = Math.min(UIO.chunkLength(UIO.chunkPower(maxBufferSegmentSize, 0)), MAX_BUFFER_SEGMENT_SIZE);
this.file = file;
this.writeable = writeable;
if ((this.maxBufferSegmentSize & (this.maxBufferSegmentSize - 1)) == 0) {
this.fShift = Long.numberOfTrailingZeros(this.maxBufferSegmentSize);
this.fseekMask = this.maxBufferSegmentSize - 1;
} else {
throw new IllegalArgumentException("It's hard to ensure powers of 2");
}
this.length = file.length();
long position = this.length;
int filerIndex = (int) (position >> fShift);
long filerSeek = position & fseekMask;
int newLength = filerIndex + 1;
ByteBuffer[] newFilers = new ByteBuffer[newLength];
for (int n = 0; n < newLength; n++) {
if (n < newLength - 1) {
newFilers[n] = allocate(n, maxBufferSegmentSize);
} else {
newFilers[n] = allocate(n, filerSeek);
}
}
bbs = newFilers;
}