Append binary file

I would like to append new binary values to the existing binary file. Write File.vi looks like a good candidate for this, and it has two inputs, pos. mode and pos. offset which looks like something useful for my task. Unfortunately whatever I put into pos offset input I got Error 4 �end of file� and whatever I put into pos. mode nothing changes in binary file. There is also no example on the web which makes any use of them.
Please can you tell how I can simply append new binary values to existing binary file. I put vi. In attachment which will write binary file, but only once.
Thanks,
Zoran
Solved!
Go to Solution.
Attachments:
bin_file_write.llb ‏396 KB

Will this work if I have a situation like this ?
I have a DAQ VI which gives me about 32667 events in about 10 loops. I want to append these events onto a binary file after every iteration. I followed the message conversations regarding the append binary file but for some reason only the latest set of events are recorded. Will this work in a loop ?
Kudos always welcome for helpful posts

Similar Messages

  • How to append binary data to existing file in OSB

    Hi,
    I have an OSB project that I need for it to append binary data via ftp.  Here's my current flow:
    MFL binary output --> Replace $body with mfl binary output --> Publish to action (Business service that's configured to ftp binary data).
    However, when the data is ftp'ed the following error is thrown:
    URI = ftp://xxx:21/opt/home/zzz/logs
    Request metadata =
        <xml-fragment>
          <tran:headers xsi:type="ftp:FtpRequestHeaders" xmlns:ftp="http://www.bea.com/wli/sb/transports/ftp" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="h
    ttp://www.w3.org/2001/XMLSchema-instance">
            <ftp:fileName>11802_insert_oh_xfrmr.eai_data</ftp:fileName>
          </tran:headers>
          <tran:encoding xmlns:tran="http://www.bea.com/wli/sb/transports">utf-8</tran:encoding>
          <ftp:isFilePath xmlns:ftp="http://www.bea.com/wli/sb/transports/ftp">false</ftp:isFilePath>
        </xml-fragment>
    Payload =
    19266787^CLLL^C711791^CLLL^C^C1178213^CSingle Phase(1)^C63185066204^CA^CConstructed^C358880 NW 4 DR LK MONTAZA^C120/240^C09361^CN/A^CProposed Remove^CAerial^C45718100^C
    Unknown^C^CNo^CNormal Closed^CClamp^CA^C1^C2-Cover^C19266796^CNo^CNo^C15^C^CYes^CYes^CYes^C13200Y/7620 X 22860Y/13200^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
    ^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C19266641^Coh_fuse_switch^C63086930001^C4^CN31^CDD0613^C22.9^C63376474601^C8129580^CFalse^C4^COke
    echobee^C43^C0^Cdefault^CYes^C
    >
    ####<Nov 6, 2013 2:28:23 PM EST> <Error> <WliSbTransports> <goxsd1604> <osb_server1> <[ACTIVE] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<
    anonymous>> <BEA1-4B688443B66FA09FFE75> <d2b4601b2fffd9b7:6b9f2297:1422a857ee8:-8000-000000000000171b> <1383766103889> <BEA-381105> <Error occured for the service endpo
    int: com.bea.wli.sb.transports.TransportException: Unable to open data connection. Message is Received error response (553) from FTP server [mpsd1] IP [10.111.19.32] po
    rt [21] status [connected] upon executing command [stor opt/home/zzz/logs/11802_insert_oh_xfrmr.eai_data.a]
    com.bea.wli.sb.transports.TransportException: Unable to open data connection. Message is Received error response (553) from FTP server [mpsd1] IP [10.111.19.32] port [2
    1] status [connected] upon executing command [stor opt/home/icanadm/logs/11802_insert_oh_xfrmr.eai_data.a]
            at com.bea.wli.sb.transports.ftp.connector.FTPTransportProvider.sendMessage(FTPTransportProvider.java:422)
    From what I understand the error code 553 represents a bad file name.  The file name that I'm supplying is 11802_insert_oh_xfrmr.eai_data but it appears that the name is changed to 11802_insert_oh_xfrmr.eai_data.a .  So I did the obvious and changed the file several different ways (without the .eai_data extension, removed the numbers from the file name) but still no luck. 
    Any suggestions?
    Thanks,
    Yusuf

    Thanks Eric.
    I'm using the JCA FTP adapter instead and noticed it's appending the test generated data supplied by the OSB test console.
    However, how can I ensure that the MFL output that I need to append will be placed on a new line? 
    Also, how should I map/assign the MFL binary output to the opaqueElement type base64Binary defined in the WSDL file below?
    Once again here's a sample payload that I need to ensure will be presented on a new line:
    19266787^CLLL^C711791^CLLL^C^C1178213^CSingle Phase(1)^C63185066204^CA^CConstructed^C358880 NW 4 DR LK MONTAZA^C120/240^C09361^CN/A^CProposed Remove^CAerial^C45718100^C
    Unknown^C^CNo^CNormal Closed^CClamp^CA^C1^C2-Cover^C19266796^CNo^CNo^C15^C^CYes^CYes^CYes^C13200Y/7620 X 22860Y/13200^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
    ^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C19266641^Coh_fuse_switch^C63086930001^C4^CN31^CDD0613^C22.9^C63376474601^C8129580^CFalse^C4^COke
    echobee^C43^C0^Cdefault^CYes
    Here's the WSDL file that gets generated for the FTP adapter:
    <wsdl:definitions
         name="PutGenericDevice"
         targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/ftp/AMS/Project1/PutGenericDevice"
         xmlns:jca="http://xmlns.oracle.com/pcbpel/wsdl/jca/"
         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
         xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/ftp/AMS/Project1/PutGenericDevice"
         xmlns:opaque="http://xmlns.oracle.com/pcbpel/adapter/opaque/"
         xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
        >
      <plt:partnerLinkType name="Put_plt" >
        <plt:role name="Put_role" >
          <plt:portType name="tns:Put_ptt" />
        </plt:role>
      </plt:partnerLinkType>
        <wsdl:types>
        <schema targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/opaque/"
                xmlns="http://www.w3.org/2001/XMLSchema" >
          <element name="opaqueElement" type="base64Binary"/>
        </schema>
        </wsdl:types>
        <wsdl:message name="Put_msg">
            <wsdl:part name="opaque" element="opaque:opaqueElement"/>
        </wsdl:message>
        <wsdl:portType name="Put_ptt">
            <wsdl:operation name="Put">
                <wsdl:input message="tns:Put_msg"/>
            </wsdl:operation>
        </wsdl:portType>
    </wsdl:definitions>
    Here's the JCA details:
    <adapter-config name="PutGenericDevice" adapter="FTP Adapter" wsdlLocation="PutGenericDevice.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
      <connection-factory location="eis/ftp/DssPut"/>
      <endpoint-interaction portType="Put_ptt" operation="Put">
        <interaction-spec className="oracle.tip.adapter.ftp.outbound.FTPInteractionSpec">
          <property name="PhysicalDirectory" value="/opt/eai/ofmw/Oracle/Middleware_R7/logs"/>
          <property name="FileType" value="binary"/>
          <property name="Append" value="true"/>
          <property name="FileNamingConvention" value="dummy.txt"/>
        </interaction-spec>
      </endpoint-interaction>
    </adapter-config>
    Thanks,
    Yusuf

  • 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.

  • Binary file data plugin : append block values to channel

    I need to create a data plugin for a unique binary file structure, which you can see in the attached graphic.
    With these objects
    Dim sBlock : Set sBlock = sFile.GetBinaryBlock()
    sBlock.Position = ? 'value in bytes
    sBlock.BlockWidth = ? 'value in bytes
    sBlock.BlockLength = ? 'value in bits
    I have the possiblity to read chunks from my binary file. At the end, I want to have each signal in a respective channel. I could manage to extract signals 1 and 2, as they only have one value in each block with a known byte-distance in between. How can I extract the other channels, that have 480 successive values in each block? I could probably write a loop and read the specific signal part in each block, but how can I append these parts to the relevant channels? I tried by creating a new channel and then merging them, but unfortunately functions like ChnConcat are not working in a data plugin. Any ideas?
    /Phex
    PS. Of course I could create a hideous plugin with running GetNextBinaryValue() throught the whole file, but that doesn't seem to be a smart idea for a 2 GB file size.
    Attachments:
    KRE_DataPlugin_schematic.JPG ‏84 KB

    Phex wrote:
    @usac:
    Your workaround seems to work at least for part of the file. If I loop it through the whole 1.5 GB file I am getting the DLL error "The application is out of memory". There is enough dedicated RAM available, but I guess this is x86 related.
    Hello Phex,
    Have you tried running this Script in the DIAdem 64-bit preview version (which gets you access to more than 2 GB or RAM for your application) that can be found at http://www.ni.com/beta and can be installed in parallel to the 32-bit version.
    It might get you around the "out of memory" issue ...
          Otmar
    Otmar D. Foehner
    Business Development Manager
    DIAdem and Test Data Management
    National Instruments
    Austin, TX - USA
    "For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."

  • Append Text Header for Binary file

    Hello Experts
    I am using LabView 7.0 with PCI 6040 DAQ. I have created two separate files, one file is Binary that collects binary raw data from 16 channels of the DAQ. The second file contains variable length Header, i.e the information about all 16 channels and physical conditions of the recording. I am trying to merge these two files to form a single file that contains a text header at the top and followed by the binary data. I am unable to figure out that how can I append binary data to a text file.
    I need help from users please.  
    Ciao!!!!
    Nabeel

    Hi Chris, Dev
    I am working on Implementation of EDF file format (European data Format) in Lab View.  This file format is widely becoming a standard to acquire and store the physical data of patients. In short, the specification of the file can b read at  ( http://www.hsr.nl/edf/specs/edf.html ). Most of the companies that develop equipments for EEG (electroencephalogram) are implementing this format to read and write data. In my experiments I am also using the same file format but just to acquire and store. For reading and analysing the data Matlab is widely used instead of Labview. Dev, I have just start introducing myself to the idea of Data loggers.  
    Dear Chris I have labview 7.0, is it possible to reload the file for 7.0? If not can you load it as a picture format?
    Regards
    Nabeel    

  • Report using Binary file

    Hi All , can anyone help me here ...
    I used “Write to Binary” to  write my report , at first stage this file is writing headers , including column  headings . at 2nd writing stage it is writing  data in columns.  This file can be viewed in .doc or .xls format. I have three issues
    1.         If I want to print this file from Front Panel  , what I should do?
    2.         other thing is if I stop logging and then start for another span , it starts writing from the first line instead of from last line  , because of this problem it is causing over-writing .
    3          another thing  , lets say if for 2nd or 3rd logging , I want to display sub-headings (test-1 , test-2) , how to insert , for example :
    MAIN HEADING (COMPANY NAME , REPORT TITLE )
    DATE , PRODUCT INFO , OPERATOR NAME
    COL1              COL2              COL3              COL4
    Subheading (test-1)
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Subheading (Test-2)
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Any help in this regard will be highly appreciated.
    Regards
    Faiyaz
    Attachments:
    report-writing-binaryfile.vi ‏68 KB
    02-display-subVI.vi ‏12 KB

    Hi Faiyaz,
    1. How Do I Print a File Programmatically From LabVIEW?
    2. Please the Programming >> File I/O >> Advanced File Functions >> Set File Position function on the block diagram after the Open/Create/Replace File function and set the from input to "end." This will append new data to the end of the file.
    3. You can simply add that information to the Format into String you are writing to the second Write to Binary file.
    Michael K.
    | Michael K | Project Manager | LabVIEW R&D | National Instruments |

  • Deleting a single element from a binary file

    I am working on a server application that must keep track of the messages that have been sent but not responded to.  After I send a message, I append it to an array cycling through an uninitialized shift register and I write it to the end of a binary file.  When I receive a response to a message, which was probably but not necessarily the first message sent, I delete that message from the array and the file.  This allows me to look up entries quickly but also to maintain a permanent record of what messages have been sent and not responded to.
    Basically, I need an intelligent way to make a file, or any other permanent storage medium, act effectively like a queue.  The problem with the current implementation is that when I delete one variable-sized entry from the file, I need to move all subsequent entries, which are usually all of the other entries in the file, forward in memory to take its place.  Is there a way to get around recopying the majority of the file or to implement this entire thing more intelligently?

    You can organize your datafile as a list. For example In this list any record consists of a fixed size data field and referencies (file position f.e.) to the next record and  to the previous record. You can then rewrite the record-have-to-be-deleted with new one, or you can "delete" this record modifiyng the referencies of the "previous" and the "next" records. When you will add a new record you can write one at this "free" place.
    The other way is to manage two files. The first one contains your data record by record. The second one contains the numbers of the records and the corresponding datafile positions or record counter. This second file can be very small and easy-to-manage. It can represent the only record's queue position in the datafile. You can rewrite your records, mark them as deleted without moving large portions of data.
    You can setup the datafile capacity in "number of records" term.
    Additionally it is possible to use the records with variable length but it will be much more dificult. 
    Best regards, Evgeny. 

  • PI 7.1 Email Attachment binary file

    Hi,
    I am trying to attach a binary (encrypted) file to a regular mapped email (receiver adapter) before sending it.
    It is similiar to attach pdf-files at the end of a mapping process.
    Is there no way to attach binary files other than writing an adapter module?
    Is there no generic "Attach File" module in PI 7.11?
    I tried ASMA with XSLT, but the problem is, that the file is binary and the sender adapter would not read it without xml-format.
    Any good idea?
    thanks
    hs

    Hi Holger,
    Just a suggestion:
    1. Read the binary file using file adapter (in binary mode)
    2. use a mail package and put the read content into the Content node of it. You can use this java mapping for it
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import com.sap.aii.mapping.api.AbstractTransformation;
    import  com.sap.aii.mapping.api.DynamicConfiguration;
    import com.sap.aii.mapping.api.DynamicConfigurationKey;
    import com.sap.aii.mapping.api.StreamTransformationException;
    import com.sap.aii.mapping.api.TransformationInput;
    import com.sap.aii.mapping.api.TransformationOutput;
    import com.sap.aii.mapping.api.InputHeader;
    public class JavaMapping extends AbstractTransformation {
         public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
         getTrace().addInfo("JAVA Mapping Called");
         //Input payload is obtained by using arg0.getInputPayload().getInputStream()
         String inData = convertStreamToString(arg0.getInputPayload().getInputStream());
         String outData = inData
         try
         //8. The JAVA mapping output payload is returned using the TransformationOutput class
         // arg1.getOutputPayload().getOutputStream()
              arg1.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
         catch(Exception exception1) { }
         public String convertStreamToString(InputStream in){
         StringBuffer sb = new StringBuffer();
         try
         InputStreamReader isr = new InputStreamReader(in);
         Reader reader =
         new BufferedReader(isr);
         int ch;
         while((ch = in.read()) > -1) {
              sb.append((char)ch);}
              reader.close();
         catch(Exception exception) { }
         return sb.toString();
    Then provide the filename dynamically into the ContentType of the mail package.
    I guess this should work.
    Regards
    Suraj

  • Decode Base64 and save as binary file

    Hi there,
    I am using Adobe Air 1.5 with JavaScript and want to save a file to my hard
    drive. I get the data from a WebService via SOAP as a Base64 encoded string. A test-string is attached. When I try to decode it with
    the WebKit function "atob()" and try to save this bytes with following code, I can't open the file.
    this.writeFile = function(outputfile, content, append){
    var file =a ir.File.applicationStorageDirectory.resolvePath(outputfile);
    var stream = newa ir.FileStream();
    if (append) {
    stream.open(filea, ir.FileMode.APPEND);
    }else {
    stream.open(filea, ir.FileMode.WRITE);
    try{//Binärdaten
    stream.writeBytes(content0, , content.length);
    }catch(e){//Textdaten
    stream.writeUTFBytes(content);
    stream.close();
    The same happens when I try to open a file from my HDD and read in the bytes. When I decode it to base64, the string is not equal to the string, which is correct.
    I attached a working Base64 string, which I could convert back to a zip-file via a only encoder.
    So my question is, how can I decode a Base64 string and save the binary data to a file?
    Thank you for your help.

    I rewrote the Base64 decoder/encoder to use it with a ByteArray. Here ist the code:
    var byteArrayToBase64 = function(byteArr){
        var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         var encOut = "";
        var bits;
        var i = 0;
        while(byteArr.length >= i+3){
            bits = (byteArr[i++] & 0xff) << 16 | (byteArr[i++] & 0xff) << 8 | byteArr[i++] & 0xff;
              encOut += base64s.charAt((bits & 0x00fc0000) >> 18) + base64s.charAt((bits & 0x0003f000) >> 12) + base64s.charAt((bits & 0x00000fc0) >> 6) + base64s.charAt((bits & 0x0000003f));
        if(byteArr.length-i > 0 && byteArr.length-i < 3){
            var dual = Boolean(byteArr.length - i - 1);
            bits = ((byteArr[i++] & 0xff) << 16) | (dual ? (byteArr[i] & 0xff) << 8 : 0);
            encOut += base64s.charAt((bits & 0x00fc0000) >> 18) + base64s.charAt((bits & 0x0003f000) >> 12) + (dual ? base64s.charAt((bits & 0x00000fc0) >> 6) : '=') + '=';
        return encOut;
    var base64ToByteArray = function(encStr){
        var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         var decOut = new air.ByteArray(); 
        var bits;
        for(var i = 0, j = 0; i<encStr.length; i += 4, j += 3){
            bits = (base64s.indexOf(encStr.charAt(i)) & 0xff) <<18 | (base64s.indexOf(encStr.charAt(i +1)) & 0xff) <<12 | (base64s.indexOf(encStr.charAt(i +2)) & 0xff) << 6 | base64s.indexOf(encStr.charAt(i +3)) & 0xff;
            decOut[j+0] = ((bits & 0xff0000) >> 16);
              if(i+4 != encStr.length || encStr.charCodeAt(encStr.length - 2) != 61){
                   decOut[j+1] = ((bits & 0xff00) >> 8);
              if(i+4 != encStr.length || encStr.charCodeAt(encStr.length - 1) != 61){
                   decOut[j+2] = (bits & 0xff);
        return decOut;

  • Write to binary file

    I have a relatively large 3D array (Phase Settling), which I want to store in a Binary File. The array is a 15000 point sweep (after decimation), repeated up to 48 by 48 times (in two FOR loops, one inside the other), meaning it can end up having as many as 34,560,000 data points. At the moment, I am attempting to dump that 3D array into a Binary File in one go, using the following VI. There are two possile versions of this array (both the same size as each other) and, depending on which has just been tested, they will be written to their own individual file. Once both tests have been run and their results stored, the idea was to open both files, subtract one array from the other, and store the new 3D array to another Binary File whilst also displaying this latest data elsewhere in a higher-level VI.
    After its first trial run, LabVIEW presents me with an error message saying something along the lines of "LabVIEW had run out of memory". I assume it would be to do with this VI, since that's where the first error code appeared (Error Code: 2), apparently originating in a 'Write to Binary File' function.
    Any ideas as to how I could get round this first hurdle, or perhaps an alternative method I could try?
    Thank you.
    - James
    Message Edited by James Mamakos on 04-08-2010 10:07 AM
    Never say "Oops." Always say "Ah, interesting!"
    Attachments:
    Running out of LabVIEW memory when writing to binary file.PNG ‏30 KB

    Well, as shown in the attached screen-shot, the error indicator shows an error code of 2, and that the error occurred in one of the Write to Binary File functions.
    However, when trying to save this particular VI after a couple of tweaks, I was presented with the following pop-up alert message:
    LabVIEW:  Memory is full.
    Cannot save VI "Compare Amp - calculate.vi".
    LabVIEW Save error code 10: Default data space.
    Anyway, returning back to the main problem at hand, I've though of a couple of possible solutions...
    We don't really need a particularly high resolution to the data points for the comparison, so I could convert the array doubles into an array of singles to save space.
    I should be able to implement the 'Write to Binary File' for the initial arrays into the outer FOR loop, thereby reducing the amount data written in each instance by a factor of up to 48. The only problem I can foresee in this is that I'm not sure how to append 2D arrays into a binary file such that, when the file is read, they would appear as (or be easily converted into) a 3D array.
    As for the 'True' case in my case structure, am I being grossly inefficient in my passing of data from one place to the next? I know there are a lot of branches (and buffers?) of 3D arrays; is there a decent way to reduce this overhead by tweaking the data paths or something?
    - James
    P.S. The computer I'm using has 1GB RAM.
    Message Edited by James Mamakos on 04-08-2010 12:39 PM
    Never say "Oops." Always say "Ah, interesting!"
    Attachments:
    LabVIEW - error code 2.PNG ‏35 KB

  • Can't decrypt binary file with PBE

    Hi,
    I'm writing an simple file transfer application using UDP that encrypts the data
    before sending it with PBEWithMD5AndDES. Text files are encrypted and
    decrypted fine, but binary files such as a JPG/EXE/DOC... are messed up
    and an application can't open them on the other side. Has anyone experienced
    such a problem?
    Thanks

    Below are my encrypt and decrypt functions.
    Thanks in advance.
            public  byte[] encrypt(byte[] data)
                 PBEKeySpec pbeKeySpec;
                 PBEParameterSpec pbeParamSpec;
                 SecretKeyFactory keyFac;
                 ByteArrayOutputStream b=null;
                 DataOutputStream d =null;
                 //      Salt
                 byte[] salt = {
                           (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
                        (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
                 //      Iteration count
                 int count = 1000;
                 // Create PBE parameter set
                 pbeParamSpec = new PBEParameterSpec(salt, count);
                 try{
                      pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
                      keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
                      SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                      // Create PBE Cipher
                      Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
                      // Initialize PBE Cipher with key and parameters
                      pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
                      b = new ByteArrayOutputStream();
                      d = new DataOutputStream(b);
                      // create CipherOutputStream
                      CipherOutputStream out = new CipherOutputStream( b, pbeCipher );
                      // write contents to file and close
                      try {
                           for ( int i = 0; i < data.length; i++ )
                                out.write(data);
                             out.flush();
                        out.close();
                   // handle IOException
                   catch ( IOException exception ) {
                        exception.printStackTrace();
              catch(Exception e){}
              return(b.toByteArray());
         public byte[] decrypt(byte[] data)
              PBEKeySpec pbeKeySpec;
              PBEParameterSpec pbeParamSpec;
              SecretKeyFactory keyFac;
              byte[] decryptedData=null;
              //      Salt
              byte[] salt = {
                        (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
                        (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
              //      Iteration count
              int count = 1000;
              // Create PBE parameter set
              pbeParamSpec = new PBEParameterSpec(salt, count);
              try{
                   pbeKeySpec = new PBEKeySpec(sessionPassword.toCharArray());
                   keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES","SunJCE");
                   SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
                   // Create PBE Cipher
                   Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES","SunJCE");
                   // Initialize PBE Cipher with key and parameters
                   pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
                   Vector fileBytes = new Vector();
                   ByteArrayInputStream b = new ByteArrayInputStream(data);
                   CipherInputStream in = new CipherInputStream( b, pbeCipher );
                   byte contents = ( byte ) in.read();
                   while ( contents != -1 )
                        fileBytes.add( new Byte( contents ) );
                        contents = ( byte ) in.read();
                   in.close();
                   decryptedData = new byte[ fileBytes.size() ];
                   for ( int i = 0; i < fileBytes.size(); i++ )
                        decryptedData[ i ] = (( Byte )fileBytes.elementAt( i )).byteValue();
              catch(Exception e){Gui.chatArea.append("exception:"+e+"\n");}
              return(decryptedData);

  • Write-read binary file Error 116

    Hi all,
    I am saving double, numeric array data into a binary file and then trying to read it back but keep on getting Error 116 (cannot read from binary file).
    I have attached screenshots of the way I am writing my data into the binary file and then the way I am trying to read it. Basically my data is chunks of 2D double arrays, coming at a rate of 1hz and this is why I have to use the get and set file size functions prior to saving into the file (i.e. so that each time I can append my file with new data).
    I have tried all combinations for the write to binary and read to binary file functions, thus meaning I have tried little, big and native endian options but I keep getting the same error. Also played with the way I append my data, i.e. I have used both the "offset in bytes" and "end of file" options, just in case this made any difference, but again no luck.
    Any help would be much much appreciated.
    Regards,
    Harry
    Solved!
    Go to Solution.
    Attachments:
    Write_Bin.JPG ‏154 KB
    Read_Bin.JPG ‏100 KB

    Just as an amendment to my original post, I can succesfully read my data in MATLAB using the standard fread function with double precision. I presume that this means that there is nothing wrong with the way I write the data into the file. However, it would be useful for me to be able to read it directly from Labview without having to build matlab executables etc etc...
    cheers again

  • How to Convert Binary Data in Binary File

    hi,
    my telecom client puts a binary file which is asn.1 encoded with BER.
    how to handle binary data in java.
    how to convert binary to hexa to ascii format
    how to convert binary to octet to ascii format
    please help me in this.
    regards,
    s.mohamed asif

    You don't need to convert the data.
    Only you can do is print it in that formats, like it:
    public static String byteArrayToHex(byte[] b) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < b.length; i++)
             sb.append(Integer.toHexString(b&255) + " ");
    return sb.toString();
    take a look at this
    http://java.sun.com/docs/books/tutorial/essential/io/

  • Convert Large Binary File to Large ASCI File

    Hello, I need some suggestions on how to convert a large binary file > 200MB to an ASCI File. I have a program that streams data to disk in binary format and now I would like to either add to my application or create a new app if necessary. Here is what I want to do:
    Open the Binary File
    Read a portion of the File into an array
    Convert the array to ASCI
    Save the array to a file
    Go back and read more binary data
    Convert the array to ASCI
    Append the array to the ASCI file
    Keep converting until the end of the binary file.
    I should say that the binary data is 32-bits and I do need to parse the data; bits 0-11, bits 12-23, and bits 31-28, but I can figure that out later. The problem I see is that the file will be very large, perhaps even greater than 1GB and I don't have a clue how to read a portion of the file and come back and read another portion and then stop at the end of the file. I hope to save the data in a spreadsheet.  If anyone has some experience with a similiar situation I'd appreciate any input or example code.
    Thanks,
    joe

    sle,
    In the future, please create a new thread for unrelated questions.  To answer your question, you can use "Split Number" from the Data Manipulation palette.
    Message Edited by jasonhill on 03-14-2006 03:46 PM
    Attachments:
    split number.PNG ‏2 KB

  • Binary File IO DLL Problem

    Hiii
        I have developed one Binary file Read/Write Vi..  and then i have convert that vi in to DLL......
        Now i tested that DLL Vi  it is showing an error No 74. Actually for Binary write i will convert the Input cluster to Flattern to String and for Binary Read i will convert the output to unflattern to string.. I have attached the TEST.vi for reference
    Attachments:
    Binary Read#Write DLL.vi ‏18 KB
    Binary File Read#Write.vi ‏24 KB
    TEST.vi.vi ‏31 KB

    hi there
    if you want to read the size of the string you have to enable the "append array or string size" at the write file function. or you do not append the size and simply read all bytes.
    in any case you should replace existing files to avoid remaining bytes of larger strings written in prior calls.
    See attachment for details.
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"
    Attachments:
    IO.JPG ‏66 KB
    IO_8.5.vi ‏27 KB

Maybe you are looking for

  • How do I get my airport extreme to show up under hardware in my Lion server app.

    My airport extreme is not showing up in Hardware in my lion server app. How do i configure the settings on my airport extreme to work with the lion server app?

  • Isn't it a time for a new E61i firmware?

    I am sure that may be true for a lot of Nokia phones, but based on what I am reading here and on other Nokia forums, doesn't it sound like it may be a time for a new firmware? There is certainly a few "issues" to be addressed there.

  • CN41 Customer Fields for WBS not visible in the CN41 report

    Hi, I have Done the Below Steps: I have done all the Things Below and it is working Also.: Create structure CI_PRPS. Create enhancement. Edit the function exits. Maintain the global declarations. Design the customer-specific screen. Activate the enha

  • Auditing dba to syslog

    Hi Hemant, 11.2.0.1 Aix 6.1 I am still confused about sys logging. I configured sys logging already thru: editing pfile and add: *.audit_file_dest='/var/log/oracle/proddr' *.audit_sys_operations=TRUE *.audit_trail='OS' *.audit_syslog_level='LOCAL5.IN

  • Wrong cell #

    I have been without my cell for over a month now.  My son was helping to activate my new phone and it has the wrong cell #.  It is showing (removed) and it should be (removed).  I NEED to activate my cell, so how does it get changed to the correct #?