java - Handling multiple file input mechanisms gracefully -
I am currently redefining a library for internal use in Java.
The library receives an XML document, and gives a result data structure. Given that:
- There are two clients for this library, one is the XML document in the form of an input sprame and the other is a file path in the form of a string.
- Class
What is the best architecture to handle the file?
Currently, it is handled in the following manner: (Names of unclassified sections have been changed):
Public category ILUUSERS {public results getResult ( String path) {get getResult (ElementsLoader.loadIntermediateType (path)); } Public results getResult (InputStream stream) {get getResult (ElementsLoader.loadIntermediateType (stream)); } Private results getResult {intermediate type iType} {// ... content and return results}} Public category elements loader {type public fixed intermediate type (initial input stream) {document doc = document builder. New Instruction () NewDocumentBuilder (). is); Returns Sotheby's Documents (Doctor); } Public Static Intermediate Type Load Interactive Type (Last String Path) {Document Doc = DocumentBeltfactine. New Instance () NewDocumentBuilder (). Pars (path); Returns Sotheby's Documents (Doctor); }}
The way in which I need to create overload in each class for inputstream and string, I think that the code is like odor what will happen if the next file 'file' Need to use type? Best of all, I would like to automatically support for every surcharge for document filter parse methods.
Since it is not really possible in Java and it all looks like a normal enough case, what are the best practices for this problem? Have you seen any good solution?
This is not really bad at all, the domain is limited and does not develop quickly.
However, you have seen an issue where you need to find the "least common denominator" for input.
This is usually something like InputStream
.
Looking at a string
, you want to open stream
and stream
loader.
Looking at a stream
, you are golden.
Viewing a file
, you would like to use a stream
and use the stream
loader.
This should cover almost all possible grounds, because AFAIK can almost exclude you from InputStream.
Comments
Post a Comment