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

  • SEARCH
  • Home
  • 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 7532441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:27:12+00:00 2026-05-30T05:27:12+00:00

I am designing the API for a client of a service that retrieves data

  • 0

I am designing the API for a client of a service that retrieves data as a stream of bytes.
What is the advantage of using

InputStream getData(String param1, String param2);

over

byte[] getData(String param1, String param2);

The method that returns the inputstream bothers me because

  1. now my code has to depend on external code to close the inputstream. I know that it is a best practice to close only those resources that you open so this seems wrong.
  2. The inputstream is not repeatable. Once the client of my code reads the stream the bytes are lost
  3. The stream in my implementation is actually over the network (socket). While I am using a connection pool and monitoring it to get rid of expired connections etc I feel it might be better to be able to close the resources I opened myself.

What’s the best way to design this? I even considered using

void writeData(String param, String param, OutputStream os);

but that makes the method name non-intuitive.

  • 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-30T05:27:17+00:00Added an answer on May 30, 2026 at 5:27 am

    I’d return something like Guava’s InputSupplier<InputStream>, which lets you request multiple distinct input streams.

    Additionally, Guava provides a number of methods which take an InputSupplier<InputStream>, open an input stream, perform some whole-stream operation, and then close it without making you remember to close the input stream or whatever.

    Even if you don’t want to use Guava directly, it’s a nice technique that lets the client program decide how it wants to deal with it.

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

Sidebar

Related Questions

I'm designing an API for a web service and I can't decide between using
I'm designing a web service that serves up JSON through a REST API. This
I am designing an API that is very comparable to Linq (it's a linq
I am designing a game engine that makes use of the DirectX 11 API,
We're in the early stages of designing a RESTful/resource-oriented web service API for a
I am designing an API in PHP using slim framework. These are working fine
I'm designing an API that interacts with MongoDB. Now the question is, if it
Well, I'm designing an online service that needs subscription in order to be used
I am designing a REST service that could be used by many types of
I am designing a WCF service which have some operations that i expose 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.