Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 987955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:34:00+00:00 2026-05-16T05:34:00+00:00

I’m currently refactoring a library for internal use in Java. The library receives an

  • 0

I’m currently refactoring a library for internal use in Java.

The library receives an XML document, and returns a Result data structure.
Given that:

  • There are two clients for this library, one has the XML document as an InputStream and the other has a file path as a String.
  • The class that the clients use is passing around inside the library before being actually processed

what it the best architecture for handling the file?

Currently, it is handled in the following way (unrelated details omitted, classes’ names changed):

public class ILuvUsers {

public Result getResult(String path) {
    return getResult(ElementsLoader.loadIntermediateType(path));
}

public Result getResult(InputStream stream) {
    return getResult(ElementsLoader.loadIntermediateType(stream));
}

private Result getResult(IntermediateType itype) {
    //... do stuff and return Result
}
}

public class ElementsLoader {
public static IntermediateType loadIntermediateType(final InputStream is) {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
    return doSomethingWithDocument(doc);
}

public static IntermediateType loadIntermediateType(final String path) {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(path);
    return doSomethingWithDocument(doc);
}
}

The way I need to create overloads in each class for InputStream and a String seems like a code smell to me.
What if the next day I’ll need to support using the ‘File’ type?
Optimally I would like to somehow automagically support every overload for the DocumentBuilder’s parse methods.

Since this is not really possible in Java and it all seems like a common enough case, what are the best practices for this problem? Have you seen any good solutions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:34:00+00:00Added an answer on May 16, 2026 at 5:34 am

    This is not really all that bad. The domain is limited and doesn’t grow quickly.

    However, you’ve spotted an issue where you need to find a “lowest common denominator” for inputs.

    That’s usually some kind of InputStream.

    Given a String, you want to open a Stream and use the Stream Loader.

    Given a Stream, you’re golden.

    Given a File, you’ll want to open a Stream and use the Stream Loader.

    This should cover just about all possible bases, since AFAIK you can make an InputStream out of almost anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.