WriteTo closes the outputstream too early (java.io.IOException: Bad file 
descriptor error)
------------------------------------------------------------------------------------------

                 Key: MIME4J-12
                 URL: https://issues.apache.org/jira/browse/MIME4J-12
             Project: Mime4j
          Issue Type: Bug
    Affects Versions: 0.3
            Reporter: Stefano Bagnara
             Fix For: 0.3


On server-dev, GX GLIX reported this:
---------------------------
Hi all
I sincerely apologise for the delay, I have had other priorities and had to put 
this aside till now, after futher debugging I have come across the cause of the 
java.io.IOException: Bad file descriptor error.

In the file /org/mime4j/message/Header.java the following code is found
public void writeTo(OutputStream out) throws IOException {
  String charString = ((ContentTypeField) 
getField(Field.CONTENT_TYPE)).getCharset();
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, 
CharsetUtil.getCharset(charString)),8192);
  writer.write(toString()+ "\r\n");
  writer.flush();
  writer.close();
}

as you can see the output stream is closed here.
This is cause of the IOException as the stream is used later again for writing.
I tried commenting the writer.close(); call and it worked fine, however I dont 
know what the implications of this may be.
The case I am facing is a multipart message which calls the writeTo method below
public void writeTo(OutputStream out) throws IOException {
  getHeader().writeTo(out);
  Body body = getBody();
  if (body instanceof Multipart) {
    Multipart mp = (Multipart) body;
    mp.writeTo(out);
  } else {
    body.writeTo(out);
  }
}

when getHeader().writeTo(out); is called the stream is closed and when 
mp.writeTo(out); is called the exception is throw as the stream is 
closed.Regards

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to