public AbstractFile findFileByOffset(final long offset, final boolean returnFirstIfNotFound) {
        this.readLock.lock();
        try {
            if (this.files.size() == 0)
                return null;
            final AbstractFile firstAbstractFile = getFirstFile();
            final AbstractFile lastAbstractFile = getLastFile();
            if (firstAbstractFile != null && lastAbstractFile != null) {
                if (offset < firstAbstractFile.getFileFromOffset()
                    || offset >= lastAbstractFile.getFileFromOffset() + this.fileSize) {
                    LOG.warn(
                        "Offset not matched. Request offset: {}, firstOffset: {}, lastOffset: {}, fileSize: {}, fileNums: {}",
                        offset, firstAbstractFile.getFileFromOffset(), lastAbstractFile.getFileFromOffset()
                                                                       + this.fileSize, this.fileSize,
                        this.files.size());
                } else {
                    // Locate the index
                    final int index = (int) ((offset / this.fileSize) - (firstAbstractFile.getFileFromOffset() / this.fileSize));
                    AbstractFile targetFile;
                    targetFile = this.files.get(index);

                    if (targetFile != null && offset >= targetFile.getFileFromOffset()
                        && offset < targetFile.getFileFromOffset() + this.fileSize) {
                        return targetFile;
                    }

                    // If pre not found , then traverse to find target file
                    for (final AbstractFile abstractFile : this.files) {
                        if (offset >= abstractFile.getFileFromOffset()
                            && offset < abstractFile.getFileFromOffset() + this.fileSize) {
                            return abstractFile;
                        }
                    }
                }
                if (returnFirstIfNotFound) {
                    return firstAbstractFile;
                }
            }
        } catch (final Exception e) {
            LOG.error("Error on find abstractFile by offset :{}, file type:{}", offset, this.fileType.getFileName(), e);
        } finally {
            this.readLock.unlock();
        }
        return null;
    }
@Test
    public void testFindAbstractFileByOffset() {
        writeDataToSecondFile();
        {
            // Test find first file by offset 0
            final AbstractFile firstFile = this.fileManager.findFileByOffset(30, false);
            assertEquals(firstFile.getFileFromOffset(), 0);
            // Test find second file by offset 136
            final AbstractFile secondFile = this.fileManager.findFileByOffset(this.indexFileSize + 10, false);
            assertEquals(secondFile.getFileFromOffset(), this.indexFileSize);
        }
    }