CharlesO
I’ve built and Elixir application that needs to read files produced by a Legacy Java platform.
Looking at the Java source shows clearly how the files are being constructed:
HashMap localHashMap = null;
List localList1 = null;
...
ByteArrayOutputStream localByteArrayOutputStream = null;
ObjectOutputStream localObjectOutputStream = null;
localByteArrayOutputStream = new ByteArrayOutputStream();
localObjectOutputStream = new ObjectOutputStream(localByteArrayOutputStream);
localObjectOutputStream.flush();
localHashMap = new HashMap();
localHashMap.put("SecretKey", someBytes);
localHashMap.put("EncryptedData", localList1);
localHashMap.put("IVSpec", someMoreBytes);
localObjectOutputStream.writeObject(localHashMap);
arrayOfByte3 = localByteArrayOutputStream.toByteArray();
At the end of the day it’s really just a Java HashMap with known string keys that’s being written to file…
I tried to grok this link below, but i feel there’s got to be a much simpler way to interop common data structures from other platforms
https://medium.com/@mr.anmolsehgal/java-hashmap-internal-implementation-21597e1efec3
Any suggestions please?
Samples:
http://paperlesssolutionsltd.com.ng/sample1.zip
http://paperlesssolutionsltd.com.ng/sample2.zip
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Hey @CharlesO, your file.io links do not work for me, I get a 404 for both.
To make sure I understand what you’re trying to do, you’re trying to read these files in Elixir and build maps out of them?
CharlesO
sorry, i’ve moved them to my personal server:
http://paperlesssolutionsltd.com.ng/sample1.zip
http://paperlesssolutionsltd.com.ng/sample2.zip
CharlesO
I want to read the content into elixir.
Looking @ the Java source, it’s clear how they are being constructed.
benwilson512
@CharlesO Unzipping those files turns into
sample1.zip.cpgz, it does not unzip.Sure, but it isn’t clear at all what the format of the files are. The java source has nothing to do with the structure of the file.
CharlesO
Oh, those zip files were encrypted.
Decrypting them is not the problem, it is reading the Java Hashmap that’s the issues.
The Java source shows how the file was constructed … if i can read back the parts, I can easily decrypt the files. I have the keys and all.
benwilson512
What does a java hashmap written to a file look like? What is its format?
tcoopman
Wouldn’t it be easier to read them back in a java application and save them as json or an other interop format?
There is no magical solution to read files from an internal java binary format. You could always try to understand and parse the java binary format but that sounds like something that will be a lot of work and possible error prone.
CharlesO
That’s my question exactly. See what the code is doing:
It reads the zipped file, encrypts it, and overwrites the same zipped file name with the encrypted content.
basically this: https://paperlesssolutionsltd.com.ng/RSASecImpl.java.txt
CharlesO
But once Java has written the bits to a physical - binary file, shouldn’t any programing language be able to readback the binary content?
tcoopman
Sure, every language can read it the physical bits, but how do you know what these bits represent? But I guess (because you didn’t specify in your original question) that you need to do something with the files in Elixir, so how do you know what the contents of the file mean?
The information on how the bits are stored are defined by the
ObjectOutputStreamfrom java. If you want to read them, you can, and you will have to parse them yourself. Basically implementing anObjectInputStreamin elixir.So, it would be a lot easier if instead of using the
ObjectOutputStreamyou wrote the files to ajsonorxmlformat in java. Then you don’t have to implement the binary parsing yourself.