/** Close <code>RandomAccessFile</code>. */ public void close() { if (raf != null) { try { raf.close(); } catch (IOException e) { } raf = null; ffReadLine.setRaf(raf); } }
/** * @param offset file pointer to start reading lines from * @param prefixArr prefix to search forward for * @return offset where the search found the first match or EOF * @throws IOException if an I/O exception occurs while searching */ public long search(long offset, char[] prefixArr) throws IOException { // debug // System.out.println(offset + " - " + prefix); String tmpStr; ffReadLine.seek(offset); if (offset > 0) { ffReadLine.readLine(); } while (true) { offset = ffReadLine.filePointer; tmpStr = ffReadLine.readLine(); if (tmpStr == null) { break; } if (psComparator.comparePrefix(prefixArr, tmpStr.toCharArray()) <= 0) { break; } } ffReadLine.reset(); return offset; }
/** * Try to open the flat file, suppress file not found exception for open lock problems but throw * it if the file does not exist. * * @return true, if the opening was successful * @throws FileNotFoundException if the flat file does not exist */ public boolean open() throws FileNotFoundException { if (raf == null) { if (flatFile.exists() && flatFile.isFile()) { try { raf = new RandomAccessFile(flatFile, "r"); ffReadLine.setRaf(raf); } catch (FileNotFoundException e) { } } else { throw new FileNotFoundException(); } } return raf != null; }
/** * Read the next line at the current file pointer. * * @return next line at the current file pointer * @throws IOException if an I/O exception occurs while reading tne next line */ public String readLine() throws IOException { return ffReadLine.readLine(); }