Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing text hashtables created in Java, in VB 1

Status
Not open for further replies.

jlgdeveloper

Programmer
Jun 15, 2002
105
US
Hi: Looking for direction on editing text files that are (I believe) binary hashtables.

Example of the file content:
======================================================

¬í sr java.util.Hashtable»%!Jä¸ F
loadFactorI thresholdxp?@ w 
t DATEt
2003_08_14t Z1_DCRsq ~ ?@ Gw _ (t ROW19COL1sr java.lang.Double€³ÂJ)kû D valuexr java.lang.Number†¬• ”à‹ xp@¶WÙ™™™št ROW19COL0sq ~  t ROW18COL1sq ~ @¶WÙ™™™št ROW18COL0sq ~ @ t ROW17COL1sq ~  t ROW17COL0sq ~  t ROW16COL1sq ~  t ROW16COL0sq ~  t ROW15COL1sq ~ @ú¡Îfffft ROW14COL1sq ~ @¶rèõ\t ROW15COL0sq ~ @Õ* t ROW14COL0sq ~  t ROW13COL1sq ~ @µ.Y™™™št ROW13COL0sq ~  t ROW12COL1sq ~ @P€ t ROW12COL0sq ~  t ROW11COL1sq ~  t ROW10COL1sq ~  t ROW11COL0sq ~  t ROW10COL0sq ~  t ROW9COL1sq ~  t ROW9COL0sq ~  t ROW8COL1sq ~ @V£33333t ROW8COL0sq ~ @P t ROW7COL1sq ~ @mffffft ROW7COL0sq ~ @cÀ t ROW6COL1sq ~ À¸Që…t ROW5COL1sq ~ À0G®záHt ROW6COL0sq ~ ?ð t ROW5COL0sq ~  t ROW4COL1sq ~ Àõ\(öt ROW4COL0sq ~ ?ð t ROW3COL1sq ~ Àfffffft ROW3COL0sq ~ @ t ROW2COL1sq ~ À ž¸Që…t ROW1COL1sq ~ @=p£×
=t ROW2COL0sq ~ @5 t ROW1COL0sq ~  t

=========================================================

Within vb, I would need to take the existing file, edit one or more items, and save it to a new location for re-processing. I understand the scripting.dictionary object allows handling of hashtables, but have not found any direction of physically loading and saving.

All comments appreciated. Being a VB programmer, not schooled in Java, your Java expertise may assist me here. Thanks.

Jonathan Galpin MCSD
because software should be easy to use
 
Whether or not there are any custom API's out there to do what you wish I am not sure, but from a standard API perspective, I don;t believe it is possible.

What you are seeing there (the posted file) is the compiled byte code of a class (I guess your class containing the HashTable). This is what the Java's virtual machine uses when it interprets a compiled program into machine code. Hence it is fairly specific to the Java VM, and hence is probably unreadable by VB ....
 
I appreciate that Sedj. The file begins as a text readable file (or this is created as a backup)example:
================================
{
"DATE" = "2003_06_15";
"Z1_DCR" = {
&quot;ROW19COL1&quot; = <&quot;2736.23&quot;>;
&quot;ROW19COL0&quot; = <&quot;0.0&quot;>;
&quot;ROW18COL1&quot; = <&quot;2736.23&quot;>;
&quot;ROW18COL0&quot; = <&quot;506.0&quot;>;
&quot;ROW17COL1&quot; = <&quot;0.0&quot;>;
&quot;ROW17COL0&quot; = <&quot;0.0&quot;>;
=================================
It is converted using a client java app, and the resulting binary object is ftp'd to a database server which uses it to update a database.

I need to modify it at the database.

Sun has a &quot;com bridge&quot; that supposedly allows use of the java object model to instantiate these classes in VB.

Any further thoughts?

Jonathan Galpin MCSD
because software should be easy to use
 
I'm not sure whether the file is class-file. Could it be a serialized file?
What is the extension of the file?
Can't you send the text readable file to the server, or edit the text readable file and convert the edited file?
If it is a class file, you can decompile it, change it and recompile.

If you are on a windows system you can see what's in the file via the &quot;debug&quot; command. See Thread269-630235 for this.
 
Hi Hologram

The extension is .txt.

To modify the text readable version, output by the same app for human consumption (see it at ) would be a snap, the problem is that the app that then processes it into the binary form needs to be initialized as per the client, and we have many different clients. That approach would not work when trying to update multiple sets of data from different clients.

The binary form ( ) has the exact same filename and extension. I have viewed it in the debug mode, and it is somewhat readable.

Could you take a look at the full files and comment? I appreciate your input to date.

Jonathan Galpin MCSD
because software should be easy to use
 
I think it is indeed a serialized file. You can deserialize it (in java) with ObjectInputStream (if you know how it was serialized).
There should be a utility called &quot;ObjectStreamWalker&quot; to view a serialized file (somewhere on the internet). I was not able to find it.

See also :
 
Yes, the more I study it, it seems that it is a java object representing a custom array, that has been serialized.

I wonder if by reading the file in binary format if I can locate an existing amount ie &quot;1560.25&quot; and insert my corrected number without disturbing the file?

There are plenty of articles on how to manipulate the file in binary form( I have to figure out how to spot the offending amount, and use the put statement to place the new amount in the file without modifying it.

I'll look for the objectstreamwalker, many thanks.



Jonathan Galpin MCSD
because software should be easy to use
 
To deserialize a hastable in java look at :


code snippet :
Code:
       try {
           FileInputStream fis = new FileInputStream(&quot;/home/mike/RateTable&quot;);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Hashtable newCollection = (Hashtable)ois.readObject();
            System.err.println(&quot;Loading RateTable read object&quot; + newCollection);
       }
       catch (Exception e) {
           System.err.println(e);
           e.printStackTrace();
       }
 
After some contemplation, I believe the human readble file is a &quot;toString&quot; representation of the java object.

I believe the solution is to write a java app that will:

deserialize it if it is serialized(however, I believe it is just the object),
instantiate it as a true java.util.hashtable object from the file,
modify the amounts,
re-write the object to disk.

Integration:
The app would start up every minute or so, see if any records exist in a db, and if so, execute the above, then shut down. The vb apps would write the changes needed to the db.

The apps that produce and then handle the file are from the apple webObjects family. In case the hashtable object is from that flavor of Java, I will start there.

One thought is that the serialized file could be multiple java hashtable objects, serialized into one file for transport via ftp.

Comments, opinions?

Jonathan Galpin MCSD
because software should be easy to use
 
You can check whether it is a class with the &quot;javap&quot; command, which gives a printout of the fields and methods f.ex. (I think you have to copy your *.txt file to a file with a &quot;class&quot; extension :
Code:
D:\java\projects\MyProject\classes>javap Interface
Compiled from &quot;Interface.java&quot;
public class Interface extends javax.swing.JApplet{
    java.lang.String[] birdname;
    javax.swing.JPanel jPanel1;
    javax.swing.JLabel jLabel1;
    javax.swing.JComboBox birdBox;
    javax.swing.JButton transformButton;
    javax.swing.JTextField text;
    javax.swing.JTextArea stackTrace;
    public Interface();
    public void init();
    public void Transform();
       throws java/io/IOException, java/io/FileNotFoundException, javax/xml/tran
sform/TransformerConfigurationException, javax/xml/transform/TransformerExceptio
n
    public static void main(java.lang.String[]);
}
================================
Also, if it is a &quot;class&quot; file, it should start with &quot;CA FE&quot;
and then probably &quot;BA BE&quot; (magical number)
================================
D:\java\projects\MYPROJ~1\classes>debug Inter.exe
-d
0CEE:0100 CA FE BA BE 00 00 00 2F-00 FC 0A 00 50 00 7A 07 ......./....P.z.
0CEE:0110 00 7B 08 00 7C 08 00 7D-08 00 7E 09 00 36 00 7F .{..|..}..~..6..
0CEE:0120 07 00 80 0A 00 07 00 81-09 00 36 00 82 07 00 83 ..........6.....
0CEE:0130 0A 00 0A 00 84 09 00 36-00 85 07 00 86 0A 00 0D .......6........
0CEE:0140 00 87 09 00 36 00 88 07-00 89 08 00 6B 0A 00 10 ....6.......k...
0CEE:0150 00 8A 09 00 36 00 8B 07-00 8C 0A 00 14 00 8D 09 ....6...........
0CEE:0160 00 36 00 8E 07 00 8F 0A-00 17 00 90 09 00 36 00 .6............6.
0CEE:0170 91 0A 00 36 00 92 07 00-93 0A 00 1B 00 94 0A 00 ...6............
-
================================
If not try to deserialize it with the code snippet from my earlier post.
================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top