Reading a large file?  I created an Applescript to read an XML document...

I created an Applescript to read an XML document that had been exported from Final Cut Pro but it has trouble reading anything larger than a 1mb. Even 500kb takes a long time.
My code is most likely very ineffecient, but I have little experience with Applescript. The script reads an XML document one line at a time then breaks down each line into it's componenents and literally reads each character looking for "<name>" then it checks to see if "<reel>" came before it. It then records the name in between "<name>" and "</name>." Then I get my list of tapes that are in the Final Cut Pro project. Does anyone have any advice on how to improve this code?
property type_list : {"TEXT", "XML"}
property extension_list : {"TXT", "XML"}
on open these_items
tell application "Finder"
set my_file to these_items as string
set file_ref to (open for access my_file) read
close access file my_file
set AppleScript's text item delimiters to ASCII character 10
set new_list to every text item of file_ref
set lengthofarray to length of new_list
set h to 1
set shotcount to 0
set finalShots to {"You have ", "", " shots in your project."}
set finalListoftapes to {"Your list of tapes are:", ""}
repeat lengthofarray times
set i to 1
set x to 1
set switch to 0
set z to {""}
set reelName to {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}
set letter_list to item h of new_list
set AppleScript's text item delimiters to ""
set final_list to every text item of letter_list
set lengthofletter_list to length of final_list
repeat lengthofletter_list times
if item i of final_list is "<"a" then
if item (i + 3) of final_list is "m" then
set letter_list2 to item (h - 1) of new_list
set final_list2 to every text item of letter_list2
set lengthofletter_list2 to length of final_list2
set j to 1
repeat lengthofletter_list2 times
if item j of final_list2 is "<" then
if item (j + 1) of final_list2 is "r" then
if item (j + 2) of final_list2 is "e" then
set x to (i + 6)
set y to 1
repeat while item 1 of z is not "<"
set item y of reelName to item x of final_list
set x to (x + 1)
set y to (y + 1)
set item 1 of z to item x of final_list as string
end repeat
if item 1 of reelName is not "" then
set displayText to reelName as string
set lengthofListoftapes to length of finalListoftapes
set shotcount to (shotcount + 1)
set k to 1
repeat lengthofListoftapes times
if item k of finalListoftapes is equal to displayText then
set switch to 1
end if
set k to (k + 1)
end repeat
if switch is 0 then
set finalListoftapes to (finalListoftapes & displayText)
set check to finalListoftapes as string
end if
set switch to 0
end if
end if
end if
end if
set j to (j + 1)
end repeat
end if
end if
end if
end if
set i to (i + 1)
end repeat
set h to (h + 1)
end repeat
set item 2 of finalShots to shotcount
set finalShots to finalShots as string
set AppleScript's text item delimiters to ASCII character 10
set finalListoftapes to finalListoftapes as string
set finalListoftapes to finalShots & (ASCII character 10) & (ASCII character 10) & finalListoftapes & (ASCII character 10) & (ASCII character 10) & "This list of tapes has been saved on your desktop."
set path_list to these_items as string
set filepath to path_list & "_listoffiles.txt"
set outputFile to (open for access file filepath with write permission)
write finalListoftapes to outputFile
close access outputFile
display dialog finalListoftapes
end tell
end open

Try changing your approach - don't read it into an array, process it one line at a time. Obviously any approach where you have the whole file in memory is going to exceed memory at some size of the file.

