Announcement

Collapse
No announcement yet.

Need to get the kb size of a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need to get the kb size of a file

    I am working on a file reader interface and I would like to get the kb size of the file I am reading.

    I tried this:
    var contents = FileUtil.readBytes('F:\\fred.txt');
    var kb = contents.size()
    channelMap.put('kb', kb)



    and got this error:
    DETAILS: Java class "[B" has no public instance field or method named "size".


    What am I doing wrong?


    thanks
    Thanks,

  • #2
    The readBytes function returns a byte array, so just use .length to get the number of bytes.

    Code:
    var kb = contents.length / 1024;
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      Who's better than you, narupley?


      Thanks

      Comment


      • #4
        Is there any other way to get the file size?

        I think FileUtil.readBytes(filePath) increases the run times if I check for ~99MB Files or is my assumption wrong?
        Work for a NPO health care provider in Berlin
        • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

        Comment


        • #5
          This may not have been true in 2013, but today if you are actually using a File Reader to read the file, there is a sourceMap variable named fileSize with the size in bytes.

          If you want to get the size of a file using the path to the local filesystem without actually reading in the file you can do:

          Code:
          var bytes = java.nio.file.Files.size(java.nio.file.Paths.get('/path/to/file'));

          Comment


          • #6
            thank you! I'll try this
            Work for a NPO health care provider in Berlin
            • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

            Comment


            • #7
              got some with '/path/to/file'

              It works when I escape with ''\C:\\path\\to\\file'' but I get later the path as UNC- Path
              Work for a NPO health care provider in Berlin
              • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

              Comment


              • #8
                Okay, seems to work lokal, unfortunately not with my rights on the Path:

                Code:
                Wrapped java.nio.file.AccessDeniedException: \\server\folder\file.pdf
                any suggestions?
                Work for a NPO health care provider in Berlin
                • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

                Comment


                • #9
                  If you're trying to open a UNC path instead of a local file, it will only work when running mirth on Windows, and it will access the share as the user mirth is currently running as.

                  Comment


                  • #10
                    Well I get the Server Name of our MC with

                    Code:
                    logger.debug("Current User: " + java.lang.System.getProperty("user.name"));
                    It is running on a Windows Server 2012 R2. But I guess there is no way to allow access to an UNC as a Server Name or give credentials with the Java NIO Collection API?
                    Work for a NPO health care provider in Berlin
                    • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

                    Comment


                    • #11
                      Sorry for beeing a noob on this agermano: I've gave the OUR-MIRTH-SST$ a permission to read on the share. now it works

                      I think with SMB and jCIFS might be another way, but now your solution work for me so far
                      Work for a NPO health care provider in Berlin
                      • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

                      Comment


                      • #12
                        If your company has a Windows security/admin team, you might want to check with them to see the recommended way to set up a service account that needs to access both local and network resources. There are multiple ways to do it.

                        If your mirth service is set up to log in as Local System, it will access network resources using the domain Computer Account for that server, which you can actually use when setting up the permissions. This could cause an issue if you upgrade to a different server, or are forced to leave and rejoin the domain for some reason, as that will create a new account. It is also the equivalent to running as root on a unix/linux based system.

                        Some people will create a domain user account and have the service log in as that user instead of Local System.

                        Another option is a Managed Service Account, which is also defined at the domain level, but used like a local service account (you don't need to worry about passwords.)

                        Comment


                        • #13
                          Thank you, I'll consider this with our Admin Team!
                          Work for a NPO health care provider in Berlin
                          • Current Version of MC 3.4.1.770 with the onboard MySQL Database on a Windows Server 2012 R2

                          Comment

                          Working...
                          X