3

I am wondering what the algorithm behind unpack() method in PHP is? Is there maybe an equivalent in Java which I could use?

What would be the best way to implement PHP unpack() method in Java?

Sascha
  • 31
  • 4
  • are you attempting to unpack data packed in php in java? is this a php -> java interop question? – Gareth Davis Aug 27 '10 at 10:20
  • PHP is open source. Check the algoritcm at php/ext/standard/pack.c No full implementation of that is know to me in java. – Imre L Aug 27 '10 at 10:52
  • @gid No, I am looking at php code which I try to implement in Java. Specifically this code: http://stackoverflow.com/questions/3299003/how-to-convert-openssh-public-key-file-format-to-pem/3303128#3303128 – Sascha Aug 27 '10 at 11:25
  • @Imre Good point, I will take a look at the source. – Sascha Aug 27 '10 at 11:25

2 Answers2

2

The nearest functionality is the DataInputStream/DataOutputStream pair.

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40
1

I believe the closest in java in Object Serialisation.

See java.io.ObjectOutputStream and java.io.ObjectInputStream

as always there is a library method to wrap this stuff up a couple of nice convenient methods

in commons-lang:

But this isn't going to help you with php to java interop.

Gareth Davis
  • 27,701
  • 12
  • 73
  • 106