Jump to content
blech

need help with some code (Java & Py)

Recommended Posts

salut,

 

am urmatoarea bucata de cod Java pe care nu stiu daca o inteleg perfect si ca sa fie si mai rau am nevoie sa scriu ceva cu aceeasi functionalitate in Python:

"rs", "CEVA" si "ALTCEVA" sunt niste variabile care vin de mai sus din script....

      Inflater inflater = new Inflater();
      byte[] result = new byte[rs.getInt("CEVA")];
      inflater.setInput(rs.getBytes("ALTCEVA"));
      int length = inflater.inflate(result);
      System.out.println(new String(result, 0, length, "UTF-8"));
      System.out.println();
      System.out.println("-----");
      System.out.println();
      inflater.end();

aveti idee cum pot scrie ceva cu aceeasi functionalitate in Python?

exista vreo librarie in Pyton care face ce face acel Inflater in Java? (am cautat pe net si am vazut raspunsurile de pe stackoverflow dar probabil sunt prea prost sa le inteleg)

ma poate ajuta cineva cu un exemplu ceva in Python despre cum as putea realiza asta?

 

 

multumesc,

Link to comment
Share on other sites

UPDATE:

@Nytro

am gasit niste documentatie de la Peoplesoft si am gasit asta:

 

When PeopleSoft system receives a message, it ensures that the message is in UTF-8 format, then compresses the contents of the <data> element using the deflate algorithm prior to storage in the database. Because the compressed data is binary, it's base64-encoded so it can be embedded in an XML document.
The PeopleSoft subscribing node can accept XML data in either a compressed and encoded or an uncompressed and unencoded format. Note the following:
When compressed, the encoding attribute of the <data> element will contain information about how many bytes each routine produced.
The length attribute of the <data> element is the number of Unicode characters when uncompressed. Because PeopleTools 8 and above is Unicode, two bytes represent a character that was previously represented by a single byte. One way to derive the Unicode byte length is to multiply the character length of the inflated contents of the <data> tags by 2 to get the correct length that PeopleTools can use to inflate to Unicode.
For example, the following code describes data that contains 4126 Unicode characters when uncompressed. When deflated, the size of the data is 532 bytes and when base64 encoded, becomes 712 bytes in size:
<data encoding="base64(deflate)" encodedlength="712(532)" length="4126">

se pare ca mai intai trebuie sa fac un base64.decode pe stringul meu apoi ce rezulta este binar....si pe chestia aia trebuie sa fac zlib.decode... insa tot ma lovesc de probleme in sensul ca fac ceva gresit pentru ca primesc "zlib.error: Error -3 while decompressing data: incorrect header check".

 

am evoluat, macar nu mai sunt la aceeasi eroare.

care crede ca poate sa-mi dea o mana de ajutor il astept cu drag.

 

 

multumesc.

 

----------------------------------

multumesc Nytro, am incercat asa cum mi-am imaginat eu ca trebuie dar nu prea mi-a iesit.

adica am stringuri care functioneaza perfect cu programul scris in java insa cand incerc ceva de genul zlib.decompress(string, 0, buffsize) unde string este o variabila care contine string-ul meu primesc eroare "unknown compression method".

daca zlib este compatibil cu inflater-ul din java nu stiu si nici nu stiu ce default-uri au fiecare.

 

 

daca aveti vreo idee si daca ma puteti ajuta...va multumesc!

eu din pacate atat ma pricep ca nu sunt vreun expert in programare :))

Edited by blech
Link to comment
Share on other sites

acel rs este raspunsul, este o linie din baza de date cu coloane.
si acol vezi ca face rs.getInt("CEVA") unde CEVA este numele unei coloane. linia asta nu face altceva decat sa initializeze un binary array cu marimea bufferului egala cu valoarea expresiei  rs.getInt("CEVA").

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...