@Test public void testRemoveAfter() throws IOException { ByteArraySeekableFile seekableFile = makeEntryIndexFileContent(5, 6); long oldSize = seekableFile.size(); EntryIndexFile file = new EntryIndexFile(seekableFile); file.removeAfter(6); Assert.assertEquals(5, file.getMinEntryIndex()); Assert.assertEquals(6, file.getMaxEntryIndex()); Assert.assertEquals(oldSize, seekableFile.size()); Assert.assertEquals(2, file.getEntryIndexCount()); }
public void removeAfter(int newMaxEntryIndex) throws IOException { if (isEmpty() || newMaxEntryIndex >= maxEntryIndex) { return; } if (newMaxEntryIndex < minEntryIndex) { clear(); return; } seekableFile.seek(OFFSET_MAX_ENTRY_INDEX); seekableFile.writeInt(newMaxEntryIndex); seekableFile.truncate(getOffsetOfEntryIndexItem(newMaxEntryIndex + 1)); for (int i = newMaxEntryIndex + 1; i <= maxEntryIndex; i++) { entryIndexMap.remove(i); } maxEntryIndex = newMaxEntryIndex; entryIndexCount = newMaxEntryIndex - minEntryIndex + 1; }
EntryIndexFile implements Iterable<EntryIndexItem> { public void removeAfter(int newMaxEntryIndex) throws IOException { if (isEmpty() || newMaxEntryIndex >= maxEntryIndex) { return; } if (newMaxEntryIndex < minEntryIndex) { clear(); return; } seekableFile.seek(OFFSET_MAX_ENTRY_INDEX); seekableFile.writeInt(newMaxEntryIndex); seekableFile.truncate(getOffsetOfEntryIndexItem(newMaxEntryIndex + 1)); for (int i = newMaxEntryIndex + 1; i <= maxEntryIndex; i++) { entryIndexMap.remove(i); } maxEntryIndex = newMaxEntryIndex; entryIndexCount = newMaxEntryIndex - minEntryIndex + 1; } }
EntryIndexFile implements Iterable<EntryIndexItem> { public void removeAfter(int newMaxEntryIndex) throws IOException { if (isEmpty() || newMaxEntryIndex >= maxEntryIndex) { return; } if (newMaxEntryIndex < minEntryIndex) { clear(); return; } seekableFile.seek(OFFSET_MAX_ENTRY_INDEX); seekableFile.writeInt(newMaxEntryIndex); seekableFile.truncate(getOffsetOfEntryIndexItem(newMaxEntryIndex + 1)); for (int i = newMaxEntryIndex + 1; i <= maxEntryIndex; i++) { entryIndexMap.remove(i); } maxEntryIndex = newMaxEntryIndex; entryIndexCount = newMaxEntryIndex - minEntryIndex + 1; } EntryIndexFile(File file);  EntryIndexFile(SeekableFile seekableFile); }
EntryIndexFile implements Iterable<EntryIndexItem> { public void removeAfter(int newMaxEntryIndex) throws IOException { if (isEmpty() || newMaxEntryIndex >= maxEntryIndex) { return; } if (newMaxEntryIndex < minEntryIndex) { clear(); return; } seekableFile.seek(OFFSET_MAX_ENTRY_INDEX); seekableFile.writeInt(newMaxEntryIndex); seekableFile.truncate(getOffsetOfEntryIndexItem(newMaxEntryIndex + 1)); for (int i = newMaxEntryIndex + 1; i <= maxEntryIndex; i++) { entryIndexMap.remove(i); } maxEntryIndex = newMaxEntryIndex; entryIndexCount = newMaxEntryIndex - minEntryIndex + 1; } EntryIndexFile(File file);  EntryIndexFile(SeekableFile seekableFile); boolean isEmpty(); int getMinEntryIndex(); int getMaxEntryIndex(); int getEntryIndexCount(); void appendEntryIndex(int index, long offset, int kind, int term); void clear(); void removeAfter(int newMaxEntryIndex); long getOffset(int entryIndex); @Nonnull EntryIndexItem get(int entryIndex); @Override @Nonnull Iterator<EntryIndexItem> iterator(); void close(); }
EntryIndexFile implements Iterable<EntryIndexItem> { public void removeAfter(int newMaxEntryIndex) throws IOException { if (isEmpty() || newMaxEntryIndex >= maxEntryIndex) { return; } if (newMaxEntryIndex < minEntryIndex) { clear(); return; } seekableFile.seek(OFFSET_MAX_ENTRY_INDEX); seekableFile.writeInt(newMaxEntryIndex); seekableFile.truncate(getOffsetOfEntryIndexItem(newMaxEntryIndex + 1)); for (int i = newMaxEntryIndex + 1; i <= maxEntryIndex; i++) { entryIndexMap.remove(i); } maxEntryIndex = newMaxEntryIndex; entryIndexCount = newMaxEntryIndex - minEntryIndex + 1; } EntryIndexFile(File file);  EntryIndexFile(SeekableFile seekableFile); boolean isEmpty(); int getMinEntryIndex(); int getMaxEntryIndex(); int getEntryIndexCount(); void appendEntryIndex(int index, long offset, int kind, int term); void clear(); void removeAfter(int newMaxEntryIndex); long getOffset(int entryIndex); @Nonnull EntryIndexItem get(int entryIndex); @Override @Nonnull Iterator<EntryIndexItem> iterator(); void close();  }