What is best practice when working with (Zip)FileSystems – keep open or re-open as needed?

I’m working on a project that still uses JDK 8. The component I’m working on provides read-only access to local files for other components. Until now only resources from the default file system needed to be accessed. A new resource provider shall be added that provides access to class path resources, meaning files that are located in different jar files.

The overall use case is that different consumers require several configuration files initially and then maybe again at any time during runtime or never again. Atm it’s also not even hundreds of files. But I would like the look-up and access to be efficient, because at the end I cannot be sure know what a consumer does – if a file is read once by one/several consumer(s) or if a file will be read again and again by one/different consumer(s) because of bad practices.

Working with JAR files, nio.file.FileSystems and nio.file.Path is not what I usually do and I’ve looked up several things online. What I don’t understand is:
Can a (Zip)FileSystem remain open to ease further working with a Path instance and e.g. needed InputStreams? Or should it always be closed and “reloaded” when processing of a file is finally needed.

At the moment only ~3 JARs files will be accessed at all. But I would like good a solution that doesn’t need an justification like “Doesn’t matter, its just a small amount of open ZipFileSystems”.

I initially only a Path instance for a requested resource is created that than shall be used by the consuming components as needed – loading Properties, PropertiesResourceBundles, InputStreams. The Path is provided to the consumer using a wrapper like MyResource.
I don’t know if it relevant or TMI: I plan to retain a list of all MyResource to ease further access, because the look-up also involves different SPI services and handling duplicated resources where one ‘wins’ to be used depending on specific parameters and only the ‘winner’ will be provided to my consumers.

This is a rough draft of how a Path is created atm.

Path getResource(fileNameStr) {
  Path result = null;

  URI uri =  ClassLoader.getSystemResource(fileNameStr).toURI();

  Map<String, String> env = new HashMap<String, String>(); 
  env.put("create", "true");

  FileSystem zipfs = FileSystems.newFileSystem(uri);
  result = Paths.get(uri);

  // question: close zipfs or keep open?

  return result;
}

Depending on your answers to my question, it would be possible to add further support to MyResource if needed – getFileSystem, getInputStream, ... . Or an additional utility class could be provided that eases the access to the file represented by a Path instance, but I assume if that is needed, it would exist. Therefore I assume there must be an answer/process of working with (Zip)FileSystems I’m not understanding yet.

Thank you in advance for helping me to learn! 🙂

New contributor

CJOverflow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật