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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:54:54+00:00 2026-05-30T00:54:54+00:00

I am defining a buffered writer in a class I am developing, but having

  • 0

I am defining a buffered writer in a class I am developing, but having problems with it.

In the class constructor I am defining:

public class RestHandler  {
public static BufferedWriter rest_logger;

public RestHandler(parsedXMLConfigData _config, BufferedWriter writer) {
    rest_logger = writer;
    try {
        rest_logger.write("RestHandler instance finished init and ready to receive calls!" + "\n");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

This works and prints the text to my file. But when I try to use the same rest_logger in another one of my class methods:

    @POST
@Path("{subResources: [a-zA-Z0-9_/]+}")
public void postHandler
(
        @Context final UriInfo uriInfo,
        @PathParam("subResources") String subResources) {

    try {
        rest_logger.write("TEXT...");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }

It gives me a stream closed exception! I should mention that I use this to close the stream:

    protected void finalize() throws Throwable {
    rest_logger.close();
}
  • 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-30T00:54:56+00:00Added an answer on May 30, 2026 at 12:54 am

    There are several problems with your code:

    • the rest_logger variable should not be static
    • you shouldn’t initialize it to a new BufferedWriter just to discard it afterwards and reinitialize it with the writer argument (that you have no control on)
    • you shouldn’t ignore exceptions. If you don’t know what to do with them, make your methods throw IOException and let the caller decide what to do
    • you should not use finalizers
    • you should not close a writer that you have not created. Let the opener of the writer close it.

    Other than that, and since your code doesn’t make much sense, it’s hard to understand what the code is supposed to do.

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

Sidebar

Related Questions

When Defining a constructor in a class I initially had something like: public function
When defining a class as internal, do you define what would usually be public
I stuck at defining a static pointer inside one of my class which is
Defining custom components in Facelets is easy and quick but there's one thing I
When defining a method on a class in Python, it looks something like this:
I am having trouble defining the content-type of an element (phonenumber) whilst at the
When defining nested classes, is it possible to access the outer class' methods? I
In defining my Element class I get the following error: no matching function for
When defining a PHP class, which is preferred/best practice? Are there any key differences
When defining a global or static array in c++ its memory is not immediately

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.