File Read and Byte Conversion Efficiency

Im working on a program that needs to store WAV data.
2 unsigned bytes Little Endian -> signed Short
this is my code:
fis = new BufferedInputStream(new FileInputStream(file), 1764000);
for(int x = 0; x < wav.samples; x++){
fis.read(byte2);
wav.left[i] = (short)b2LEtoInt();
public int b2LEtoInt(){
i += (int)(byte2[1] & 0xff) << 8;
i += (int)(byte2[0] & 0xff);
if(i > 32767){ i -= 65536; }
return i;
}I set the buffer size to 1,764,000 bytes because that is fairly
large and it is 10 seconds of 44100 16bit stereo WAV data.
Reading 79,161,264 takes 8282 ms
Waiting 8 seconds for almost 8 mins of WAV data isnt horrible
but its markedly worse than WaveLAB or CoolEditPro etc that can
load the same data and graph it pretty much as quickly as i can
drag the file onto the screen.
Is this a Java vs Native code speed problem or a design problem?
Does anyone have any tips to speed up this loading process?
I dont know if thats the best 2 byte little endian to short conversion.
I dont know if im using the right reader / buffersize.
I dont know how programs like WaveLAB work with wavs.
Do they load them into memory completely? Are the graphs
images that are then zoomed into or are they redrawn every
time you move them?
Anyone have any expert advice?

is this right...
the buffered reader grabs 1,765,000 bytes from the
file automatically,
read(byte[]...) then reads [x] many bytes from the
reader?Yes but if your byte array has only 2 elements this read method will be called (1,765,000 /2) times and that was the problem. You can reduce by increasing the size of the array.
What the buffered reader does is it minimze the IO blocks which will occure when you actualy read file from the disk buy redusing the niumber of Disk IOs.
and also read method does not gurrantee that the exact number of bytes that you specify is read from the stream by read method
(Read the java documentation of InputStream.read(byte[],int,int))
it says that the maximum number of bytes that will be read is what you specified but the actual number read may be less than that and that depending on the implementation.
read method return an integer value which is the actuall number of bytes I think you should get it in to a variable and use when processing

Similar Messages

  • File read and write operations

    how do use file read and write operations?
    can anyone give simple program?

    http://www.tutorialspoint.com/cplusplus/cpp_files_streams.htm
    http://www.cplusplus.com/doc/tutorial/files/
    check this
    and with mfc
    http://www.functionx.com/visualc/fileprocessing/serialization.htm
    https://msdn.microsoft.com/en-us/library/6337eske.aspx
    http://www.informit.com/library/content.aspx?b=Visual_C_PlusPlus&seqNum=90

  • IPhone4 how through the USB mobile phone file reading and writing?

    iPhone4 how through the USB mobile phone file reading and writing?

    No idea what you are asking.
    Please explain

  • File reader and comparing words

    hi, im currently trying to create a project and i need a little help to get it started!
    What i need to do is create an application which can read a text file. I also need to have a list of words already in the application, and if a word in the list is also in the text file, id like this to be printed in the terminal.
    can anybody help me out with how to start this? ive been looking for relevant posts, and there seems to be alot of things on file reading and comparing words, but they r pretty difficult to follow and not really the same as what im looking for.
    thanks for your help!
    Torre

    You can place a for loop within a for loop to to compare every word in the temp array with every word in the other array.
    try {
    String[] array = new String[] {"wow", "cool"};
    BufferedReader in = new BufferedReader(new FileReader("text.txt"));
    String str;
    while ((str = in.readLine()) != null) {
    String [] temp = null;
    temp = str.split(" ");
    for (int i = 0 ; i < temp.length ; i++) {
      for(int j = 0; j < array.length; j++) {
        if (array[j].equals(temp)) {
    System.out.println(temp);
    } catch (IOException e) {
    } finally {
    //Always close your resources in your finally block... good coding practice.
    in.close();

  • File Reader and BuffredReader

    Hi All,
    Is it that one buffred reader object works with one file reader.???
    I am writing a code for reading the text files with fixed format,
    So i used one file reader and operated two buffered reader object with the same file reader,
    but its not working.
    Please help

    Is it that one buffred reader object works with one
    file reader.???what?
    I am writing a code for reading the text files with
    fixed format,
    So i used one file reader and operated two buffered
    reader object with the same file reader,
    but its not working.what do you mean by "not working"?
    post your code so that people know what you are trying to do.

  • Problem With File Reading And Sorting

    I'm having problems with a particular task. Here is what I have to do:
    Write a program which reads 100 integers from a file. Store these integers
    in an array in the order in whcih they are read. Print them to the screen.
    Sort the integers in place using bubble sort. Print the sorted array to the
    screen. Now implement the sieve of Eratosthenes to place all prime numbers
    in an ArrayList. Print that list to the screen.
    Here is the code I have so far:
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add();
            catch(Exception e)
    This is the file reading part I have done but it doesn't recognise the line numbers.add() . It brings up the error - 'Cannot resolve symbol - method add(). Thats the first problem I have, can anyone see any way to fix it and to achieve the task. Also can someone help with the structure of a bubble sort method and a sieve of Eratosthenes method as I have no clue whatsoever. Any help will be greatly appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Ok, I've done that but I'm having another problem. When I'm printing an output to the screen, it prints 100 lines of integers and not 1 line of 100 integers. Can you see the problem in the code that is doing this?
    import java.util.ArrayList;
    import java.io.*;
    public class Eratosthenes
        private ArrayList numbers;
        private String inputfile1 = "numbers.txt";
        public Eratosthenes()
            numbers = new ArrayList();
        public void readData()
            try {
                BufferedReader reader = new BufferedReader(new FileReader(inputfile1));
                for(int i = 1; i <= 100; i++) {
                    String temp = reader.readLine();
                    numbers.add(temp);
                    System.out.println(numbers);
            catch(Exception e)
    }

  • File Read and Write using File Adapter in Bpel

    In Bpel Process i am using File Adapter ( Schema is Opaque) for read and write the file contents. i am able do successful deployment and read, write function in first time deployment, after that again i tired to run the application, its not going to write the content of file, its only writing the file with out data's or content in that file.
    Please help me...
    Saravanan

    Hi Eric
    In my domain.log file having the following details. In this file im unable to find out what the exact problem. Please look at this and help me.
    <2008-01-22 18:25:42,024> <INFO> <default.collaxa.cube.compiler> validating "C:\product\10.1.3.1\OracleAS_1\bpel\domains\default\tmp\.bpel_BPELProcess2_1.1_298e83988d77b6640c33dfeec11ed31b.tmp\BPELProcess2.bpel" ...
    <2008-01-22 18:25:49,850> <INFO> <default.collaxa.cube.engine.deployment> <CubeProcessFactory::generateProcessClass>
    Process "BPELProcess2" (revision "1.1") successfully compiled.
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Loading JCAActivationAgent for {portType=Read_ptt}
    <2008-01-22 18:25:49,914> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Locating Adapter Framework instance: OraBPEL
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::load - Done loading JCAActivationAgent for processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:25:49,930> <INFO> <default.collaxa.cube.engine.deployment> Process "BPELProcess2" (revision "1.1") successfully loaded.
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::uninit Shutting down the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.0/', activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - performing endpointDeactivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Endpoint De-activation called in adapter for endpoint : D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::init - Initializing the JCA activation agent, processId='bpel://localhost/default/BPELProcess2~1.1/
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> JCAActivationAgent::initiateInboundJcaEndpoint - Creating and initializing inbound JCA endpoint for:
    process='bpel://localhost/default/BPELProcess2~1.1/'
    domain='default'
    WSDL location='rd.wsdl'
    portType='Read_ptt'
    operation='Read'
    activation properties={portType=Read_ptt}
    <2008-01-22 18:26:02,698> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <File Adapter::Inbound> Endpoint Activation called in File Adapter for endpoint: D:\MAXIMUS_Project_Softwares\jdevstudiobase10132\jdev\mywork\MyLabs\BPELProcess2\in
    <2008-01-22 18:26:02,730> <INFO> <default.collaxa.cube.activation> <AdapterFramework::Inbound> Adapter Framework instance: OraBPEL - successfully completed endpointActivation for portType=Read_ptt, operation=Read
    <2008-01-22 18:26:02,890> <WARN> <default.collaxa.cube.activation> <File Adapter::Inbound> PollWork::run exiting, Worker thread will die
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Managed Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> Connection Created
    <2008-01-22 18:26:04,171> <INFO> <default.collaxa.cube.ws> <File Adapter::Outbound> FileInteraction Created

  • File Read and Extract

    Hi,
    I have a script which runs and generates log files. Rather than manually read through these log files, I'd like to code a program which will take the file, read through it and extract the data I wish to extract.
    For example, it may read:
    bla bla bla
    bla bla bla
    23/03/05 - 151105 Files
    bla bla bla
    23/03/05 - Elapsed Time: 3m 50s
    bla bla bla
    24/03/05 - 51250981502 files
    bla bla
    24/03/05 - Elapsed Time: 59m 12s
    bla bla
    etc etc.
    So I want to ignore the "bla bla bla", pick out my keywords, such as file, time and print out the number next to it, preferably to a nice little html file or something :)
    I am able to read files and I think I can pick out keywords using string tokenizers, although this is more advanced than tokenizers I've used before. I used a buffer to split the file and read it line by line.
    I'm pretty stumped, although this seemed like a straight forward thing to do at the time....
    Any advice to get me going?
    Thanks!

    you could use a reg ex to match on xx/xx/xx and still read line by line.
    or you could use Integer.parseInt and always parse the first two characters of a line, if they parse they are integers, but maybe blah has integers in the first two positions as well.

  • Large File Reading and Processing

    Hi:
    Suppose I have a file much larger than my computer's memory e.g. say on a Windows XP system, the memory is 256 MB RAM and the file size is 1 GB on disk. Now if I want to create a File object and read from this file, is this possible to do? If yes, how about the performance?
    I understand that this is more of an Operating System question but nevertheless it affects the Java process.
    Thanks!
    Rahul.

    If you mean, you plan to read the whole file into memory, then:
    Theoretically possible, sure. The process would be much bigger (in terms of memory used) than the amount of memory available, which means that it would start swapping out to disk, and that would reduce performance, although to what extent depends on XP's virtual memory implementation, which I know nothing about.
    But if all you mean is that you want to create a File object and read bits of the file, it won't make any difference. File represents a name or description of a file, not the file itself (you can create File objects for files that don't exist). So it doesn't need to read the whole into memory just to create a File object. You can easily create a File object for the huge file, and then read it in line by line, throwing away old lines as you go, and you won't use up very much memory at all. (Unless, of course, there's some horrible weird artifact of XP that I'm not aware of.)

  • File Read and write in Flex

    hi,
    can any one tell me how to read and write a file using
    actionscript in flex2
    regards,
    Shah Mohamed

    Hi all,
    I have tried read and write file using AIR inturn in Flex 3
    .I can able to compile it with no errors. But while i try to run
    ,it throw an error .and the stack trace of the error is below.. Im
    in showstopper stage. kindly update me with your suggesstions .
    Expecting the reply..
    Thanks in advance
    VerifyError: Error #1014: Class flash.filesystem::FileStream
    could not
    be found.
    at [newclass]
    at
    global$init()[D:\dev\nexxus\metasoft\iGallery;com\metasoft\flex\util;MetasoftUtils.as:8]
    at
    com.metasoft.flex.server::MetasoftServer/getUserInfo()[D:\dev\nexxus\metasoft\iGallery;co m\metasoft\flex\server;MetasoftServer.as:146]
    at
    com.metasoft.flex.server::MetasoftServer/isValidUser()[D:\dev\nexxus\metasoft\iGallery;co m\metasoft\flex\server;MetasoftServer.as:17]
    at
    components::Login/components:Login::login()[D:\dev\nexxus\metasoft\iGallery;components;Lo gin.mxml:14]
    at
    components::Login/__loginButton_click()[D:\dev\nexxus\metasoft\iGallery;components;Login. mxml:102]
    at [mouseEvent]
    regards,
    Shah Mohamed.N

  • Multi files reading and plotting

    i got three text files to be read  and i wana plot them on a single chart ,how can i do that ?? bundling them??
    And is there any way to write three different values on a single file in three columns ??? i m doing it with matlab ? is there any direct way??

    Hello,
    See if the attached file it's enought.
    For writting the 3 different values in 3 columns, use the "write to spreadsheet file.vi"
    Software developer
    www.mcm-electronics.com
    PS: Don't forget to rate a good anwser ; )
    Currently using Labview 2011
    PORTUGAL
    Attachments:
    Read3files.PNG ‏9 KB

  • Sender File Adapter and content conversion

    Hi,
    How can we remove the last line from the file using content conversion?
    The last line should not be read from the input file.
    Like for the first line we can use Document Offset .......similarly do we have any option for the last line?

    >
    neelansha singh wrote:
    > date                       Empno         Empname
    > 19.03.2009            12345            Neel
    > 20.03.2009             34566           Neelkanth
    > EmpDes                 Japan        100
    >
    >
    > The file is like this first row i have removed using document offset.......from 2nd row till nth row the structure is as shown above and the last row has no. of fields 1 less than all other rows and also its root node is different like shown above its rootnode is EmpDes..........How to use File content conversion for this?
    do you want to avoid the last line i.e
    EmpDes                 Japan        100
    in that case the 3 options are
    1. use a adapter module and remove the last line - this is the ideal option
    2. use a OS script - will work but only if you are using the NFS option in the file adapter instead of FTP
    3. read that also using content conversion (treat it as a trailer) and ignore it during the mapping

  • Csv file reading and voltage and current plotting with respect to time samples XY plotting

    Hallo,
             I've been struggling with reading  a comma separated value (csv) file from another instrument (attached). I need to plot this data for analysis. I have 5 column of data with numbers of rows, the first three row is the information of the measurement. I want to read 4th row as string and rest of the row as numbers. I want to plot 2nd column (i1)  with respect to TIMESTAMP; 4th column(u2) wrt TIMESTAMP. And finally plotting i1 (x-axis) vs.. u2 (y-axis) in labview. Could anyone help me.
    In excel its so easy to plot  but I don't know how its done in labview.
    Attachments:
    labview forum test.csv ‏30 KB
    excel plot.jpg ‏88 KB

    Start by opening the file.  Then use the Read Text File function.  You can right-click on it and configure it to read lines.  First make it read 3 lines (this is your extra header data).  Then make it read a single line.  That will give you your channel names.  Then read the rest of the file (disable the read by line and wire a -1 into the number of bytes to read).  Then use the Spreadsheet String to Array function to give you your data.
    I would recommend going through the LabVIEW tutorials if you are really new at this.
    LabVIEW Basics
    LabVIEW 101
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to modify a datafile using file read and file write

    I have a datalog file containing port and DMM setup information.  I want to read this file into an aray, update or modify it, and write it to a file.  I can read the file in, but I am at a loss on how to modify it since it is stored in an indicator.  Any suggestions?

    The simplest thing is to replace your indicator by a control, and to use a local variable to write your data into the control.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How do I protect File (read and copy only)

    I have created a photo file that I want my kids to be able to see and copy( make an imovie or slideshow with)but not write onto. This way as I update the file with more pictures I can copy the new items over easily without creating copies of pictures. The file size is currently 250GB and to re-write the entire folder each time takes 8 hours and it might only take minutes if it only has to write the new pics. My hope is to be able to drag the file onto their drive and then for the system to ask if I want to replace or ignore existing files and just write the new ones. I want to be the only one that has the capability to do this. Help

    If you control their Apple menu -> System Preferences -> Accounts to have parental controls, you can keep that file inside a read only folder that you create for them to access. That's true for nearly every version of Mac OS X.
    If you are able to boot into Mac OS 9 on any of your machines, you will have to setup those accounts to boot via Apple -> Control Panels -> Users and Groups to have read only folders.
    Secure your account with a password that no one can guess. Birthdays, names, foreign language words are not good passwords. A mixture of consonants, numbers, and symbols are best, and at a minimum 8 characters.

Maybe you are looking for

  • URGENT:PR event not triggering

    Hi Experts,               I am creating a PR through me51n.It should create an event of BUS2009(Releasestepcreated).But not event is triggering.Is it related to some setting in SPRO.Please help me

  • Non-English fonts problems.

    Hello guys, I have a problem with non-English (well Cyrillic) font. I faced this problem 3 days ago when was working in iDVD trying to type text there. The problem is if I type in Russian with chosen font it does no appear as its english counterpart.

  • Why does my photo turn white?

    I added some picutres to my library and then a subsequent album.  When I went to move the picutres around the album displayed black photos or a washed out version of the same picutre.  I did a full library rebuild several times and only the thumbnail

  • Signature id for tcp port 6070

    guys, We've problem with signature IPS in our idsm2, my customer is Banking company,they want to develop application banking based on ip, the application need to open and allowing port tcp 6070 and 7007 is there any signature ID that's inspect the tr

  • HOW DO I BACK UP MY MUSIC

    how do i back up my music so when i send it in to get repaired i can easily transfer all my music back into my iPod and can i put all the songs form my iPod into my computer? thx for helping