Problems writing a structured binary file...

Hi Folks,
I've been working with one of my students to convert this matlab routine into a VI to no avail:
fwrite(fout,version,'char');
fwrite(fout,nchar_text,'short');
% convert wave_text into array of ascii integers
fwrite(fout,wave_text,'char');
% output a null character to terminate string
%count=fwrite(fout,0,'char');
fwrite(fout,n_bits,'char');
fwrite(fout,n_bytes,'char');
fwrite(fout,data_polarity,'char');
fwrite(fout,user_data,'float');
fwrite(fout,s_rate,'ulong');
fwrite(fout,adrange,'float');
fwrite(fout,n_pts,'long');
fwrite(fout,wave,'short');
fclose(fout);
I've written a VI that can open the files written by this Matlab procedure with no problem (see openfile.VI), however I can't seem to recreate the method for writing this file to binary (writefile.VI).  I think the Matlab approach is very similar to C, and I'm guessing the issue has to do with converting datatypes effectively.  I've been searching the forms and google, but can't seem to come up with the proper solution.  Any pointers would be greatly appreciated!
Best,
Jason Gallant
Attachments:
writefile.vi ‏27 KB
openfile.vi ‏26 KB

crossrulz wrote:
The additional bytes for the array and string lengths is what is throwing you off.  Even if you turn it off at the Write Binary File, because you built a cluster they will be in there.  You do not want to cluster up your data in this case.  You need to string together a bunch of Write Binary Files, one for each of your parts of data.  Similar to what you had to do in Matlab.
Great suggestion!  We tried implementing this, and things are looking better.   I've attatched the new VI that implements this.   There still seems to be a problem, however with the datatypes being written.  As mentioned in the previous post, the data written is:
version   - 'char
nchar_text, 'short'
wave_text, 'char'
n_bits,'char'
n_bytes,'char'
data_polarity,'char'
user_data,'float'
s_rate,'ulong'
adrange,'float'
n_pts,'long'
wave,'short'
Should i be typecasting (or something similar) to string in order to make this readable by my previous routine?
Attachments:
writefile.vi ‏38 KB

