private synchronized void saveToIndexOfIndexFile(String fileName) throws IOException { FileAccessBase file = FileFactory.newFileAccess(fileName); if (file == null) { return; } if (!file.exists()) { file.create(); } if (file.isFile() && file.canWrite()) { int writeBufLen = 256 + 1 + 16; byte[] buf = new byte[bufLen]; int pos = 0; int ret = 0; int contentLength = 0; starIndex.putIntintoByte(this.bucketSize, 0, buf); // System.out.println("write " + wordList.size()); file.write(buf, 0, 4); for (int i = 0; i < wordList.size(); i++) { starIndexItem item = (starIndexItem) wordList.elementAt(i); if (item.getBytes().length + 19 + pos < bufLen) { ByteArrayString.byteCopy(item.getBytes(), 0, buf, pos, item.getBytes().length); pos += item.getBytes().length; buf[pos] = 0; pos++; starIndex.putIntintoByte(item.getbucket(0).getStart(), pos, buf); pos += 4; starIndex.putIntintoByte(item.getbucket(0).getLength(), pos, buf); pos += 4; starIndex.putIntintoByte(item.getStart(), pos, buf); pos += 4; starIndex.putIntintoByte(item.getLength(), pos, buf); pos += 4; } else { file.write(buf, 0, pos); pos = 0; i--; } } if (pos != 0) { file.write(buf, 0, pos); } file.flush(); file.close(); buf = null; } }