Binary file compare

I'm sorry. I didn't want to have to post here, but I've been banging my head on this all week. Hopefully somebody here can shed some light on this for me.
I'm trying to write an application that compares a series of binary files in a user-defined order. The user needs to be able to specify the type of change that has occured ( > < = !, and numerical searches) for a given byte. (I am also supporting WORD/DWORD, but it's the same principal) To clarify, imagine:
Byte at given offset: (((fileA < fileB) = fileC) != fileD) ...
Now, my original code worked, but it was extremely poor. It had two methods fullCompare() and partialCompare(), it read data directly from the DataInputStream, and used skipBytes() to pass over bytes that had been excluded from a previous search. I kept thinking "There has to be a better way to do this." So I made it as simple as possible! I created an inner class called BinaryFile. BinaryFile reads the data (using getUnsignedByte() getByte() getUnsignedShort() getShort() etc... depending on the user's option.
I created two instances of this class... One I call 'result' and the other 'bin' the files are read in by the constructor and stored in an ArrayList<Integer> (later I cast my Shorts to int)
Now, 'result' holds the first file opened, and bin holds each additional file, ex:
BinaryFile result = new BinaryFile("C:\\test1.bin", BinaryFile.UNSIGNED_WORD);
All of this works�. OK, so now I run my first compare:
compare(new BinaryFile("C:\\test2.bin", BinaryFile.UNSIGNED_BYTE), GREATER_THAN);
again, everything works like a champ.. now to actually compare the files, I do this:
public void compare(BinaryFile bin, int compareType) {
for (int count=0; count < results.values.size(); count++) {
if (results.values.get(count) != null) {
switch (compareType) {
case GREATER_THAN:
if (bin.values.get(count) > results.values.get(count))
results.values.set(count, bin.values.get(count));
else
results.values.set(count, null);
break;
                    ����������..
Now, it works for the FIRST two files that I compare, but after that it's like it started setting null when it wasn't supposed to�. I know that nobody probably read this far, but somebody please help me, this is killing me.

I posted that at some unruly hour of the morning, while tired and frustrated... I had a flight from Korea to Japan today and spent the entire trip reading J2SE 5 docs about collections and generics, etc... So I'm going to give this one more go-round before I ask for help. I hate being beaten by a machine, asking for help makes me feel like I lost!
Thanks

Similar Messages

  • Binary File compare - Problem with char 65533

    Hi,
    I tried to copy an sqlite database (a normal text file) out of my *.jar file. The database is in my java project as a resource file. I read every byte and store it directly into the new file, but somewhow it changes 4 Bytes to 65533! The correct values are 2 times 129 and 2 times 144. It's really strange!
    Have you an idea why this happens? Or is there a better way how to copy out a resource file?
    Thank you for your answers.
            URL u = this.getClass().getResource("/database/resources/mydb.sqlite");
            try {
                InputStreamReader in = new InputStreamReader(u.openStream());
                File outputFile = new File("newdb.sqlite");
                FileWriter out = new FileWriter(outputFile);
                BufferedWriter writer = new BufferedWriter(out);
                while ((c = in.read()) != -1) {
                    writer.write(c);
                in.close();
                writer.close();
            } catch(Exception e) {
                jErrorFld.setText(e.toString());
            }

    Writers are for characters not bytes. Use OutputStreams.

  • Compare binary file

    Hi,
    I am using LV 8.5.1. Would like to know, is there any method can compare 2 binary files? Same function as command prompt below:
    fc /b "file 1 path" "file 2 path"
    First do not consider use the system exec.vi.
    Appreciate your feedback.
    Thanks.
    Solved!
    Go to Solution.

    Doing it in LabVIEW is fraught with all sorts of issues that the fc command has probably already addressed.  But if you want to do it, I would recommend the following:
    Read your file in 65,000 byte chunks to optimize disk I/O.
    Compare each chunk.  Your compare operation is up to you.  Note that depending on how you want to compare, you may want to do this byte by byte or chunk by chunk to find the locations of differences, but also find locations which equal, even if they have different offsets (e.g. a difference is a single byte inserted into the file).
    Output your results.  The output is also up to you.  It could be a file, a front panel indicator, the operating system error buffer, etc.
    All in all, this is a lot of work vs. just using the fc command.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Compare service-types.db.pacnew, binary file

    After today's update I have /usr/lib/avahi/service-types.db.pacnew. I use 'Meld' to usually, compare .pacnew with the original file. However I am unable to do so because 'Meld' says, "Could not read file... appears to be a binary file".
    I don't have any knowledge of comparing binary files.. I don't know how to deal with it even if I use any other utility which might read binaries.
    I need to know, whether it will be safe to delete either file, /usr/lib/avahi/service-types.db or /usr/lib/avahi/service-types.db.pacnew?
    I am sure I never edited the said file, unless some application did so.
    The Forum guidance is requested.
    Thanks.
    Last edited by fantab (2013-03-03 11:28:50)

    I got the reply to my query with the package maintainer:
    Gaetan Bisson wrote:
    Feel free to inspect the svnlog:
            https://projects.archlinux.org/svntogit … ages/avahi
    Notice that this changed to the backup array was introduced to
    "implement FS#33930", and check the corresponding bug report:
            https://bugs.archlinux.org/task/33930
    https://projects.archlinux.org/svntogit … 842f2d4496
    If someone can translate the gist of the links in simple English I will be grateful.
    Thanks...

  • 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

  • Problem working with binary file

    Hi,
    I have two seperate programs.
    The first one:
    *Reads a  PDF file from disk via InputStreamReader.read(char[])
    *converts it to s String [String.valueOf(char[])]
    connects to other program using Socket and writes the string's bytes to the OutputStream of the Socket (socket.getOutputStream().write(string.getBytes);)
    Second one:
    *Reads the file from socket via BufferedReader.read(char[])
    *converts it to a string via String.valueOf()
    *writes it to a file using FileOutputStream.write(content.getBytes())
    The problem is:
    If the secong program is running on Win2K,the PDF file is opened with no errors but the pages are all blank.But everything is OK if it is running on Unix(IBM AIX java ver 1.3.1)
    First program is always on Win2K.
    I compared the win2k and unix PDF files,some nonprintable chars are displayed as ? in the win2K one,
    what can be the reason? why does the same problem not occur on Unix?
    Some problems are mentioned on web/forums but these are related with browsers or servlets which I am not using in this case.
    Thanks in advance,

    PDF is a binary file.
    You're doing 1 of 2 possible things wrong....
    1) trying to read a binary file as a text file ( string )
    You can't "just read" a binary file as a text file to extra the strings.
    You need to get the binary format, and parse it's format properly to extract the
    string data.
    2) trying to send a binary file across a socket as a string
    You need to read the PDF file as an array of bytes and send them across
    the socket as such. Trying to convert binary data to characters / strings
    is wrong. characters get converted to and from native encoding schemes to
    unicode.... among other problems.
    regards,
    Owen

  • Binary file corrupted when downloading

    Hi. I'm trying to download binary files using a JSP. This is my code:
    <%
         response.setContentType(report.getContent_type());
         response.setHeader ("Content-Disposition", "attachment;filename=\""+report.getNombre()+"\"");
         byte[] file = report.getFile();
         ServletOutputStream sos = response.getOutputStream();                         
         sos.write(file);
         sos.close();
    %>
    It seems to work, but when i'm going to open the downloaded file, it's corrupted, and when I compare it with the original one, all bytes that follow the first '\0' character have been replaced by '\0'. The file size is the same, but not the content.
    I'm using Websphere as application server. Maybe this problem is related with the server, or maybe I'm doing something wrong. Any ideas?
    Thanks.

    I'm surprised that you didn't event get a IllegalStateException. Rather move all your logic to a servlet, jsps usually add whitespace where scriplets were and could corrupt your content.

  • Binary file to variable

    Hi,
    I want to store a binary file content (it is a MS WORD file) onto a java variable (type String ?) to use this variable to create a new file identical by writing this variable value into a new file.
    I tried it as follow :
    1- I read a file using a fileInputString and method read
    2- I got a byte array, converted it in a String and using URLEncoder produced another String
    3- With this encoded String I created a java code that I displayed on System.out, It looks like :
    String content=""
    +"%D0%CF%11%E0%A1%B1%1A%E1%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%3E%00%03%00%FE%FF%09%00%06%00%00%00%00%00%00%00%00%00%00%00%01%00%00%00%21%00"
    +"%00%00%00%00%00%00%00%10%00%00%23%00%00%00%01%00%00%00%FE%FF%FF%FF%00%00%00%00+%00%00%00%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%FF%F"
    +"%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00";Now I have my binary file in a string and using URLDecoder and writing this String into a new file I must obtain a clone of the original file, but when I compare the original file with this file with command cmp I always obtain severals differences (about 10 or 12 bytes that are differents in a total of 180000) I don't know why theses two files are differents, is there a way to obtain a perfect clone ?

    Hi,
    I want to store a binary file content (it is a MS
    WORD file) onto a java variable (type String ?) to
    use this variable to create a new file identical by
    writing this variable value into a new file.If you want to copy a file, never ever use Strings, use bytes!
    Have a look at the IO tutorial how to read a file as a byte stream:
    http://java.sun.com/docs/books/tutorial/essential/io/

  • Binary File comparaison GUI

    Hi,
    I looking for an implementation of a binary file comparaison with a GUI.
    A component that looks like Eclipse compare API UI.
    A split pane that displays differences between two files with differents colors and automatic scrolling.
    Can you help me
    Thanks in advance

    Resolved..
    Issue is in the code
      do.
        write sy-index to lv_index no-zero.
        concatenate 'CTXT_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        concatenate 'CVAL_' lv_index into lv_heading.
        condense lv_heading no-gaps.
        concatenate lv_string lv_heading c_tab into lv_string.
        if sy-index eq gv_no_col.
          " concatenate c_cret c_tab lv_string into lv_string. "<< to be commented
          exit.
        endif.
      enddo.
    and
      loop at lt_textab into ls_textab.
        wa_out-text = ls_textab.
        lv_string1 = wa_out-text.
        concatenate lv_string c_cret lv_string1 into lv_string. " This line tab is removed
      endloop.

  • Bit comparison on binary files

    Hi
    I am trying to compare two binary files in order to find out how many bits differ between the two files. I dont know how to reference file 'bits' in order to perform the comparison however, and i cannot find much information online. Can anybody give me some pointers on how to start or point me towards some helpful information?
    Thanks

    Read the files in bytes.
    XOR the corresponding bytes. Only bits that differ will be 1.
    AND with 0x01 to see if the low order bit is 1. Shift right and repeat for the rest of the bits.

  • How read just a part of a binary file?

    I want to read only a part of a big binary file.
    I have made a piece of labview code that works well, but every time I try to read only a part of the file, I have an error.
    I try to search where I have make a mistake in the code, but dont find.
    Just for information : at the end of the code, I just display 1 data of 5.
    Thanks in advance.
    Attachments:
    LECTURE-ZOOM.vi ‏66 KB

    Johnsold.
    Thank you for your answer.
    I have tested you vi LECTURE-ZOOM.2.vi, and I think there is some problems with my application.
    First, let me transduce the vi into words : if columns index is more than the max columns value, then you stop, and the same think with the rows index.
    With the sift register you make a memory allocation for the array that changes every loop.
    By doing this way, I have two problem.
    When I read a big file, the memory allocation takes a lot of memory, because the array allocation in memory changes every loop.
    Besides, when I run the vi, the columns and rows are completly wrong, because, the command "chanel number is not respected : if I put 7 chanels, I have 5 chanels on the array.
    Then, When I have it, I compare the "sortie" array versus "entrée" array, and I seems that AFTER decimation (1 point taken on 5), I have more points at the end than at the begining.
    I give you a sample of a data file (compressed in zip...) to test your vi.
    It's a 6 chanels data file, puted in a array.
    When I try to run the vi you modify for me, I seems that it doexn't work because the result was totaly wrong... :-(
    I think that I make a mistake/error in the vi understanding, because I try to change some parts of your vi, to adapt it to my application, but it doesn't work.
    What do you think about my way of read the datas?
    How can I change the vi to obtain the same array than in mine.
    To see what I obtain, just lunch the vi in my next post with the data file in this post.
    Attachments:
    buffer01.zip ‏1201 KB

  • Simulating merge of binary files

    Hello,
    I have someone who is trying to merge binary files. This is not their fundamental problem, but it may be a means of correcting the underlying problem (which is that the file system shows the wrong date and size for some files, while the Designer interface shows them correctly).
    To the binary file issue, the functionality was not introduced to Designer. However, the error message hints at a way of simulating it. But the description of the solution is sparse and I am not certain how to implement it.
    Error Suggestion:
    Binary files cannot be compared. But to simulate a merge
    you may copy one version on top of another version by
    downloading and uploading the data in the appropriate workareas.
    A merge line can be set manually by using the version service
    (jr_version ) function merge.
    Is anyone aware of any documentation that explains the "trick" more clearly, or has anyone had success in implementing it?
    Much thanks,
    Chris

    How do you unzipping the archives?
    Because when you use unzip linux.x64_11gR2_database_1of2.zip
    unzip linux.x64_11gR2_database_2of2.zipit will unpack contents of those archives to database directory (which is created during unpacking), so it is merged automatically.
    Here is output from my test case, archives were freshly downloaded from oracle.com site. Note "-q" switch is quiet mode:
    $ ls
    linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip
    $ unzip -q linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
    $ ls
    database  linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip

  • Any info on CRC, checksum, or other file integity VIs for large binary files?

    Working on send rather large binary files (U16 stream to file) via internet. Would like to check for file integity via CRC or comparable checksum. Would appreciate any comments/suggestions

    Hi Brian,
    You said;
    "Would appreciate any comments/suggestions".
    You did not mention what transport mechanism you plan on using.
    As I understand ALL of the standard mechanism use CRC of some form to ensure the validity of the packet BEFORE it is ever passed up the OSI 7-Layer model.
    TCP/IP based protocols will see to it that all of the segments of a transfer are completed and in order.
    UDP on the other hand is a broadcast type protocol and does not ensure any packets are recieved.
    So,
    At the very worst you should be able to handle your "sanity checks" by simply using a sequence value that is included in your out-going message. The reciever should just have to check if the current seq value is equal to the previous +1.
    I co-developed an app that ut
    ilized this technique to transfer status messages from a RT platform to a Windows machine. The status messages in this app where concidered FYI, so the sequence counter served as a way of determining if anything was missed.
    I am insterested in others thoughts on this subject.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Siebel 8.0.0.12 Fix Pack; Unable to get the seed from binary file.

    Hello Folks,
    Can anyone throw some light into what action is required on my scenario.
    I have applied Fix Pack Siebel 8.0.0.12 on top of 8.0.0.11 SBA. After it is appled, I am facing a documented issue within the Release Notes for the 8.0.0.12 Fix Pack
    The issue is "UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12". I tried the steps given with the MR document, however, I am still having this issue.
    I am also not sure what is expected at the step of; Run the following command: seedgeneratorutil myseed.dat abcdef .
    It's asking me for a value to enter for seed at command prompt. "Enter the seed":
    what I should give here. As an assumption values,I gave SADMIN and tried to launch but still shows up the same error
    Please Assit
    Steps Details from Release Notes:
    UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12
    Component: Server Infrastructure
    Subcomponent: SWSE
    Product Version: Siebel 8.0.0.12
    Base Bug ID: 11938270
    **Users are unable to launch the URL after applying the Siebel 8.0.0.12 Fix Pack.
    **Use the following workaround to address this issue:
    Navigate to the eappweb/bin directory from the command line on the SWSE installation.
    Run the following command:
    seedgeneratorutil myseed.dat abcdef
    NOTE: In the example, myseed.dat is a filename. You can give any file name you wish.
    The myseed.dat file is generated in the eappweb/bin directory.
    Edit eapps.cfg to include the following parameters under the SWE section:
    seedfile = < complete path for myseed.dat >
    Bounce the web server.
    (For Linux only) Copy libmod_swe.so from the eappweb/bin folder to the web/ohs/modules folder
    Thanks
    Kumar

    Wilson,
    Thanks for your reply.I have repeated the steps and regenerated the error messages.
    Browser
    Message:
    An error occurred while trying to process your request. This error indicates a problem with the configuration of this server and should be reported to the webmaster (along with any errors listed below). We apologize for the inconvenience
    Initialization error:
    Unable to get the seed from binary file.
    Log
    2021 2011-09-20 23:23:01 0000-00-00 00:00:00 +0530 00000000 001 003f 0001 09 ss110920_7068 7068 7852 E:\sba80\SWEApp\log\ss110920_7068.log 8.0.0.12 [20444] ENU
    ProcessPluginState     ProcessPluginStateError     1     000000024e781b9c:0     2011-09-20 23:23:01     7852: [SWSE] Unable to get the seed from binary file.
    Eapps.cfg
    [swe]
    Language = enu
    Log = errors
    LogDirectory = $(SWSERoot)\log
    ClientRootDir = $(SWSERoot)
    SessionMonitor = False
    AllowStats = true
    LogSegmentSize = 0
    LogMaxSegments = 0
    DisableNagle = False
    seedfile = E:\sba80\SWEApp\BIN\80012seed.dat
    Thanks
    Kumar

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

Maybe you are looking for