CharlesO

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

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

CharlesO OP

I want to read the content into elixir.
Looking @ the Java source, it’s clear how they are being constructed.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

@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

CharlesO OP

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

What does a java hashmap written to a file look like? What is its format?

tcoopman

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

CharlesO OP

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.

         byte[] arrayOfByte = getByteArray(this.compressedFile);
          arrayOfByte = SecurityService.performEnc(SecMgrConstants.ASYM_ALGORITHM, arrayOfByte);
          localFileOutputStream = new FileOutputStream(this.compressedFile);
          localFileOutputStream.write(arrayOfByte);
          localFileOutputStream.close();

basically this: https://paperlesssolutionsltd.com.ng/RSASecImpl.java.txt

CharlesO

CharlesO OP

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

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 ObjectOutputStream from java. If you want to read them, you can, and you will have to parse them yourself. Basically implementing an ObjectInputStream in elixir.

So, it would be a lot easier if instead of using the ObjectOutputStream you wrote the files to a json or xml format in java. Then you don’t have to implement the binary parsing yourself.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

mikehostetler
ReqLLM v1.28.0 has been released. Features: add StepFun chat and audio providers (#1087) by mikehostetler openai: honour image deta...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews