blech Posted March 17, 2017 Report Posted March 17, 2017 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, Quote
Nytro Posted March 17, 2017 Report Posted March 17, 2017 Inflater - "This class provides support for general purpose decompression using the popular ZLIB compression library" https://docs.python.org/2/library/zlib.html Quote
blech Posted March 20, 2017 Author Report Posted March 20, 2017 (edited) 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 March 20, 2017 by blech Quote
watsonAI Posted March 22, 2017 Report Posted March 22, 2017 Poti adauga si ce este acel "rs"(Vad ca din el se citesc datele)? (eventual unde e definit)?(Eventual da-mi un pm cu tot fisierul java, sa ma uit peste el). Quote
blech Posted March 22, 2017 Author Report Posted March 22, 2017 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"). Quote