java proc / base64 string

Homepage Clovertech Forums Cloverleaf java proc / base64 string

  • Creator
    Topic
  • #118860
    Stewart
    Participant

    How do you setup/configure/use java on msgs?  I need to decode a base64 string to PDF and don’t know that this is possible w/ tcl.

Viewing 5 reply threads
  • Author
    Replies
    • #118861
      Tipu Razaq
      Participant

      With TCL you have to read/write the file as binary

      set infile [open “base64string” rb]
      set outfile [open “file.pdf” w+b]
      puts $outfile [binary decode base64 [read $infile]]

      close $infile
      close $outfile

      • This reply was modified 3 years, 5 months ago by Tipu Razaq.
      • This reply was modified 3 years, 5 months ago by Tipu Razaq.
    • #118864
      David Barr
      Participant

      This is possible with TCL, although to be honest this is one of my biggest struggles with Cloverleaf. Making sure the binary data isn’t corrupted as it’s put into a message with msgset, routed to another threads, possibly read back into TCL with msgget, sent out via an outbound thread seems difficult. You have to keep track of the message encoding settings on the threads that the data passes through. You have to keep track of (and maybe change) the encoding system that TCL uses (see the “encoding system” command in TCL).

      For a project that I was working on recently, I had some binary data passing through Cloverleaf that I tried to reencode into base64, and I was never able to figure out why the encoding wouldn’t work. The data would be garbage when it was decoded by the receiver. I ended up coming up with a workaround that didn’t require the encoding. My code was using the tcllib base64 module and not the TCL binary command, so maybe that was part of the problem.

      I’ve got some sample code that we run if you want to see how we use it.

    • #118865
      Jeff Dinsmore
      Participant

      I’ve used the base64 package in Tcl.

      package require base64

      base64::encode <your data to encode here>

      set decodedString [base64::decode <your base64 data here>]

      if you’re reading a PDF file to be encoded in a message, open the PDF file with binary translation.

      set pdfPath /tmp/jeffTestPdf.pdf
      set infile [open $pdfPath r]
      fconfigure $infile -translation binary
      set encodedPdfString [base64::encode [read $infile]]
      close $infile

      Jeff Dinsmore
      Chesapeake Regional Healthcare

    • #118869
      Stewart
      Participant

      I was able to create the file and based on the file contents it looks to have decoded the string.  However, the PDF is blank.  Thoughts?

    • #118871
      Jim Kosloskey
      Participant

      I would first make sure the supplied data is indeed encoded properly. One way I would do that is to locate a utility product that decodes base64 file and see if that produces a viewable PDF.

      Here is a link but a search on the Internet should produce a number of free utilities.

       

      https://sourceforge.net/directory/os:windows/?q=base64+decryption+utility

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #118872
      Stewart
      Participant

      I found the solution.  I had to use fconfigure.

      set codedString “<base64 string>”
      set outfile [open <filename>.pdf w+]
      fconfigure $outfile -encoding binary -translation binary
      puts $outfile [base64::decode $codedString]
      close $outfile

Viewing 5 reply threads
  • You must be logged in to reply to this topic.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10