From 5ed67386298122627309687845b6d784a6e9f022 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Tue, 25 Mar 2008 01:47:11 +0000 Subject: [PATCH] better max size calculation git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@299 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/java/com/healthmarketscience/jackcess/Index.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 020f42f..b462b77 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -334,15 +334,16 @@ public class Index implements Comparable { buffer.put((byte) 0); //Unknown buffer.put((byte) 0); //Unknown byte[] entryMask = new byte[getFormat().SIZE_INDEX_ENTRY_MASK]; + int maxTotalSize = getFormat().PAGE_SIZE - + (getFormat().OFFSET_INDEX_ENTRY_MASK + entryMask.length); int totalSize = 0; for(Entry entry : _entries) { - int size = entry.size(); - totalSize += size; - int idx = totalSize / 8; - if(idx >= entryMask.length) { + totalSize += entry.size(); + if(totalSize > maxTotalSize) { throw new UnsupportedOperationException( "FIXME cannot write large index yet"); } + int idx = totalSize / 8; entryMask[idx] |= (1 << (totalSize % 8)); } buffer.put(entryMask); @@ -499,7 +500,7 @@ public class Index implements Comparable { indexPage, getFormat().OFFSET_INDEX_COMPRESSED_BYTE_COUNT); int entryMaskLength = getFormat().SIZE_INDEX_ENTRY_MASK; int entryMaskPos = getFormat().OFFSET_INDEX_ENTRY_MASK; - int entryPos = entryMaskPos + getFormat().SIZE_INDEX_ENTRY_MASK; + int entryPos = entryMaskPos + entryMaskLength; int lastStart = 0; byte[] valuePrefix = null; boolean firstEntry = true; -- 2.39.5