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 6757031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:35:52+00:00 2026-05-26T13:35:52+00:00

Is it bad style to keep the references to streams further down a filter

  • 0

Is it bad style to keep the references to streams “further down” a filter chain, and use those lower level streams again, or even to swap one type of stream for another? For example:

    OutputStream os = new FileOutputStream("file");
    PrintWriter pw = new PrintWriter(os);
    pw.print("print writer stream");
    pw.flush();
    pw = null;
    DataOutputStream dos = new DataOutputStream(os);
    dos.writeBytes("dos writer stream");
    dos.flush();
    dos = null;
    os.close();

If so, what are the alternatives if I need to use the functionality of both streams, e.g. if I want to write a few lines of text to a stream, followed by binary data, or vice versa?

  • 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-26T13:35:53+00:00Added an answer on May 26, 2026 at 1:35 pm

    This can be done in some cases, but it’s error-prone. You need to be careful about buffers and stuff like the stream headers of ObjectOutputStream.

    if I want to write a few lines of text to a stream, followed by binary
    data, or vice versa?

    For this, all you need to know is that you can convert text to binary data and back but always need to specify an encoding. However, it is also error-prone because people tend to use the API methods that use the platform default encoding, and of course you’re basically implementing a parser for a custom binary file format – lots of things can go wrong there.

    All in all, if you’re creating a file format, especially when mixing text and binary data, it’s best to use an existing framework like Google protocol buffers

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

Sidebar

Related Questions

Is it considered bad style to use the increment operator (++) on floats? It
How bad is it to use Location Manager to retrieve the location information when
I constantly hear how bad reflection is to use. While I generally avoid reflection
I have some C++ code written in C-style. For some reasons I can't use
The general question: Is it bad style if you create a form in rails
Is it considered as bad style to have a mixture of exact width types
I get a Error: Warning 25: bad style, all clauses in this pattern-matching are
Are both of the examples below OK, or is the second one bad style?
In short I have code like this. I know its bad style but have
Bad style notwithstanding, is it legal C to have a for loop with braces

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.