Similar Messages

  • Getting problem while editing a binary file

    Hi All,
    I am trying to edit a binary file using Java.The file contain a string that I have to replace with some other string.For exanple let us assume following is the content of the file -
    õgëÓÌ©™ÿÿ ABC õgëÓÌ©™ÿÿ
    Here, I have to replace this ABC(a string) with some other string.Now,if the replace string length is more than 3(the length of exiting string) then, the binary file is generating some blank space at the end.
    My Code::
    //Here I am trying to insert "Hello" in place of "ABC".
    FileInputStream fis = null;
    fis = new FileInputStream(aFile);
    FileOutputStream to = new FileOutputStream(aF);
    byte[] aTes=new byte[1024];
    String str="Hello";
    aTes=str.getBytes();
    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = fis.read(buffer)) != -1) {
    to.write(buffer, 0, 5);
    to.write(aTes);
    to.write(buffer, 5, bytesRead);
    Plesae guide me to solve this problem.
    Regards,
    Soumitra

    Okay. So was that code you posted supposed to be a failed answer to the question, and you need help with fixing it? Because to me it just looks like code which copies a file, with random modifications. It doesn't look for ABC in any way, it uses the magic number "5" for no apparent reason, and the other modifications are buggy too. So clarification of what the code is supposed to be would be helpful.

  • Problems on saving a binary file

    Hi,
    I have a String object that I need to save on disk, in binary format, for a database implementation project. I am using the FileOutputStream class, like this:
    FileOutputStream fos = new FileOutputStream("file.db");
    byte[] arrayBytes = new byte[myStr.length()];
    arrayBytes = myStr.getBytes();
    fos.write(arrayBytes);
    fos.close();
    The problem is that it saves the string in text (ASCII) format. If I open the file in Notepad it displays all the characters of the string, in a readable format, as it were a .txt file.
    I have some friends implementing the project in Delphi, using a class called "FileWriter". Their file is not readable in Notepad. If we try to open it in notepad, only some characters are readable, other are junk characters.
    As my professor doesn't want the database file to be readable by an ASCII editor, what can I do to save my String in binary format, like "FileWriter" class in Delphi?
    (he said I can't serialize the object to disk)
    The strange thing is that the FileOutputStream class documentation says it writes raw bytes of data. If they are raw bytes, how can I read them in notepad?
    It's confusing to me... Is there any solution for what I need?
    Thanks for your time and help.
    Leo Hyppolito.

    Like I said - search around. Something simple is:public class XOR {
        public static void main (String[] args) {
            String s = "Hello";
            s = flip (s);
            System.out.println (s);
            s = flip (s);
            System.out.println (s);
        private static String flip (String s) {
            String flippedString = "";
            for (int i = 0; i < s.length (); i ++) {
                flippedString += flip (s.charAt (i));
            return flippedString;
        private static char flip (char c) {
            return (char) (c ^ 0x5678);
    }Kind regards,
    Levi

  • Problem writing image(Blob) to file

    Hi ,
    I'm trying to write image to file. The Image(26KB) is stored in database as BLOB. I have to change this to CLOB because when I try to write to file its writing all junk data. So I converted BLOB to CLOB then I try to write its giving me error.
    ORA-21560 :argument string is null, invalid, or out of range
    Cause: The argument is expecting a non-null, valid value but the argument value passed in is null, invalid, or out of range. Examples include when the LOB/FILE positional or size argument has a value outside the range 1 through (4GB - 1), or when an invalid open mode is used to open a file, etc.
    Action: Check your program and correct the caller of the routine to not pass a null, invalid or out-of-range argument value.
    The size of IMAGE after coverting to CLOB is 21102 bytes which is between the range.
    Here is how my code looks like:
    DECLARE
    f UTL_FILE.file_type;
    l_blob_len INTEGER;
    buffer VARCHAR2 (32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER (38);
    l_blob BLOB;
    l_clob CLOB := 'x';
    l_dest_offsset INTEGER := 1;
    l_src_offsset INTEGER := 1;
    l_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
    l_warning INTEGER;
    BEGIN
    SELECT blobdata
    INTO l_blob
    FROM lob_table ip
    WHERE ip.id = 2;
    DBMS_LOB.converttoclob (dest_lob => l_clob,
    src_blob => l_blob,
    amount => DBMS_LOB.lobmaxsize,
    dest_offset => l_dest_offsset,
    src_offset => l_src_offsset,
    blob_csid => DBMS_LOB.default_csid,
    lang_context => l_lang_context,
    warning => l_warning);
    amount := buffer_size;
    offset := 1;
    f := UTL_FILE.fopen ('IN_FILE_LOC', 'something.doc', 'w');
    WHILE amount >= buffer_size
    LOOP
    DBMS_OUTPUT.put_line ('buffer_size');
    DBMS_LOB.READ (l_clob,
    amount,
    offset,
    buffer);
    UTL_FILE.PUT (f, buffer);
    UTL_FILE.FFLUSH (f);
    END LOOP;
    UTL_FILE.fclose (f);
    END;
    Please tell me what did I do wrong.

    Try this posts
    http://www.oracle-base.com/articles/9i/ExportBlob9i.php
    http://download.oracle.com/docs/cd/B10500_01/appdev.920/a96591/adl06faq.htm

  • Problems writing from BLOB to File with Thin-drivers

    I'm having problems when I'm trying to put a blob to a file
    using jdbc-thin drivers(8.1.5).
    It works perfectly well with the oci-drivers but not with thin.
    When I execute the same code with the thin-drivers I get:
    Error: java.io.IOException: ORA-21560: argument 2 is null,
    invalid, or out of range
    ORA-06512: at "SYS.DBMS_LOB", line 640
    ORA-06512: at line 1
    Please help me...
    /Stefan Fgersten
    lob_loc = ((OracleResultSet)rset).getBLOB(1);
    in = lob_loc.getBinaryStream();
    FileOutputStream file =
    new FileOutputStream("d:/dir/picture.jpg");
    int c;
    while ((c = in.read()) != -1)
    file.write(c);
    file.close();
    in.close();
    null

    Has anyone managed to find a solution (other than switching drivers) for this? I too am using the 8.1.5 thin driver on an 8.1.5 database and receive the same error. Please help!!
    Nkem
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Stefan Fgersten ([email protected]):
    I'm having problems when I'm trying to put a blob to a file
    using jdbc-thin drivers(8.1.5).
    It works perfectly well with the oci-drivers but not with thin.
    When I execute the same code with the thin-drivers I get:
    Error: java.io.IOException: ORA-21560: argument 2 is null,
    invalid, or out of range
    ORA-06512: at "SYS.DBMS_LOB", line 640
    ORA-06512: at line 1
    Please help me...
    /Stefan Fgersten
    lob_loc = ((OracleResultSet)rset).getBLOB(1);
    in = lob_loc.getBinaryStream();
    FileOutputStream file =
    new FileOutputStream("d:/dir/picture.jpg");
    int c;
    while ((c = in.read()) != -1)
    file.write(c);
    file.close();
    in.close();<HR></BLOCKQUOTE>
    null

  • Binary file problem

    I am writing to a binary file. My poblem is that i want that the next time it write to the file it will write on a new line. What can i do? Thanks a lot.
    This is the piece of code that writes to the file:
                         File aFile  = new File( "players.dat" );
                         // create an output stream to the file
                         FileOutputStream aFileOutStream = new FileOutputStream ( aFile, true );
                         // create a data output stream to the file output stream
                         DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
                         // write data to file
                         aDataOutStream.writeUTF(player);
                         aDataOutStream.writeUTF(String.valueOf(percent) );
                         aDataOutStream.writeUTF(type );
                         aFileOutStream.close();

    kopl wrote:
    I am writing to a binary file. My poblem is that i want that the next time it write to the file it will write on a new line. What can i do? Thanks a lot.I'm confused. I'm no expert in I/O, but When I hear "new line" I think "text file"; "new line" and binary files just don't seem to mix properly in my mind.

  • Error when reading back a binary file

    Hello,
    I am writing out a binary file consisting of U32 arrays, packed strings, and clusters. I get error 116 when reading back. As long as I am synchronized on the correct data position why should LV care what I write to the file? In the example I write a simple 16 element array and a time stamp cluster. When reading back the array I get the error. What is the correct way to do mixed structures? Thanks.
    Attachments:
    file write.PNG ‏44 KB

    David,
    You can solve the problem in various ways. The easiest might be to modify the writer VI by wiring a True constant into the "header (F)" input of your first Write File node. That forces LabVIEW to include a four-byte header that specifies the length of the array you are writing.
    When you wire up the reader code the way you did, the length of the array you wire to the "byte stream type " input is irrelevant; by wiring nothing into the "count" input, you are implicitly telling LabVIEW to look for a header to determine the length of the array you are asking it to read. Because you didn't write any header, LabVIEW is interpreting the first four bytes of the array itself as a length. That length doesn't match the actual amount of data present in the datafile, so LabVIEW generates your error.
    An alternative solution would be to leave the writer unchanged and modify the reader VI: wire an I32 constant into "byte stream type" and wire a 16 into "count". The choice depends on what you prefer and whether or not these binary files need to be compatible with some other program or not.
    Another aside: you can dispense with your case that checks whether the datafile already exists. Just change the function input of the Open/Create/Replace to "create or replace" and wire a False constant into its "advisory dialog" input.
    Hope that's clear,
    John

  • Writing image to wbmp file in java

    I am having problem writing images to wbmp files by java using the javax.imageio.* class. Though wbmp is present in the list given by writer format names.
    String[] writers = ImageIO.getWriterFormatNames();
    System.out.println("Can write to -");
    for ( String s : writers)
                System.out.println(s);
            }but my code to convert an image format is not working for wbmp files
    File in=new File("star.png");
    File out=new File("def.wbmp");
    File out1=new File("def.jpg");
    BufferedImage image;
    try {
         image = ImageIO.read(in);
         ImageIO.write(image,"wbmp",out);
         ImageIO.write(image,"jpg",out1);
    } catch (IOException e) {}the jpeg file is created successfully but the wbmp file remains empty. can you tell me where the problem is. Or is there some alternative method for image conversion.

    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class WirelessPrep {
        private JPanel getContent(BufferedImage image) {
            JPanel panel = new JPanel(new GridLayout(1,0));
            panel.add(wrap(image));
            panel.add(wrap(convert(image)));
            return panel;
        private BufferedImage convert(BufferedImage image) {
            // Convert to BufferedImage.TYPE_BYTE_BINARY
            BufferedImage binary = convert(image, BufferedImage.TYPE_BYTE_BINARY);
            BufferedImage wbmp = null;
            File file = new File("wirelessPrep.wbmp");
            try {
                ImageIO.write(binary, "wbmp", file);
                wbmp = ImageIO.read(file);
            } catch(IOException e) {
                System.out.println("io error: " + e.getMessage());
            return wbmp;
        private BufferedImage convert(BufferedImage src, int type) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dst = new BufferedImage(w, h, type);
            Graphics2D g2 = dst.createGraphics();
            g2.drawImage(src, 0, 0, null);
            g2.dispose();
            return dst;
        private JLabel wrap(BufferedImage image) {
            ImageIcon icon = new ImageIcon(image);
            JLabel label = new JLabel(icon, JLabel.CENTER);
            return label;
        public static void main(String[] args) throws IOException {
            String path = "images/bison.jpg";
            BufferedImage image = ImageIO.read(new File(path));
            JPanel panel = new WirelessPrep().getContent(image);
            JOptionPane.showMessageDialog(null, panel, "", -1);
    }

  • Binary File, ArrayList, Serialization

    So I'm making a program that will be writing to a binary file. When the program first starts it checks if the binary file is in the directory the program is in, if it is not the file is written to the hard drive. This program will be using an ArrayList to manage objects and the objects will be serialized, but what about the ArrayList? Is it serialized, written to the file, or what? If it is written to the file how would I do that?

    Er I was following an online tutorial on it..Not
    really my code just filling in stuff. As you can
    tell, I'm a newbie in Java..Got any ideas on how to
    serialize it?I would really like to know what settingsHash is...
    ArrayList mylist = new ArrayList();
    FileOutputStream fileOut = new FileOutputStream(MyFile);
    ///fileOut = new FileOutputStream(MyFile); commented out the redundancy
    ObjectOutputStream oos = new  ObjectOutputStream(fileOut);
    oos.writeObject(myList);// hopefully serializes your ArrayList to the file
    oos.close();// please to close streams after using

  • Problem in Writing to/Reading from a Binary file placed in a Loop

    Hi
    As you can see in the attahced image, I attempt to write a set of 2*202 data in each iteration of the loop of the loop, yet when I try to read the data (in the second picture) I only get the first (or last, I assume) set of data, up to index 202. I needed to read two set (X, Y) of 402 valuse. So, I am not sure if I am making a  mistake in wrting to the file or reading from it! 
    I really appreciate it if someone could suggest a solution
    Ashakn
     

    You are only reading the first.  In your read, set your number to read to -1.  That will tell the Read Binary File to read all of the data instead just a single set.

  • Problem in reading no. of files and writing into a single file

    Hi,
    Iam with Problem in reading no. of files and writing into a single file....
    Iam reading no. of files stored in local directory.......
    Iam able to read and print the data in files successfully....but while writing..only first file is being written...and the next files are not written in my output file...
    plz tell me my mistake....I hope Iam doing some mistake while writing into file...PLz help.....
    Basically my code structure is like this....
    import java.io.*;
    import java.util.regex.*;
    import java.util.*;
    import java.text.*;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    class Writing {
    public static void main(String args[]) throws Exception {
              FileOutputStream fileOut = new FileOutputStream("ServerResult.xls"); //my output file
              int counter = 1;
              File dir = new File("C:/Perform/ServerLogs");
              String[] children = dir.list();
              if( children == null)
                   System.out.println("The Directory mentioned does not exist");
              else {
                   for (int fileNo = 0; fileNo < children.length; fileNo++ ) {        //Files iteration starts
                        String filename = children[fileNo];
              File logFile = new File(filename);
    FileReader logFileReader = new FileReader(logFile);
    BufferedReader logReader = new BufferedReader(logFileReader);
    StringBuffer sBuf = new StringBuffer(5000);
              HSSFWorkbook wb = new HSSFWorkbook();          
              HSSFSheet sheet = wb.createSheet();
              HSSFRow rowTitle;
              HSSFRow rowReq;
              HSSFRow rowRes;
    String aLine = null;
    boolean skip = false;
    boolean readed = false;
    boolean initReq = false;
              boolean flag = false;
    long requestTime = 0;
    long responseTime = 0;
    long recdTime = 0;
    long sentTime = 0;
              long hasTime = 0;
              long presentTime = 0;
              int hasCalls = 0;
    Pattern startMessage = Pattern.compile("^<MESSAGE.*ID=\".*_"+args[0]+"\".*", Pattern.DOTALL);
    Pattern requestMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"RequestMsg.\".*ID=\".*_"+args[0]+"\".*<ActName>(.*)</ActName>.*", Pattern.DOTALL);
    Pattern requestMessage1 = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"RequestMsg.\".*ID=\".*_"+args[0]+"\".*<Svc id=\"(.*)\">.*", Pattern.DOTALL);
    Pattern responseMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"ResponseMsg\".*ID=\".*_"+args[0]+"\".*", Pattern.DOTALL);
    Pattern initMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"HostConnInit\".*ID=\".*_"+args[0]+"\".*", Pattern.DOTALL);
    Pattern initResMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"ResponseMsg\".*ID=\"null\".*", Pattern.DOTALL);
    Pattern initResIDMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"ResponseMsg\".*ID=\"null\".*<IATA>"+args[0]+"</IATA>.*", Pattern.DOTALL);
              Pattern sentMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"DCMsgSentInfo\".*ID=\".*_"+args[0]+"\".*", Pattern.DOTALL);
              Pattern rcvdMessage = Pattern.compile("^<MESSAGE.*TS=\"(.*)\" CATEGORY=\"DCMsgRcvdInfo\".*ID=\".*_"+args[0]+"\".*", Pattern.DOTALL);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    DecimalFormat dcf = new DecimalFormat("########.##");
    String actName = "";
              if (fileNo ==0)
              rowTitle = sheet.createRow((short)0);
              rowTitle.createCell((short)0).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)0).setCellValue("Req/Res");
              rowTitle.createCell((short)1).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)1).setCellValue("Action");
              rowTitle.createCell((short)2).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)2).setCellValue("Server Time(in ms)");
              rowTitle.createCell((short)3).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)3).setCellValue("Request Vs Response Time in Server(in ms)");
              rowTitle.createCell((short)4).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)4).setCellValue("Time Taken By HAS/HOST(in ms)");
              rowTitle.createCell((short)5).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)5).setCellValue("No. of HAS calls");
              rowTitle.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_STRING);
              rowTitle.createCell((short)6).setCellValue("Data Size");
              //wb.write(fileOut);
    while((aLine=logReader.readLine()) != null) {
    if(aLine.startsWith("<MESSAGE TYPE=\"EVENT\"")) {
    Matcher m = startMessage.matcher(aLine);
    if(m.find()) {
    sBuf.setLength(0);
    sBuf.append(aLine);
    skip = false;
    initReq = false;
    m = initMessage.matcher(aLine);
    if(m.find()) {
    initReq = true;
    } else {
    if(initReq) {
    m = initResMessage.matcher(aLine);
    if(m.find()) {
    sBuf.setLength(0);
    sBuf.append(aLine);
    skip = false;
    } else if(aLine.startsWith("</MESSAGE>")) {
    if(!skip) {
    sBuf.append(aLine);
    readed = true;
    } else if(!skip){
    sBuf.append(aLine);
    if(!skip && readed) {
    String tempStr = sBuf.toString();
    if(tempStr.length() > 0) {
    boolean reqMatched = false;
    Matcher m = null;
    if(initReq) {
    m = initMessage.matcher(tempStr);
    actName = "Intialization";
    } else {
    m = requestMessage.matcher(tempStr);
    String time = "";
    if(m.find()) {
    reqMatched = true;
    for (int i=1; i<=m.groupCount(); i++) {
    String groupStr = m.group(i);
    if(i == 1) {
    time = groupStr;
    } else if(i == 2) {
    actName = groupStr;
    } else if(!initReq){
    m = requestMessage1.matcher(tempStr);
    if(m.find()) {
    reqMatched = true;
    for (int i=1; i<=m.groupCount(); i++) {
    String groupStr = m.group(i);
    if(i == 1) {
    time = groupStr;
    } else if(i == 2) {
    actName = groupStr;
    if(time.length() > 0 ) {
    try{
    requestTime = sdf.parse(time).getTime();
    }catch(Exception ex){}
    System.out.println("Request,"+actName+","+time+",,,,"+dcf.format(((double)time.length()/1024.0))+"K");
                                  //bw.write("Request,"+actName+","+time+",,,,"+dcf.format(((double)time.length()/1024.0))+"K");
                                  String reqDataSize = dcf.format(((double)time.length()/1024.0))+"K" ;
                                  rowReq = sheet.createRow((short)counter);
                                       rowReq.createCell((short)0).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)0).setCellValue("Request");
                                       rowReq.createCell((short)1).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)1).setCellValue(actName);
                                       rowReq.createCell((short)2).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)2).setCellValue(time);
                                       rowReq.createCell((short)3).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)3).setCellValue("");
                                       rowReq.createCell((short)4).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)4).setCellValue("");
                                       rowReq.createCell((short)5).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)5).setCellValue("");
                                       rowReq.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_STRING);
                                       rowReq.createCell((short)6).setCellValue(reqDataSize);
                                       counter = counter +1;
                                       System.out.println("counter is "+counter);
                             Matcher l = sentMessage.matcher(tempStr);
                             Matcher k = rcvdMessage.matcher(tempStr);
                   if(l.find()) {
                                            for (int i=1; i<=l.groupCount(); i++) {
         String groupStr2 = l.group(i);
    try{
    sentTime = sdf.parse(groupStr2).getTime();
    }catch(Exception ex){}
                        if(k.find())
                                                 for(int j=1;j<=k.groupCount(); j++) {
                                                 String groupStr1 = k.group(j);
                                                 try{
    recdTime = sdf.parse(groupStr1).getTime();
    }catch(Exception ex){}
                                                 presentTime = (recdTime - sentTime);
                                                 hasTime = hasTime + presentTime;
                                                 hasCalls = hasCalls +1;
    if(!reqMatched) {
    if(initReq) {
    m=initResIDMessage.matcher(tempStr);
    } else {
    m=responseMessage.matcher(tempStr);
    if(m.find()) {
    for (int i=1; i<=m.groupCount(); i++) {
    String groupStr = m.group(i);
    try{
    responseTime = sdf.parse(groupStr).getTime();
    }catch(Exception ex){}
                                                 String resDataSize = dcf.format(((double)tempStr.length()/1024.0))+"K" ;
                                                 rowRes = sheet.createRow((short)(counter));
                                                 rowRes.createCell((short)0).setCellType(HSSFCell.CELL_TYPE_STRING);
                                                 rowRes.createCell((short)0).setCellValue("Response");
                                                 rowRes.createCell((short)1).setCellType(HSSFCell.CELL_TYPE_STRING);
                                                 rowRes.createCell((short)1).setCellValue(actName);
                                                 rowRes.createCell((short)2).setCellType(HSSFCell.CELL_TYPE_STRING);
                                                 rowRes.createCell((short)2).setCellValue(groupStr);
                                                 rowRes.createCell((short)3).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                                                 rowRes.createCell((short)3).setCellValue((responseTime - requestTime));
                                                 rowRes.createCell((short)4).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                                                 rowRes.createCell((short)4).setCellValue(hasTime);
                                                 rowRes.createCell((short)5).setCellType(HSSFCell.CELL_TYPE_NUMERIC);
                                                 rowRes.createCell((short)5).setCellValue(hasCalls);
                                                 rowRes.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_STRING);
                                                 rowRes.createCell((short)6).setCellValue(resDataSize);
                                                 hasTime = 0;
                                                 hasCalls = 0;
                                                 counter = counter + 1 ;
    sBuf.setLength(0);
    readed = false;
              wb.write(fileOut);
              } // End of for (int fileNo = 0; fileNo < children.length; fileNo++ )
    }     //End of else
              fileOut.close();
    } //End of public static void main
    } // End of Class

    First of all, use [code]-tags to make your code readable, please.
    I didn't do a complete inspection of your code (because it's too much and unreadable as it is) and I don't know POI, but creating a new HSSFWorkbook for each input file sounds fishy to me ... try re-using the workbook and just creating a new sheet in each iteration.

  • Problem when streaming out a binary file

    Hi,
    I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the
    file, read it to a a byte array, and writing it out to my output stream. However, I got corrupted data at my other end and it took me quite a bit of
    debugging hours to find out why.
    I tried writing to a file the same information I was writing to my output stream but, although my file was correct, my output stream still contained
    corrupted data.
    I think I have finally narrowed down my problem to the fact that when I try to write a 0x00 value to my output stream, everything gets ignored from this
    point until I write a 0x0a byte to my output stream. Obviously this produces corrupted data, since I need all the bytes of my binary file.
    If somebody can direct me as to how to write a 0x00 value to a socket output stream, I would really appreciate your input.
    This is a sample of my code (Right now I am writing byte by byte: not very efficient, but was the only way I found where I was getting a problem):
    // out is of type OutputStream
    if (Zipped){
         // In this case we just have to stream the file out
    File myFile = new File(fileName);
         FileInputStream inputFile = new FileInputStream(myFile);
         FileOutputStream fos = new FileOutputStream(new File("/tmp/zip.gz")); //zip.gz results in a good (not corrupted) file.
         ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
         int bytes = (int)myFile.length();
         byte[] buffer = new byte[bytes];
         bytes = inputFile.read(buffer);
         while (bytes != -1) {
              out1.write(buffer,0,bytes);
              bytes = inputFile.read(buffer);
         inputFile.close();
         try {
              int count=0;
              bytes=out1.size();
              while (count<bytes){
                   fos.write(buffer,count,1);
    out.write(buffer,count,1); // when buffer[count] == 0x00, everything after it gets ignored until a 0x0a byte is written.
                   count++;
         } catch (IOException ioe) {
              SysLog.event("IOEXCEPTION: "+ioe);
         } catch (Exception e) {
              SysLog.event("EXCEPTION: "+e);
         fos.flush();
         fos.close();
         out.flush();
    out.close();
         return;
    }

    Actually, I had thought about that and for some time I tried getting rid of some of the header information in the gzipped file, and then I stopped doing that when I realized that part of the gzipped file is a CRC value which I believe is computed taking into account both the data of the file and the header information. If this is the case, then getting rid of part of the header would produce a corrupted file ... but then, I might be wrong in this issue.
    Anyway, to make my application more clear, what I am doing is writing the code for a cgi command which is suppossed to access information from a database, create an xml file, gzip it, and then send it to the client who requested the information.
    Therefore, what I am sending is an xml file (Content-Type: text/xml) in compressed format (Content-Encoding: gzip). Note that if I don't gzip the file and then send it uncompressed to the client, I have no problems. However, for me it is very important to gzip it because the size of the file can get very large and that would just take bandwidth unnecessarily.
    On the other hand, if I try to gunzip the file locally, I have no problem either (the file is not corrupt at the server's end). Therefore, my problem is when I stream it out.
    Any further help would be really appreciated!

  • Writing waveforms from Ch. 0 of niSCOPE to binary file in a multi-record setup?

    Hello,
    I am not very experienced with niSCOPE and writing waveform records, so I need some expert help here.
    Here is my application:
    I am generating a pulse train using a 6602 counter/timer. Each rising edge of this pulse train triggers an niFGEN to generate a single sawtooth waveform output to another device and, at the same time, acquiring data from Ch. 0 of an niSCOPE. I am fetching one record per rising edge of the pulse train for the niSCOPE (multi-record setup).
    The attached VI is where I am at thus far. All triggering and reading/fetching of the waveforms seems to be working just fine when testing with an oscilloscope. I now need to save each waveform record along with the timestamp of its rising edge trigger to a binary file. The bottom of the VI is where my attempt is at saving the waveforms to a binary file, so the attention should be there when looking at it.
    I am running LabVIEW from a computer connected to the NI PXI-Chassis using a cross-over cable.
    Questions:
    1.) Do I need to convert the data coming in on Ch. 0 of the niSCOPE to digital? Does it come in as analog from an oscilloscope? If I need to do this, how can I accomplish this?
    2.) When I try to run an example VI to write a waveform to a binary file by choosing "My Computer" in the bottom left of the VI window, it works it saves the file just fine. When I change this to run on "PXI2", a file is not even created and I get an error on File Dialog (code# 7, I think) each time the file is attempted to be closed. This may be a stupid question, but why can I not save data to a file on my computer if running the VI on "PXI2"?
    3.) Assuming the saving of each waveform to a binary file is working (read: (2) is successfully addressed), how can I also write the timestamp of the starting trigger for the waveform along with the waveform in the binary file? An example VI of how I can accomplish this would be fantastic, but I haven't been able to find one thus far.
    4.) When I was messing around and trying to accomplish this, it seemed that doing this writing may slow down the entire process too much. I need to record data to the extent of the sawtooth waveform generated by the niFGEN AWG for each trigger. Is there any changes I should make to my acquisition process in the niSCOPE section so that I can read each waveform, along with keeping the timestamp for each, and write this information to a binary file?
    I need to get this working quickly, so any help on this is greatly appreciated. Thanks in advance.
    Attachments:
    5124_update.vi ‏157 KB

    Thank you so much for your reply, David. Let me try and explain my
    situation and setup a little better, as well as discuss the points you
    made in your reply. Beware, you may want to refill your coffee as this
    post is long .
    I am using an embedded controller in a PXI-1044 chassis. I now have the
    chassis hooked up to our local network, and I am deploying my project
    to the chassis over the network as I am also connected to the local
    network. I have an oscilloscope next to me that takes as input the
    pulse train for a trigger and the generated sawtooth from the niFGEN
    for each trigger (rising edge of the pulse train from the 6602
    counter). Just to make sure synchronization is taking place, the
    sawtooth is also fed as input to the niSCOPE for acquisition.
    "PXI2" is what shows up when I choose to run a VI on the PXI chassis
    rather than "My Computer"; not sure why the 2 is there either, but that
    is what it says. I may have tracked down the issue I was having with
    writing, but more about that a little later...
    The attached VI is an update, although not much has changed. My
    application design is like this (keep in mind that some values for VI's
    are still constants in the block diagram while others are controls on
    the front panel): I am using the 6602 to generate a 1 KHz pulse train
    and routing this pulse train to PXI_Trigger0/RTSI0. I am also using the
    PXI_Clock (10) as a sample clock for this, and also using this same
    clock as the reference clock for both the 5422 and the 5124 (as per the
    synchronization help file mentioned for synchronizing multiple
    devices). Both the 5422 and the 5124 are triggered by a digital rising
    edge (from the pulse train) on PXI_Trigger0/RTSI0 (as it was routed
    there). For each trigger, the niFGEN generates a sawtooth waveform
    using a stepped trigger mode and outputs it. For each trigger, the
    niSCOPE acquires data. They are both synchronous, which is tough to see
    since one has its trigger source on the front panel and the other has
    its trigger source on the block diagram. All devices use PXI_Clock so
    they are synchronized.
    The expected behavior is to only generate a single sawtooth waveform
    per trigger with a certain number of sample points. I want to acquire
    the same number of samples using the niSCOPE, which is what I meant by
    "the extent of the waveform" in my previous post. So, should I change
    the 8192 to 1000 for the number of samples for the niSCOPE? What would
    you recommend for the sampling rate? I have been using 5 MHz for the
    niFGEN and 5 MHz for the niSCOPE...this is how it should be done,
    correct? If it is different in the VI, please let me know. For some
    reason, I have to adjust all of the values each time I open it since
    the default values are not the ones I want.
    I want to generate and acquire one waveform per trigger (one waveform
    per record). However, I want to be able to record a large number of
    records so I have enabled the circular buffer-like treatment of the
    acquired waveforms. The 100 or 1000 records is actually just a number I
    am giving it for now to make sure it is working before recording many
    more records.
    As for saving the niSCOPE data, I would like to save all data in a
    single file that is NOT ascii (to save space). I have been looking at
    the HWS file format, and would like to use it. I think the attached VI
    includes this at the bottom of the while loop. For each trigger, I
    would like to save the time (as accurate as possible) that the trigger
    occurred for the record/waveform, which appears to be (absoluteInitialX
    - relativeInitialX) as you said in your post (thanks!). I just need to
    store as much information about the waveform and time information for
    it as possible with the waveform in the file. So it looks like I will
    need to use the wfm info for that information, providing portions of it
    as waveform attributes in the HWS VI's?
    What format of data do you recommend I fetch, and will I be fetching a
    "Single waveform" or "Multiple waveforms"? Should I use I32, DBL, WDT,
    or other for the format? A balance between good precision in values and
    time it takes to fetch/record would be best.
    Given all of the above, I am having one troube with saving data to a
    file. As a reminder, I am deploying the project to the chassis over the
    network. When I choose a location and/or file to save the HWS data to,
    I only get choices that are on the PC's hard disk (such as C:\Documents
    and Settings\cgifford\...) NOT the chassis's hard disk. When I choose
    something other than "C:\" I get an error that the file could not be
    opened. However, when I choose "C:\" everything goes fine. The saved
    data is nowhere to be found on my PC though, so I am assuming that it
    is being stored on the internal 60G hard disk in the chassis that must
    be named "C" by default or something!?
    I have been told by phone support that I should be able to make a
    direct connection with the chassis just like another PC, and should be
    able to access the information on its internal hard disk in a drag and
    drop fashion. I however cannot directly connect to the PXI chassis to
    get the data that has been saved on the hard disk. We are running
    Windows XP on the PC. We did some poking around and noticed that the
    chassis is not running Windows file sharing, and only has ftp and http
    running. We tried to access it using ftp, but we didn't have a username
    and password to supply it. So, how can we enable Windows file sharing
    on the chassis? How can I connect to it to do drag and drop to get
    saved waveform data off of it? This is the main problem I am now
    facing. Eventually we would like to store data to an external hard disk
    connected to the chassis, which assumes that I can have access to the
    internal storage to tell it to save files to the external hard disk.
    For now saving it to the internal hard disk is just fine until
    everything is proven to work, but I would like to get the data off of
    the internal hard drive to put on another computer.
    Any answers/suggestions on my above questions are greatly appreciated.
    I also want to thank you for reading this long post . I eagerly await
    a reply. Thanks again in advance.
    Chris
    Attachments:
    5124_update.vi ‏143 KB

  • Write structure to binary file and append

    I have a very simple problem that I cannot seem to figure out, which I guess doesn't make it so simple, for me at least.  I've made a little example .vi which basically breaks down what I want to to.  I have a structure, in this instance 34 bytes of various data types.  I would like to iteratively write this structure to a binary file as the data in the ACTUAL structure in my .vi will be changing through time.  I'm having trouble getting the data to be appended to the binary file rather than overwriting it since the file size is always 34 bytes regardless of how many times I run the .vi or run the for loop.
    I'm not an expert, but it seems if I write a 34 byte structure to a file 10 times, the final product should be a binary file of 340 bytes (assuming I haven't padded or prepended with size).
    One really strange thing is that I keep getting error #1544 when I wire the refnum out wire to the file dialog input on the write function, but it works fine when I wire the file path directly to the write function.
    Can someone please swoop in and save me from this remedial task?
    Thanks for all the help. NI Forum rules!
    Solved!
    Go to Solution.
    Attachments:
    struct_to_bin.vi ‏13 KB

    Did you consider reading the text of the error message? Don't set the "disable buffering" input to true - just leave that input unwired. Why do you want to disable buffering?
    As a general practice, the file refnum should be stored in a shift register around the for loop instead of using loop tunnels, that way if you have zero iterations you will still get the file refnum passed through correctly. Also, there is no need for Set File Position inside the loop, since the file location is always the end of the last write unless it's specifically moved to another location. You might want it once outside the loop after you open the file, if you're appending to an existing file.

  • UTL_FILE write_error when writing large binary files to unix os

    I am trying to write large files to a folder in unix from a table containing a BLOB object. The procedure below is called by another procedure I have written to do this. It works in windows environment fine with files up to 360MB. When I run this exact same procedure in UNIX I get an initialization error. When I change the WB in the fopen call to W it works. I can store all the files I want up to 130MB in size. The next size larger file I have is 240MB and it fails after writing the first 1KB passing the utl_file.write_error message. If someone can help me to diagnose the problem, I would really appreciate it. i have been trying everything I can think of to get this to work.
    Specifics are, the windows version is 10GR2, on unix we are running on Sun Solaris 9 using 9iR2
    PROCEDURE writebin(pi_file_name IN VARCHAR2, pi_file_url IN VARCHAR2, pi_file_data IN BLOB)
    IS
    v_file_ref utl_file.file_type;
    v_lob_size NUMBER;
    v_raw_max_size constant NUMBER := 32767;
    v_buffer raw(32767);
    v_buffer_offset NUMBER := 1;
    -- Position in stream
    v_buffer_length NUMBER;
    BEGIN
    -- WB used in windows environment. W used in unix
    v_lob_size := dbms_lob.getlength(pi_file_data);
    v_file_ref := utl_file.fopen(pi_file_url, pi_file_name, 'WB', v_raw_max_size);
    v_buffer_length := v_raw_max_size;
    WHILE v_buffer_offset < v_lob_size
    LOOP
    IF v_buffer_offset + v_raw_max_size > v_lob_size THEN
    v_buffer_length := v_lob_size -v_buffer_offset;
    END IF;
    dbms_lob.READ(pi_file_data, v_buffer_length, v_buffer_offset, v_buffer);
    utl_file.put_raw(v_file_ref, v_buffer, TRUE);
    v_buffer_offset := v_buffer_offset + v_buffer_length;
    END LOOP;
    utl_file.fclose(v_file_ref);
    END writebin;
    Message was edited by:
    user599879

    check if this cample code helps -
    CREATE OR REPLACE PROCEDURE prc_unload_blob_to_file IS
    vlocation      VARCHAR2(16) := ‘LOB_OUTPUT’;
    vopen_mode     VARCHAR2(16) := ‘w’;
    bimax_linesize NUMBER := 32767;
    v_my_vr        RAW(32767);
    v_start_pos    NUMBER := 1;
    v_output       utl_file.file_type;
    BEGIN
    FOR cur_lob IN (SELECT vmime_type,
    blob_resim,
    vresim,
    dbms_lob.getlength(blob_resim) len
    FROM tcihaz_resim a
    WHERE rownum < 3 -- for test purposes
    ORDER BY a.nresim_id) LOOP
    v_output := utl_file.fopen(vlocation,
    cur_lob.vresim,
    vopen_mode,
    bimax_linesize);
    dbms_output.put_line(’Column length: ‘ || to_char(cur_lob.len) || ‘ for file: ‘ ||
    cur_lob.vresim);
    v_start_pos := 1;
    IF cur_lob.len < bimax_linesize THEN
    dbms_lob.READ(cur_lob.blob_resim,
    cur_lob.len,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
    ‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
    ELSE
    dbms_lob.READ(cur_lob.blob_resim,
    bimax_linesize,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ || to_char(cur_lob.len) ||
    ‘ Bytes’ || ‘ for file: ‘ || cur_lob.vresim);
    END IF;
    v_start_pos := v_start_pos + bimax_linesize;
    WHILE (v_start_pos < bimax_linesize) LOOP
    -- loop till entire data is fetched
    dbms_lob.READ(cur_lob.blob_resim,
    bimax_linesize,
    v_start_pos,
    v_my_vr);
    utl_file.put_raw(v_output,
    v_my_vr,
    autoflush => TRUE);
    dbms_output.put_line(’Finished Reading and Flushing ‘ ||
    to_char(bimax_linesize + v_start_pos - 1) || ‘ Bytes’ ||
    ‘ for file: ‘ || cur_lob.vresim);
    v_start_pos := v_start_pos + bimax_linesize;
    END LOOP;
    utl_file.fclose(v_output);
    dbms_output.put_line(’Finished successfully and file closed’);
    END LOOP;
    END prc_unload_blob_to_file;
    set serveroutput on
    set timing on
    create or replace directory LOB_OUTPUT as ‘/export/home/oracle/tutema/’;
    GRANT ALL ON DIRECTORY LOB_OUTPUT TO PUBLIC;
    exec prc_unload_blob_to_file ;
    Column length: 3330 for file: no_image_found.gif
    Finished Reading and Flushing 3330 Bytes for file: no_image_found.gif
    Finished successfully and file closed
    Column length: 10223 for file: OT311.gif
    Finished Reading and Flushing 10223 Bytes for file: OT311.gif
    Finished successfully and file closed
    PL/SQL procedure successfully completedWith 9iR2 PLSQL can write binary files using UTL_FILE put_raw function, prior to Oracle9iR2 you will need to create an external procedure with Java, C, VB or some 3gl language.
    Some references -
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6379798216275
    Oracle® Database PL/SQL Packages and Types Reference 10g Release 2 (10.2)
    UTL_FILE - http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14095
    http://psoug.org/reference/dbms_lob.html
    Metalink Note:70110.1, Subject: WRITING BLOB/CLOB/BFILE CONTENTS TO A FILE USING EXTERNAL PROCEDURES

Maybe you are looking for