Lines 361-377
Link Here
|
361 |
void initialize(boolean reuseExistingFile) throws IOException { |
361 |
void initialize(boolean reuseExistingFile) throws IOException { |
362 |
if (this.indexFile.exists()) { |
362 |
if (this.indexFile.exists()) { |
363 |
if (reuseExistingFile) { |
363 |
if (reuseExistingFile) { |
364 |
RandomAccessFile file = new RandomAccessFile(this.indexFile, "r"); //$NON-NLS-1$ |
364 |
FileInputStream stream = new FileInputStream(this.indexFile); |
|
|
365 |
this.streamBuffer = new byte[BUFFER_READ_SIZE]; |
365 |
try { |
366 |
try { |
366 |
String signature = file.readUTF(); |
367 |
char[] signature = readStreamChars(stream); |
367 |
if (!signature.equals(SIGNATURE)) |
368 |
if (!CharOperation.equals(signature, SIGNATURE_CHARS)) { |
368 |
throw new IOException(Messages.exception_wrongFormat); |
369 |
throw new IOException(Messages.exception_wrongFormat); |
369 |
|
370 |
} |
370 |
this.headerInfoOffset = file.readInt(); |
371 |
this.headerInfoOffset = readStreamInt(stream); |
371 |
if (this.headerInfoOffset > 0) // file is empty if its not set |
372 |
if (this.headerInfoOffset > 0) { // file is empty if its not set |
372 |
readHeaderInfo(file); |
373 |
readHeaderInfo(stream); |
|
|
374 |
} |
373 |
} finally { |
375 |
} finally { |
374 |
file.close(); |
376 |
stream.close(); |
375 |
} |
377 |
} |
376 |
return; |
378 |
return; |
377 |
} |
379 |
} |
Lines 750-777
Link Here
|
750 |
this.streamBuffer = null; |
752 |
this.streamBuffer = null; |
751 |
} |
753 |
} |
752 |
} |
754 |
} |
753 |
private void readHeaderInfo(RandomAccessFile file) throws IOException { |
755 |
private void readHeaderInfo(FileInputStream stream) throws IOException { |
754 |
file.seek(this.headerInfoOffset); |
756 |
stream.skip(this.headerInfoOffset); |
|
|
757 |
this.bufferIndex = 0; |
758 |
this.bufferEnd = stream.read(this.streamBuffer, 0, this.streamBuffer.length); |
755 |
|
759 |
|
756 |
// must be same order as writeHeaderInfo() |
760 |
// must be same order as writeHeaderInfo() |
757 |
this.numberOfChunks = file.readInt(); |
761 |
this.numberOfChunks = readStreamInt(stream); |
758 |
this.sizeOfLastChunk = file.readUnsignedByte(); |
762 |
this.sizeOfLastChunk = this.streamBuffer[this.bufferIndex++] & 0xFF; |
759 |
this.documentReferenceSize = file.readUnsignedByte(); |
763 |
this.documentReferenceSize = this.streamBuffer[this.bufferIndex++] & 0xFF; |
760 |
|
764 |
|
761 |
this.chunkOffsets = new int[this.numberOfChunks]; |
765 |
this.chunkOffsets = new int[this.numberOfChunks]; |
762 |
for (int i = 0; i < this.numberOfChunks; i++) |
766 |
for (int i = 0; i < this.numberOfChunks; i++) |
763 |
this.chunkOffsets[i] = file.readInt(); |
767 |
this.chunkOffsets[i] = readStreamInt(stream); |
764 |
|
768 |
|
765 |
this.startOfCategoryTables = file.readInt(); |
769 |
this.startOfCategoryTables = readStreamInt(stream); |
766 |
|
770 |
|
767 |
int size = file.readInt(); |
771 |
int size = readStreamInt(stream); |
768 |
this.categoryOffsets = new HashtableOfIntValues(size); |
772 |
this.categoryOffsets = new HashtableOfIntValues(size); |
769 |
this.categoryEnds = new HashtableOfIntValues(size); |
773 |
this.categoryEnds = new HashtableOfIntValues(size); |
770 |
char[] previousCategory = null; |
774 |
char[] previousCategory = null; |
771 |
int offset = -1; |
775 |
int offset = -1; |
772 |
for (int i = 0; i < size; i++) { |
776 |
for (int i = 0; i < size; i++) { |
773 |
char[] categoryName = INTERNED_CATEGORY_NAMES.get(file.readUTF().toCharArray()); |
777 |
char[] categoryName = INTERNED_CATEGORY_NAMES.get(readStreamChars(stream)); |
774 |
offset = file.readInt(); |
778 |
offset = readStreamInt(stream); |
775 |
this.categoryOffsets.put(categoryName, offset); // cache offset to category table |
779 |
this.categoryOffsets.put(categoryName, offset); // cache offset to category table |
776 |
if (previousCategory != null) { |
780 |
if (previousCategory != null) { |
777 |
this.categoryEnds.put(previousCategory, offset); // cache end of the category table |
781 |
this.categoryEnds.put(previousCategory, offset); // cache end of the category table |