Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Development (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=8)
-   -   Trying to Understand JAVA Code Output (http://www.mirthcorp.com/community/forums/showthread.php?t=221741)

Teachmeh 11-19-2019 09:38 AM

Trying to Understand JAVA Code Output
 
I am fairly new to Mirth and recently setup a Mirth service on a VM I am running. I am trying to understand some of the JAVA code used in Mirth. I placed the following code on a destination transformer of a channel that was setup to pick up a file and move it to another folder. It is a PDF file if you need to know that. The move works but then I was trying to do some manipulation of the data through JAVA I was having some issue getting the data into a variable and working with it.

Code:

    var pdfString = new String;
    var tiff = getAttachments().get(0).getContent();
    pdfString = getAttachments().get(0);
    logger.info(pdfString)
    pdfString = FileUtil.decode(new java.lang.String(getAttachments().get(0).getContent()));
    logger.info(pdfString)
    pdfString = getAttachments();
    logger.info(pdfString)
 
        tiff = FileUtil.decode(new java.lang.String(tiff));
        logger.info(tiff);
        tiff = getAttachments().get(0).getContent();
        pdfString = getAttachments().get(0);
    logger.info(pdfString)
    pdfString = FileUtil.decode(new java.lang.String(getAttachments().get(0).getContent()));
    logger.info(pdfString)
    pdfString = getAttachments();
    logger.info(pdfString)
 
        tiff = FileUtil.decode(new java.lang.String(tiff));
        logger.info(tiff);

I didn't understand what was being displayed in the log output and it made it even more confusing when I did the exact same code twice as I got two different sets of output. Can someone maybe explain what I am seeing in the log(see below) and why when I run the same exact code twice I get different outputs in the log.

Quote:


INFO 2019-11-19 11:19:10,027 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: com.mirth.connect.server.userutil.Attachment@16bbb b0
INFO 2019-11-19 11:19:10,039 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [B@fb2834
INFO 2019-11-19 11:19:10,041 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [com.mirth.connect.server.userutil.Attachment@19b80 08]
INFO 2019-11-19 11:19:10,050 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [B@76f548
INFO 2019-11-19 11:19:10,052 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: com.mirth.connect.server.userutil.Attachment@12890 52
INFO 2019-11-19 11:19:10,058 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [B@faff84
INFO 2019-11-19 11:19:10,059 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [com.mirth.connect.server.userutil.Attachment@67691 9]
INFO 2019-11-19 11:19:10,060 [Destination Filter/Transformer JavaScript Task on Multiple Page PDF to TIFF (aba35fd3-a5f4-45c0-a79a-3efd8ccb96a0), Destination 1 (1) < pool-1-thread-34] transformer: [B@9adf9
Shouldn't the .getContent() be a text representation of the PDF document? I might be misunderstanding what that should be returning exactly.

agermano 12-03-2019 05:16 PM

This should actually be in the support forum, not development, but I'll try to answer a few of your questions.

getAttachments().get(0) returns an instance of com.mirth.connect.server.userutil.Attachment, which is documented in the User API.

getAttachments().get(0).getContent() returns a byte[], which is the binary representation of the base64 encoding of your pdf file.

FileUtil.decode(new java.lang.String(getAttachments() .get(0).getContent())) returns a byte[], which is the binary representation of your pdf file.

If you were to then convert that to a string, it would be like opening the pdf file in a text editor.

Here's a code template that might help you https://github.com/nextgenhealthcare...t%20From%20PDF


All times are GMT -8. The time now is 07:11 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation