On Friday 21 April 2006 18:37, Bob Hanson wrote: > Q1: How does one read a BINARY file in Java?
Much like reading an ASCII file: parse the syntax. The main difference is that the newlines are no longer a separator, and other byte sequences are replacing this functionality. For example, the binary CDX format uses a syntax in which the subsequent bytes form a word of a command. Each command type starts with a unique 'word', and each command type is a fixed length. Thus, parsing it comes down to: 1. get the first word, determine the command type 2. read the rest of the command and process it 3. back to 1. > Q2: How difficult would it be to set Jmol up to read a BINARY model file? Jmol works with streams, which is a prerequisite. From that, reading a binary format is not so difficult, except that the format itself, which might be difficult. Like with CIF, the syntax is OK, but the data structure is difficult. > For reference, the file looks something like the following. You can > see that what I'd really want to do is switch from line-mode to binary > mode if possible. Or, failing that, parse the line-based information > from a binary stream. With plain text tools we (often) use the BufferedLineReader, which helps us cut the file in easier to work with pieces. I did the same in CDK with the CDX parser (which I never had time for to finish): I made a helper class which read one by one the two bytes that formed a meaningful word. > ....[clip].... > property_flags: > MovieFrames > MovieType 1 > numericFormat 1 1 > Axes > steps1 steps 1 593 593 > Dependents > not_objcls Potential_Energy 4 1 3 kcal/mole 1 > -1 > calculation_history calc_energy 4 1 3 kcal/mole 1 > -1 > atom xyz_coordinates 4 3 3 angstrom 9 > 1 2 3 4 5 6 7 8 9 > StartFrames > 0pC0pC ü©™? ð|‡¿êŒ¨= > [EMAIL PROTECTED]@‘~;>[EMAIL PROTECTED]@[EMAIL PROTECTED] > > "pC"pC[*Ê·Û*±·SEµ§§™?®¡³¹ÖŽ > [EMAIL PROTECTED])[EMAIL PROTECTED];>[EMAIL PROTECTED]@oIÏ¿EFX½Å² >E@ > > ....[clip].... What's the syntax of the binary parts? It would be more useful to print binary data as hexidecimal, if the binary format is using that format. That is, make sure the 'characters' of the binary language are printed right. For example, the first spaces in the frame might be unprintable ASCII chars but likely very important in the binary language... using hexidecimal (or whatever bit language the format is using) is better then. Egon -- [EMAIL PROTECTED] Cologne University Bioinformatics Center (CUBIC) Blog: http://chem-bla-ics.blogspot.com/ GPG: 1024D/D6336BA6 ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Jmol-developers mailing list Jmol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-developers