title: BufferedWriter - Stream closed prematurely during program execution
body: <p>I am defining a buffered writer in a class I am developing, but having problems with it.</p>
  
  <p>In the class constructor I am defining:</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>This works and prints the text to my file. But when I try to use the same <code>rest_logger</code> in another one of my class methods:</p>
  
  <pre><code>    @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();
      }
      }
  </code></pre>
  
  <p>It gives me a stream closed exception! I should mention that I use this to close the stream:</p>
  
  <pre><code>    protected void finalize() throws Throwable {
      rest_logger.close();
  }
  </code></pre>