Similar Messages

  • How can I get to read a large file and not break it up into bits

    How do I read a large file and not get the file cut into bits so each has its own beginning and ending.
    if the file was read on the line 11 and I wanted to read at 3 and then read again at 10.
    how do I specify the byte in the file of the large file since the read function has a read(byteb[],index,bytes to read);
    And it will only index in the array of bytes itself.
    San Htat

    tjacobs01 wrote:
    Peter__Lawrey wrote:
    Try RandomAccessFile. Not only do I hate RandomAccessFiles because of their inefficiency and limited use in today's computing world, The one dominated by small devices with SSD? Or the one dominated by large database servers and b-trees?
    I would also like to hate on the name 'RandomAccessFile' almost always, there's nothing 'random' about the access. I tend to think of the tens of thousands of databases users were found to have created in local drives in one previous employer's audit. Where's the company's mission-critical software? It's in some random Access file.
    Couldn't someone have come up with a better name, like NonlinearAccessFile? I guess the same goes for RAM to...Non-linear would imply access times other than O(N), but typically not constant, whereas RAM is nominally O(1), except it is highly optimised for consecutive access, as are spinning disk files, except RAM is fast in either direction.
    [one of these things is not like the other|] silicon disks are much better at random access than rust disks and [Machine architecture|] at about 1:40 - RAM is much worse at random access than sequential.

  • Hello, I am having issues open very large files I created, one being 1,241,776 KB. I have PS 12.1 with 64 bit version. I am not sure if they issues I am having is because of the PS version I have, and whether or not I have to upgrade?

    Hello, I am having issues open very large files I created, one being 1,241,776 KB. I have PS 12.1 with 64 bit version. I am not sure if they issues I am having is because of the PS version I have, and whether or not I have to upgrade?

    I think more likely, it's a memory / scratch disk issue.  1.25 gigabytes is a very big image file!!
    Nancy O.

  • What is the best, most efficient way to read a .xls File and create a pipe-delimited .csv File?

    What is the best and most efficient way to read a .xls File and create a pipe-delimited .csv File?
    Thanks in advance for your review and am hopeful for a reply.

    You should have no trouble doing this in SSIS. Simply add a data flow with connection managers to an existing .xls file (excel connection manager) and a new .csv file (flat file). Add a source to the xls and destination to the csv, and set the destination
    csv parameter "delay validation" to true. Use an expression to define the name of the new .csv file.
    In the flat file connection manager, set the column delimiter to the pipe character.

  • Please advice me on reading a large file

    I need and advice on reading a large file using JSP. I need to read a text file which contains around 2 millions records (lines). Also some times I need to find a specific line from that.
    I have to make a small web application to generate reports on the Text files after parsing those into a database (Oracle or MySQL). I have already a small similar application which based on PHP / MySQL. But still time consumption issue is there while parsing the text file into Database.
    How will it be improve if I go for Tomcat / Oracle / Java Web Component Development?
    Please advice me.

    Try changing your approach - don't read it into an array, process it one line at a time. Obviously any approach where you have the whole file in memory is going to exceed memory at some size of the file.

  • "This file was created by Oracle Reports. View this document in Page Layout mode" , how to avoid this text

    we print some RTF Files , we dont want to  print to paper  this text "This file was created by Oracle Reports. View this document in Page Layout mode"
    How to able do it.
    Tanks for reply.

    we print some RTF Files , we dont want to  print to paper  this text "This file was created by Oracle Reports. View this document in Page Layout mode"
    How to able do it.
    Tanks for reply.

  • Creating new analysis gives "Error loading XML Document from ..."

    Trying to create analysis and getting "Error loading XML Document from saw.dll/answers/answersproperties.xml?fmapId=S1clug.
    The response given was:" after choosing subject area. Analysis editor is opened but Subject Areas is empty and can't do anything.
    The problem is on Mozilla 12 (16.0.2, 17.0.1) and IE 8. Chrome works fine.
    My system is Win 7, BI is on Oracle Linux (and by the way Mozilla from Linux system works fine)
    What could be the reason of this?
    Edited by: 898973 on 4/12/2012 15:11

    Reinstalling Mozilla with "Remove personal data" option checked resolved the problem.

  • Reader can't read/open large files created in ArcGIS ??

    Hi there
    We have a problem with files (GEO PDF's) created primarily from ArcGIS (ESRI).
    Reader version XI or DC can't open/read them (blank screen, but all functions working). It can be files around 60 MB or 1.5 GB and above 300 DPI.
    The weird thing is that if we use FOXIT ALL of them will open/show so it can't be the file that is corrupt, but something in Reader.....either a setting, limitation or ??
    Anyone ??????

    We would like to take a look at the large files to investigate the cause of the problem.
    Please note that the Adobe forums do not accept email attachments.
    Would you share the links to the files?
    How to share a document
    If you are not comfortable sharing the links in this public user forum, please send me a private forum message with the links.
    Thank you.

  • Scenario to read from txt-file and create a sales order

    i have started creating a scenario to read from an txt-file and to create a sales order.
    When i activate my scenario, i get the following message :
        no scenario step (vBIU) associated for this step for the incoming system (SysId)
    When i look into the detailed xml-file i see that all the records are read from the file, but there is no next step to be treated.
    Has somebody any idea how this come ?
    -<Msg MessageLog="true" msglogexcl="false" logmsg="0009" recording="true" BeginTimeStamp="20111202095144" MessageId="11120209514499820828C0A801674F24" xmlns="">-<Header><msglog b1ifactive="true" always="false" step="Default message log"/>-<Resumption><starter ipo="/vP.0010000138.in_FEAN/"/></Resumption><IPO tid="11120205535899820808C0A801678C54" Id="INB_FI_EXST_ASYN_NAM"/><Sender Id="0010000138"/><Inbound file="ORDERS_TEST" ext="csv" path="C:\TEMP\In" pltype="txt" wrap="" deli=";"/></Header>-<Body><Payload Type="File exist" Role="T"/>-<Payload Role="S">-<io xmlns="" pltype="txt">
    This is my final atom :
    <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:b1e="" xmlns:b1ie="" xmlns:bfa="" xmlns:jdbc="" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:sim="" xmlns:utils2="" xmlns:vpf="" xmlns:xci="" xmlns:xsl="" version="1.0" bfa:force="" vpf:force="" jdbc:force="" rfc:force="" b1ie:force="" b1e:force="" xci:force="" sim:force="" utils2:force=""><xsl:output method="xml" encoding="UTF-8" indent="yes"></xsl:output><xsl:param name="atom"></xsl:param><xsl:param name="sessionid"></xsl:param><xsl:variable name="msg" select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role=&apos;S&apos;]"></xsl:variable><xsl:variable name="vpSender" select="/vpf:Msg/vpf:Header/vpf:Sender/@Id"></xsl:variable><xsl:variable name="vpObject" select="/vpf:Msg/vpf:Header/vpf:Sender/@ObjId"></xsl:variable><xsl:variable name="vpReceiver" select="/vpf:Msg/vpf:Header/vpf:ReceiverList/vpf:Receiver[./@handover=&apos;P&apos;]/@Id"></xsl:variable><xsl:template match="/">
    <Msg xmlns="">
    <xsl:copy-of select="/vpf:Msg/@*"></xsl:copy-of>
    <xsl:copy-of select="/vpf:Msg/vpf:Header"></xsl:copy-of>
    <xsl:copy-of select="/vpf:Msg/vpf:Body/*"></xsl:copy-of>
    <Payload Role="R" id="{$atom}">
    <xsl:call-template name="transform"></xsl:call-template>
    </xsl:template><xsl:template name="transform">
    <FinalAtomResult xmlns="">
              <xsl:copy-of select="$msg/io/row[0]/col[2]/text()"></xsl:copy-of>
              <xsl:copy-of select="$msg/io/row[0]/col[5]/text()"></xsl:copy-of>
              <xsl:copy-of select="$msg/io/row[0]/col[1]/text()"></xsl:copy-of>
         <xsl:for-each select="$msg/io/row">
              <xsl:copy-of select="$msg/io/row[*]/col[2]/text()"></xsl:copy-of>
              <xsl:copy-of select="$msg/io/row[*]/col[3]/text()"></xsl:copy-of>

    you were right, you may not specify the extension of a file.
    Another thing i detected is that the loop of my data start with the index 1 instead of 0 !!!
    In this scenario, i have to read all the lines of the file and each time i should do a SQL-query,
    so that i can use the result to build my sales document.
    Do you know if it this is possible or have you any idea how to do this ?

  • Exception while Read very large file 300 MB

    I want to read a file which has size of more than 300 MB.
    While i m executing my code, i m getting
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    Below is my code
    1. FileChannel fc = new FileInputStream(fFile).getChannel();
    2.CharBuffer chrBuff = Charset.forName("8859_1").newDecoder().decode(, 0, fc.size()));
    3.fc.close();Im getting the exception in the line 2.
    Even though i increased the Heap space up to 900 Mb, i m getting this error.
    I executed in command prompt like below,
    java -Xms128m -Xmx1024m readLargeFile
    Kindly give a solution for this. is there any other best way to read large text file ??
    I m waiting for your reply..
    Thanks in advance

    Thanks for your reply.
    My task is to open a large file in READ&WRITE mode and i need to search some portion of text in that file by searching starting and end point.
    Then i need to write that searched area of text to a new file and delete that portion from the original file.
    The above process i will do more times.
    So I thought that for these process, it will be easy by loading the file into memory by CharBuffer and can search easily by MATCHER class.
    Above is my task, then now suggest me some efficient ways.
    Note that my file size will be more and using JAVA only i've to do these things.
    Thanks in Advance...

  • What file type should i use for reading a large file of data?

    I want to store data in a file and access them later. The data file could reach 500 to 1000 MBytes, as a binary file.
    I may have memory problems.
    I do not need the whole data in memory, only a few data each time, for my calculations.
    If i use a binary file, i can not read only a few data. I have to load the whole file and then read the data i need.
    Is this correct?
    If i use another type of file, can i read only a few bytes without loading the whole file?
    Maybe a TDMS file?
    Go to Solution.

    I would probably use a TDMS file for this since it could also be read into excel if it were small enough - just more flexiblility. But you can also do it using binary types. You don't have to read the entire file when using binary files. See below.

  • I need help on reading a large file, thanks.

    I try to read a txt file into an array, just like what I ususally do. But this time the file is too big (300k rows, 100 columns seperated by single space), I got the message "java.lang.OutOfMemoryError".
    I need to do some calculation for every possible row pair. Can someone help me out of this? Thanks a lot.

    Try changing your approach - don't read it into an array, process it one line at a time. Obviously any approach where you have the whole file in memory is going to exceed memory at some size of the file.

  • Reading A Large File At Launch

    Hi all,
    I've got my app working on the ad hoc iPhones of my testers.
    At present, it loads a 6MB data file (a Property List) using the NSDictionary initWithContentsOfFile method. Of course, this is nearly instantaneous on the simulator, but my beta-testers report that the launch time of my app is 10 to 15 seconds because of this.
    If I could go ahead and present my User Interface to the user while this file was being read by another thread or NSOperation, with the only restriction being that a certain method in my code could not be called until the file was completely read in, then this would improve the perceived responsiveness of my app.
    I don't want to "read as needed", as I want the app to have the whole file in memory once it is ready to use.
    Can someone suggest the absolute easiest way to let the UI go ahead and appear while an XML plist is being read into an NSDictionary in a parallel operation/task/thread?
    Right now the -initWithContentsOfFile is in the -applicationDidFinishLaunching delegate method and I would somehow like to spin that reading of the file off and let the code continue on to load the interface and allow the user to start typing in a text box.
    The only "coordination" I need to do is make sure the file has finished being read before executing a method that looks up a key in the NSDictionary.
    What's your opinion on the easiest way to do this? NSOperation?
    I would truly appreciate any advice on this. Thanks.

    I'm not sure about Cryptix but the JDK includes APIs for encrypting/decyrpting streams.

  • How read a pdf file and change TableCell height after reading it using itext api

    I have created a pdf form file using itext ( see class CreatingFormClass ) with itext PdfPTable and PdfPCell. It is done successfully .
    Now I  read this pdf file and filling this pdf file(see class FillingFormClass  ) and at this point i want to change  PdfPCell height () according to Items.
    It is possible or Not???
    My code is given below.
    Thanx in advance
    public class FillPdfFormMainClass {
    public static  String RESULT1 = "E:/BlankForm.pdf";
        public static  String RESULT2 = "E:/FilledForm.pdf";
        public static void main(String[] args) throws DocumentException, IOException {
            String empName="Rakesh Kumar Verma";
                    // This part is Dynamic. It can be 1 item Or can be 25 items
            String listOfItem="Item 1 \n Item 2 \n Item 3\n Item 4 \n Item 5 \n Item 6 \n Item 7 \n Item 8 \n Item 9";
            CreatingFormClass example = new CreatingFormClass(0);
            FillingFormClass class1 = new FillingFormClass();
            class1.manipulatePdf(RESULT1, RESULT2,empName,listOfItem);
    public class CreatingFormClass implements PdfPCellEvent {
        protected int tf;
        public CreatingFormClass(int tf) {
   = tf;
        public void createPdf(String filename) throws DocumentException, IOException {
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(filename));
            PdfPCell cell;
            PdfPTable table = new PdfPTable(2);
            table.setWidths(new int[]{1, 2});
            cell = new PdfPCell();
            cell.setCellEvent(new CreatingFormClass(1));
            table.addCell("Item List:");
            cell = new PdfPCell();
            cell.setCellEvent(new CreatingFormClass(2));
        public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
            PdfWriter writer = canvases[0].getPdfWriter();
            TextField text = new TextField(writer, rectangle, String.format("text_%s", tf));
            text.setBackgroundColor(new GrayColor(0.95f));
            switch (tf) {
                case 1:
                    text.setText("Enter your name here...");
                case 2:
                    text.setText("Enter Your Address");
            try {
                PdfFormField field = text.getTextField();
            } catch (IOException ioe) {
                throw new ExceptionConverter(ioe);
            } catch (DocumentException de) {
                throw new ExceptionConverter(de);
    public class FillingFormClass {
        public void manipulatePdf(String src, String dest,String empName,String listOfItem) throws IOException, DocumentException {
            PdfReader reader = new PdfReader(src);
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(String.format(dest, empName)));
            AcroFields form = stamper.getAcroFields();
            form.setField("text_1", empName);
            form.setField("text_2", listOfItem);

    I am facing the same problem. Please help me out. I just want to read a PDF file as bytes from one location and write it as another pdf file in some other location with a diolog box prompting to open or save in the location where we want.
    I executed the following code:
    File report =new File(location);
    BufferedInputStream in=new BufferedInputStream(new FileInputStream(report));
    response.setHeader("Content-Disposition", "attachment; filename=" + report.getName());
    OutputStream outs = response.getOutputStream();
    int readlen;
    byte buffer[] = new byte[ 256 ];
    while( (readlen = buffer )) != -1 )
    outs.write( buffer, 0, readlen );
    } catch (FileNotFoundException fileNotFoundException) {
    PrintWriter out= response.getWriter();
    out.print("<center><Font color = 'RED'><b>"+PxDSLUtils.getApplicationProperty("label.error.CTM_E017")+"</b></Font></center>");
    Though it prompts with open, save dialog box when i try to open directly or when i save it some where locally and then open it i am getting the following message " File is repaired ot damaged.Operation failed." Any idea about what can be done??? Its very urgent.Please suggest.
    I am not convetin to string just reading and writng as bytes itself.
    Thanks in advance,

  • Read a txt file & pass it to AppleScript

    I was originally going to try to do this purely with AppleScript, but someone (who knows a lot more than me) told me it would be better to do it with a shell script.
    What I want to do is read the contents of a txt file, which would contain a single URL. It would then pass the contents of that text file (the URL) on to be run by AppleScript, via osascript. Here's the AppleScript that should be run via osascript:
    tell application "Safari"
      add reading list item fileContents
    end tell
    So basically it would grab the URL from the text file and add it to Safari's Reading List. Any help would be greatly apreciated.

    Here's the thing...
    It's almost impossible to get a shell script to interact with Safari - not quite, but bizarrely difficult.
    AppleScript, on the other hand, is designed with the explicit goal of facilitating inter-process communication - one process telling another process to do something.
    To do it all via the shell would likely either mean directly manipulating Safari's preference files to include the data you want, or invoking AppleScript (via osascript) to tell Safari what you want it to do.
    The former is a nightmare proposition, which leaves the latter, and if you're going to resort to using AppleScript (even via osascript) then why not do the whole thing in AppleScript and be happy.
    At the end of the day it's about using the right tool for the job. AppleScript was designed for this kind of thing. It's hard to see a better way of doing it.
    I suspect your 'someone' doesn't really know as much as you think (or they think )

Maybe you are looking for

  • PO Reminder Report

    Hi Guru's Is there any std report for PO Reminder please reply Tanks in advance Regards Sameer

  • Console Launcher Error **X-Fi ExtremeMusic

    i am wondering if anyone gets this error or if any one has fixed it.........Ok heres the deal?I got Vista and installed the CD that came with my sound card. I could hear sound after the installation and when ever I would go to my PC components it sho

  • Best route to an an engineer for droputs ?

    Hi I've been getting droputs on my Infinity service - brief periods of outage but then service comes back up ok. What's the best route to getting an engineer out to this ? Many thanks

  • Alarm Clock Problem

    My alarm clock used to work correctly, but within the last two weeks, the only way to get it to turn off is to snooze it, turn off the phone, turn the phone back on, and then turn off the alarm (in the edit options of the alarm settings). The slide t

  • Iphoto 9.2 crashing with Lion 10.7

    Iphoto 9.2 crashes each time I even try and open.  Has only happened since new Lion software added to computer.  Help.