Well, that is basically what I do, just on a much smaller scale. So, maybe I
can increase the scale and see if that improves performance.
The code is as follows.
These two functions, initializes the CFC, creating a pointer array as well as
the java objects.
<cffunction name="init" access="public" returntype="void" output="false">
<cfargument name="file" type="string" required="true">
<cfscript>
variables.file = arguments.file;
variables.filePointers = arrayNew(1);
variables.filePointers[1] = 0;
variables.page = 1;
initJava();
</cfscript>
</cffunction>
<cffunction name="initJava" access="private" returntype="void" output="true">
<cfscript>
variables.randomAccessFile = createObject("java", "java.io.RandomAccessFile");
variables.randomAccessFile.init(variables.file,"r");
variables.EOF = false;
</cfscript>
</cffunction>
Here is my search function, which searches the text one "page" at a time.
<cffunction name="readSearch" access="public" returntype="string"
output="false">
<cfargument name="searchValue" required="yes" type="string">
<cfscript>
var foobar = "";
var breakit = 0;
var maxSearch = 100;
var timmer = getTickCount();
arguments.searchValue = "(" & arguments.searchValue & ")";
do
{
foobar = readForward();
breakit = breakit + 1;
} while (NOT reFind(arguments.searchValue,foobar) AND breakit LT maxSearch);
timmer = (getTickCount() - timmer) / 1000;
if (breakit EQ maxSearch AND NOT reFind(arguments.searchValue,foobar))
foobar = "<tr><td colspan='3'><strong>Search Failed</strong>: " & maxSearch & "
pages Searched in " & timmer & " seconds.</td></tr>" & foobar;
foobar = reReplace(foobar,arguments.searchValue,"<span style='background-color:
CCC;'>\1</span>","ALL");
</cfscript>
<cfreturn foobar>
</cffunction>
This function reads the next page in the file. If a pointer already exists, it
uses that otherwise it searches for the next pointer.
<cffunction name="readForward" access="public" returntype="string"
output="false">
<cfset var outputStr = readBlock(variables.filePointers[page])>
<cfset outputStr = "<tr><td colspan='3'><strong>Page: " & page & "</strong> | "
& numberformat(variables.filePointers[page + 1]) & " of " &
numberformat(variables.randomAccessFile.length()) & " bytes</td></tr>" &
outputStr>
<cfset variables.page = variables.page + 1>
<cfreturn outputStr>
</cffunction>
The code that actually reads the data from the file.
<cffunction name="readBlock" access="private" returntype="string"
output="false">
<cfargument name="filePointer" required="yes" type="numeric">
<cfscript>
var outputStr = "";
var line = "";
var linePointer = 0;
variables.randomAccessFile.seek(arguments.filePointer);
try
{
line = variables.randomAccessFile.readLine();
outputStr = outputStr & format(line);
do
{
linePointer = variables.randomAccessFile.getFilePointer();
line = variables.randomAccessFile.readLine();
if (NOT ReFind(">>Web Hit>>",line))
outputStr = outputStr & format(line);
} while (NOT ReFind(">>Web Hit>>",line));
if (variables.page EQ arrayLen(variables.filePointers))
arrayAppend(variables.filePointers,linePointer);
}
catch (coldfusion.runtime.UndefinedVariableException e)
{
// this indicates end of file, ok to ignore error
outputStr = outputStr & chr(13) & chr(10) & "<tr><td
colspan='3'>-----EOF-----</td></tr>";
variables.startLine = "";
variables.EOF = true;
}
</cfscript>
<cfreturn outputStr>
</cffunction>
Just copying this into the e-mail gave me another idea. I am using the
existing pointers when I know the for the start of a page block, but I could
also be using these page pointers for the end of the block as well. Stop
searching every time to define a page. I'm sure that would help some, after
the initial read of a section of the file.
--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
"C code. C code run. Run code run. Please!"
- Cynthia Dunning
Confidentiality Notice: This message including any
attachments is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the
intended recipient, please contact the sender and
delete any copies of this message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:214061
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54