pgoldstein 2002/08/08 23:01:45
Modified: src/java/org/apache/james/core
MimeMessageInputStreamSource.java
MimeMessageSource.java
Log:
More of the String=>StringBuffer changes, as well as some changes to ensure that
Streams are closed in the case of exception
Revision Changes Path
1.6 +21 -3
jakarta-james/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
Index: MimeMessageInputStreamSource.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/core/MimeMessageInputStreamSource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MimeMessageInputStreamSource.java 18 Apr 2002 14:49:14 -0000 1.5
+++ MimeMessageInputStreamSource.java 9 Aug 2002 06:01:44 -0000 1.6
@@ -32,21 +32,39 @@
public MimeMessageInputStreamSource(String key, InputStream in) {
//We want to immediately read this into a temporary file
//Create a temp file and channel the input stream into it
+ OutputStream fout = null;
try {
file = File.createTempFile(key, ".m64");
- OutputStream fout = new BufferedOutputStream(new
FileOutputStream(file));
+ fout = new BufferedOutputStream(new FileOutputStream(file));
int b = -1;
while ((b = in.read()) != -1) {
fout.write(b);
}
- fout.close();
- in.close();
+ fout.flush();
file.deleteOnExit();
sourceId = file.getCanonicalPath();
} catch (IOException ioe) {
throw new RuntimeException("Unable to retrieve the data: " +
ioe.getMessage());
+ } finally {
+ try {
+ if (fout != null) {
+ fout.close();
+ }
+ } catch (IOException ioe) {
+ // Ignored - logging unavailable to log this non-fatal error.
+ }
+
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException ioe) {
+ // Ignored - logging unavailable to log this non-fatal error.
+ }
}
+
+
}
/**
1.6 +17 -6
jakarta-james/src/java/org/apache/james/core/MimeMessageSource.java
Index: MimeMessageSource.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/core/MimeMessageSource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MimeMessageSource.java 25 May 2002 16:58:07 -0000 1.5
+++ MimeMessageSource.java 9 Aug 2002 06:01:44 -0000 1.6
@@ -36,13 +36,24 @@
*/
public long getMessageSize() throws IOException {
int size = 0;
- InputStream in = getInputStream();
- int read = 0;
- byte[] data = new byte[1024];
- while ((read = in.read(data)) > 0) {
- size += read;
+ InputStream in = null;
+ try {
+ in = getInputStream();
+ int read = 0;
+ byte[] data = new byte[1024];
+ while ((read = in.read(data)) > 0) {
+ size += read;
+ }
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (IOException ioe) {
+ // Exception ignored because logging is
+ // unavailable
+ }
}
- in.close();
return size;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>