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

RSP87
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
kpanic
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
nseaSeb
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
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 Top

JesseHerrick
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
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews