web stats
Need to get the kb size of a file - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-11-2013, 09:57 AM
beefmon beefmon is offline
OBX.2 Kenobi
 
Join Date: Oct 2009
Posts: 62
beefmon is on a distinguished road
Default 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,
Reply With Quote
  #2  
Old 12-11-2013, 10:01 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 12-11-2013, 10:04 AM
beefmon beefmon is offline
OBX.2 Kenobi
 
Join Date: Oct 2009
Posts: 62
beefmon is on a distinguished road
Default

Who's better than you, narupley?


Thanks
Reply With Quote
  #4  
Old 09-11-2019, 06:25 AM
con con is offline
OBX.1 Kenobi
 
Join Date: Nov 2018
Location: Berlin
Posts: 34
con is on a distinguished road
Default

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?
Reply With Quote
  #5  
Old 09-11-2019, 07:32 PM
agermano agermano is online now
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

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'));
Reply With Quote
  #6  
Old 09-11-2019, 11:32 PM
con con is offline
OBX.1 Kenobi
 
Join Date: Nov 2018
Location: Berlin
Posts: 34
con is on a distinguished road
Default

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
Reply With Quote
  #7  
Old 09-12-2019, 04:13 AM
con con is offline
OBX.1 Kenobi
 
Join Date: Nov 2018
Location: Berlin
Posts: 34
con is on a distinguished road
Default

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
Reply With Quote
  #8  
Old 09-12-2019, 06:27 AM
con con is offline
OBX.1 Kenobi
 
Join Date: Nov 2018
Location: Berlin
Posts: 34
con is on a distinguished road
Default

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
Reply With Quote
  #9  
Old 09-12-2019, 10:59 AM
agermano agermano is online now
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

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.
Reply With Quote
  #10  
Old 09-13-2019, 03:22 AM
con con is offline
OBX.1 Kenobi
 
Join Date: Nov 2018
Location: Berlin
Posts: 34
con is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:34 PM.


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