Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Private Attributes
FileTable Class Reference

Provides a way to map from byte offsets into a file to line numbers. More...

Collaboration diagram for FileTable:
Collaboration graph
[legend]

List of all members.

Classes

class  Line

Public Member Functions

 FileTable (String path) throws IOException
int getLine (int offset)

Private Attributes

Line[] mLines

Detailed Description

Provides a way to map from byte offsets into a file to line numbers.

Definition at line 43 of file FileTable.java.


Constructor & Destructor Documentation

FileTable.FileTable ( String  path) throws IOException [inline]

Definition at line 55 of file FileTable.java.

                                                        {
              Vector lines = new Vector();
              BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
              int offset = 0;
              for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                     // always add 1 for the line feed.
                     int length = 1 + line.length();
                     lines.addElement(new Line(offset, length));
                     offset += length;
              }
              reader.close();
              int size = lines.size();
              mLines = new Line[size];
              lines.copyInto(mLines);
       }

Here is the call graph for this function:


Member Function Documentation

int FileTable.getLine ( int  offset) [inline]

Definition at line 71 of file FileTable.java.

                                      {
              // use binary search to find the line which spans this offset.
              int length = mLines.length;
              int minIndex = 0, maxIndex = length - 1;
              int index = maxIndex / 2;
              while (minIndex <= maxIndex) {
                     Line line = mLines[index];
                     if (offset < line.mOffset) {
                            maxIndex = (index - 1);
                            index = (minIndex + maxIndex) / 2;
                     } else {
                            if (offset < (line.mOffset + line.mLength)) {
                                   return index;
                            }
                            minIndex = (index + 1);
                            index = (minIndex + maxIndex) / 2;
                     }
              }
              // this case shouldn't happen, but provides a helpful value to detect errors.
              return -1;
       }

Here is the caller graph for this function:


Member Data Documentation

Line [] FileTable.mLines [private]

Definition at line 53 of file FileTable.java.


The documentation for this class was generated from the following file: