Easily read strings while tracking the number of bytes read?

Hi all,
I'm after a way to easily parse and read strings from a file, while also being able to check (at any point) how many bytes have currently been read from that file.
I currently use the following for the string processing:
BufferedReader in = new BufferedReader(new FileReader(filename));
String str = null;
while ((str = in.readLine()) != null)
  // process the string
}That's all fine, but the files I'm reading can be very large (multi GB) so obviously it can take a while to read them. During this time I pop up a progress bar, and attempt to track the progress of the read. The files I'm working with just now come with a header on the first line that states how many "somethings" (that I happen to be looking for) will appear in the file. I can use that number to set the maximum value for the progress bar, and update its current value as I find them.
However... I'm also about to start working with files that don't contain this information. I've thought of two ways of knowing how much work has to be done in advance of the read so the maximum value for the progress bar can be set:
1) Quickly count the number of lines in the file without doing any processing. This works, but can still take some time for large files, even with more efficient reading algorithms.
2) Use File.length() to set the maximum to be the number of bytes that will read.
I'd like to use 2), but can't work out a way to use simple String based file parsing (as in the code above), but also be able to know how many bytes have been read so far. Using this code means I don't have to worry about end of line terminators, charset encoding, etc - the Reader does it for me.
Any suggestions?
Thanks

import javax.swing.*;
Component parent; // might be null, or your JFrame
String message; // message to display in the progress bar
BufferedReader br = new BufferedReader(new InputStreamReader(new ProgressMonitorInputStream(parent, message, new FileInputStream(file)), charset));

Similar Messages

  • TS2755 how do i track the number of messages sent? i am on a limited sms plan so i want to know how many messages was i able to send in a month. is there an (free) app for it??

    how do i track the number of messages sent? i am on a limited sms plan so i want to know how many messages was i able to send in a month. is there an (free) app for it??

    Doubtful unless your carrier has an app that includes the option.
    My carrier has an app that I can check current usage and past usage with a previous bill and pay the bill.

  • Do we have any option to track the number of downloaded reports from the OBIEE dashboard or Analysis by the user using usage tracking.

    Do we have any option to track the number of downloaded reports from the OBIEE dashboard or Analysis by the user using usage tracking.

    I'll ask the question of our onsite Microsoft consulting guys, but it's my understanding that as enterprise admins, we have no controls over it. This is an outcome of putting the end-users in charge of their own destiny.
    We can revoke a user's entitlement to Office365ProPlus in the portal and via scripts, but AFAIK only the user controls the allocation of their entitlement.
    Revoking an assignment/allocation, when logged in as the user, doesn't require access to the assigned/allocated computer, but if the information about the assigned/allocated computers in the portal is vague or ambiguous, it's easy to revoke the "wrong" one.
    There's not much here in this forum about the hosted/cloudy aspects, since this forum is mainly about the client-side bits (the client applications, setup and configuration of those) - so in here, I usually refer people off to the O365 community for the
    portal and hosted stuff.
    (we have MS onsite at the moment for a big planning piece, around O365 and also Win8.1 and VDI. I'm not usually this lucky to have those guys on tap ;)
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • Output says "The number of bytes in the file are 0" but the file has bytes

    Dear Java People,
    Why would an output say a file has 0 bytes when upon doing a search for the file in Windows Explorer it say the file has 1 -4 kbytes ?
    for example part of my output was :
    "the number of bytes in TryFile3.java are 0"
    caused by the following lines of code:
    System.out.println("\n" + contents[i] + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());
    thank you in advance
    below are the two program classes
    Norman
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class TryFile3
       public static void main(String[] args)
           //create an object that is a directory
             File myDir =
            new File("C:\\Documents and Settings\\Gateway User\\jbproject\\stan_ch9p369");
              File myFile = new File(myDir, "TryFile3.java");
            System.out.println("\n" + myDir + (myDir.isDirectory() ? " is" : " is not")
            + " a directory.");
             System.out.println( myDir.getAbsolutePath() +
             (myDir.isDirectory() ? " is" : " is not") + " a directory.");
              System.out.println("The parent of " + myDir.getName() + " is " +
              myDir.getParent());
               //Define a filter for java source files Beginning with the letter 'F'
               FilenameFilter select = new FileListFilter("F", "java");
               //get the contents of the directory
               File[] contents = myDir.listFiles(select);
                //list the contents of the directory
             if(contents != null)
                 System.out.println("\nThe " + contents.length  +
                 " matching item(s) in the directory " + myDir.getName() + " are:\n " );
                 for(int i = 0; i < contents.length; i++)
                   System.out.println("\n" +  contents[i] + " is a " +
                   (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents[i].lastModified())
    + "\nthe number of bytes in TryFile3.java are " + myFile.length());
    else {
    System.out.println(myDir.getName() + " is not a directory");
    System.exit(0);
    import java.io.File;
    import java.io.FilenameFilter;
    import java.util.Date;
    public class FileListFilter implements FilenameFilter
    private String name; // file name filter
    private String extension; // File extension filter
    public FileListFilter(String name, String extension)
    this.name = name;
    this.extension = extension;
    // static boolean firstTime = true;
    public boolean accept(File diretory, String filename)
    //the following line of code can be inserted in order to find out who called the method
    // if(firstTime)
    // new Throwable("starting the accept() method").printStackTrace();
    boolean fileOK = true;
    //if there is a name filter specified, check the file name
    if(name != null)
    fileOK &= filename.startsWith(name);
    //if there is an extension filter, check the file extension
    if(extension != null)
    fileOK &= filename.endsWith('.' + extension);
    return fileOK;

    System.out.println("\n" + contents + " is a " +
    (contents.isDirectory() ? "directory" : "file\n") +
    " last modified on " + new Date(contents.lastModified())
    + "\nthe number of bytes in TryFile.java are " + myFile.length());I haven't read any of your italicized code, but perhaps there is a good reason why you have "myFile.length()" and not "contents.length()" in this line of code?

  • How to get the number of bytes stored in a field?

    Hi Guys,
    How can i get the number of bytes stored in a field.
    I tried using DESCRIBE FIELD, But here i am getting the length from the definition.
    i.e 8 bytes for string and for character value is from definition.
    Prompt replies will be Awarded with full points:-)
    Thanks,
    vinod.

    u see this : http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f2e5446011d189700000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f2e5446011d189700000e8322d00/frameset.htm
    Madhavi

  • How to get the number of bytes at TCP port

    Hi all,
    How to get the number of bytes to read at the TCp port...as someone had suggested in some forum we do read the number of bytes first and then pass this...
    but we get a problem when we have FF data in this...because then it sends 2 FF data...and cause of this we skip the last data...is there any solution for the same?

    Hi
    In LabVIEW you don't have the same property as in serail port.
    You havn't "Byte at TCPIP port".
    if you developp a protocol, one soltion, is to send the size to read.
    Ingénieur d'Application / Développeur LabVIEW Certifié (CLD)
    Application Engineer / LabVIEW Certified Developer (CLD)

  • How to reduce the number of bytes for a picture

    I want to reduce the number of bytes used for a picture to be sent to a site like Ebay or craigslist. I son't see any options in Iphoto for this purpose.

    You can do it in Preview.
    Open the image in Preview. Under Tools, click Adjust Size.
    Scale it down to the smallest acceptable size (the website should give a suggested resolution).
    Then go to File -> Export, save it as a Jpeg.
    Smaller size image means smaller file size.

  • How do you calculate the number of bytes in a hexidecimal array?

    Hi can anybody help me calculate the number of bytes in a hexidecimal array ie:
    04h + 12h + 4Eh + 20h = 84h
    Thanks

    Hi,
    I'm not sure if you want to count the bytes or sum the array. But here's an example of both:
    Hope this helps,
    Paulo
    Attachments:
    ByteCount.vi ‏18 KB

  • Trouble with output string size of the 'number to hexadecima​l string' VI

    Hi everyone.
    I am new to Labview, so I apologise if this question is too simple. I am trying to convert a float to a hex string so I can pass it to a VISA Write VI. I first cast it, so it becomes a 32-bit int and then on to the 'number to hex string' VI. Now, since after the casting the number is a 32-bit int, I would assume that the output hex string would also be 32-bit long (so 4 bytes, which is what I need). However, I use the 'string length' Vi and it says the hex string is 8-byte long. Could someone please tell me why this is the case?
    Thank you very much in advance,
    Gabriel

    Are you sure it is 8 bytes? Don't confuse a nibble and a byte.
    Try the "flatten to string" function. 
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

  • TCP/IP Read - How do I find the number of bytes available

    It appears that this is not directly possible. I am trying to get around
    this by doing a tcp/ip buffered read with a very short timeout (0 or 1ms).
    In theory it seems like I should be able to keep making the read call until
    the exact number of bytes (4 in this case) pops out. It mostly works but
    every so often hangs for some period of time and then resumes getting the 4
    byte packets. Anybody have any idea what is going on?

    The first thing I'm thinking of is that your delay is too short. Also, try to increase the packet length or use Immediate Mode (even CRLF MODE if you're transmitting text).
    Another idea (if your application really needs that and you have LV / Windows) is to use MS Winsock Control (wait for DataArrival event and read BytesReceived).
    Anyway, tune in your communication (packets and delays) taking in account details about your network or modem.
    Good luck!

  • Tracking the number of downloads or subscribers to my podcast

    Is there any way to check my server log for the number of downloads my podcast has had (it's in the iTunes podcast directory, too)? Is there any way I can track or access that information at all? Additionally, is there any way to find out how many subscribers my podcast has?
    It's all created and published with iWeb to my MobileMe space.

    Hey there,
    Check out the two links provided in this older discussion post. Hope it helps.
    http://discussions.apple.com/message.jspa?messageID=9207309#9207309
    B-rock

  • How to get the number of bytes at ethernt port using tcp/ip?

    I have data with variable sizes.I am getting the data from another sytem using software C.
    How can I get the exact number of bytes coming at the port before using the read command so that the no. of bytes at port has to be given as the input to the tcp read vi?

    Philippe_RSA wrote:
    So may responses saying your question is wrong..... typical of this site, and no decent answer after 5 years !
    The answer I have used is to use a call library function:
    short int ioctlsocket(unsigned long socket, unsigned long fionread, unsigned long *len);    
    where fionread is a windows defined constant =  4004667F
    The socket can be obtained from using the       TCP Get RAW NET OBJECT.vi   which comes with Labview (even as far back as version 7).
    Good luck.
    A protocol requiring such a hack is IMHO very poorly designed. You should always have some way on the wire to determine the data stream size. If the data is fixed size that would be inherent to the protocol, if it's variable sized there should be a fixed size header or a known message termination indication that can be used to determine how to read the rest of the message.
    As a side node, I do consider the existence of VISA Bytes at Serial Port a big error, and that is most likely where this question originally came from. Use of "bytes at port" to decode a protocol will ALWAYS lead to protocol errors sooner or later, and code that is unneccessarily complicated to force the routine to deal with the asynchonous reading of the "bytes at port" into the protocol decoding.
    If a protocol can't be decoded with fixed size reads, fixed size reads with following variable size reads determined from information in the header, or a specific message termination indication, then it is very badly flawed.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • I need to sort an array of strings based on the number in each string.

    Basically, I have a directory of files that all have the same name but each with a different number on the end.
    example: image 1.jpg, image 2.jpg, etc.
    When I use the List Directory function that returns an array of strings containing the file names in the directory, they don't come out in a 1, 2, 3, order like they appear in the directory. It sorts them character by character so that they come out like: 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22 etc.
    Is there a simple way of sorting this array of strings with the file names (as above) so that they are in numerical order?

    It's a while since this thread was started, but I am sure others will have use for this so here goes:
    The in-built array sort function sorts the strings the same way DOS and Windows do. Microsoft has fixed this in the Explorer that comes with XP, however the rest of the OS(s) still sorts the old way.
    The attached "AlphaLogical String Array Sort" VIs will sort strings arrays the same way as the new XP Explorer. There are three different implementations of the sorting, one based on the Insertion sort algorithm, a Quick Sort based on recursive calls (the most elegant way, but unfortunately LabVIEW has too much overhead when doing recursive calls so this is actually a very slow alternative) and finally the fastest; a stack based Quick Sort. There is also a test VI that will show you how the different implementations perform.
    I had not used recursive calls in LV much until I made the attached quick sort and was a bit disappointed by the fact that it is so slow, but it's a good learning example...The ability to do recursive calls this way was introduced in LV7 I believe...There is an example here on the zone that shows how you can calulate a factorial by using recursive calls, however - unlike for the quick sort (normally) - recursive calls are actually not the optimal solution for that calculation.
    Message Edited by Mads on 09-13-2005 02:30 AM
    MTO
    Attachments:
    AlphaLogical Sorting.zip ‏142 KB

  • The vi is identifyng the number of bytes to be read but the VISA Read vi is not able to read the data from the port.

    We are trying to communicate with the AT106 balance of Mettler Toledo.The VI is attached.
    We are sending in "SI" which is a standard command that is recoginsed by the balance. The balance reads it.The indicator after the property node indicates that there are 8 bytes available on the serial port. However, the VISA read VI fails to read the bytes at the serial port and gives the following error:
    Error -1073807253 occurred at VISA Read in visa test.vi
    Possible reason(s):
    VISA: (Hex 0xBFFF006B) A framing error occurred during transfer.
    The Vi is atttached.
    Thanks
    Vivek
    Attachments:
    visa_test.vi ‏50 KB

    Hello,
    You should also definitely check the baud rates specified; a framing error often occurs when different baud rates are specified, as the UARTs will be attempting to transmit and receive at different rates, causing the receiving end to either miss bits in a given frame, or sample bits more than once (depending on whether the receiving rate is lower or higher respectively). You should be able to check the baud rate used by your balance in the user manual, and match it in your VI with the baud rate parameter of the VISA Configure Serial Port VI.
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear

  • How to track the number slides view on LMS

    Hi,
    I would like to know how to get a percentage of slides view on a LMS platform.
    For example, I don't know how to get a percentage of 5 if I see 5 slides of 100 slides.
    I don't know if it's possible with Captivate and if there is an option for that.
    On our LMS, we get 0, 50 or 100% but we would like to get a more precise result.
    I tried on SCORM CLOUD too and only get 0,00%.
    Do you guys have the solution?
    Thanks in advance for your help.
    Vanessa
    PS: I'm not native english so sorry if I made some spelling mistakes (I'm French). I wanted to post here because you find more answers on english forums than french forums.

    There is not a SCORM value for slides viewed. What SCORM field/value are you seeing this percentage in?
    Also, what version of SCORM are you publishing?
    You would need to alter the scormdriver.js file in order to post the results that you want. I am in the process of writing a blog to change CP's bookmarking behavior. With this code it would be fairly simple to add some code to display the info in the comments (SCORM 1.2).

Maybe you are looking for

  • Deleting messages on iPhone won't delete on .Mac

    I have an issue where if I delete an email on my iPhone and then log in to .Mac mail, I still see the message there. Further inspection shows that the message is in the .Mac trash AND in the inbox - almost like the message was copied rather than move

  • Loss of photos in iPhoto

    I will give you the background story. I have been working on an iMovie, which I then finished with iDVD. My superdrive is non functional due to an "accident" by my children. So, I went to a local Apple Reseller. We tried several things, including put

  • Rate table determination

    Hi experts, in order to have one rate table with one Group of product freight Groups and another one for the 2 nd Group without creating new material groupings, I am using rate table Determination. I created a condition at master data -> Charge Manag

  • Can't re-install Tiger onto Tiger iMac?

    I have an Intel iMac running Tiger 10.4.11. I want to do an archive/instal to freshen it up (Mail has lost its will to live or at least to follow rules and accurately select Junk plus other reasons) but when I go to instal from the original disks it

  • EMAILS now coming in duplicate

    all of a sudden, my emails are coming in duplicates. ?