mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-12 18:52:21 -05:00
Improve exception handling
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@48 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
d2e141e9f7
commit
aad97b08b4
@ -665,8 +665,9 @@ public class ExchangeSession {
|
||||
StringBuffer result = new StringBuffer();
|
||||
boolean mstnefDetected = false;
|
||||
String boundary = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
String line;
|
||||
line = reader.readLine();
|
||||
while (line != null && line.length() > 0) {
|
||||
@ -754,13 +755,23 @@ public class ExchangeSession {
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to preprocess headers " + e + " " + e.getMessage());
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void write(OutputStream os) throws IOException {
|
||||
// TODO : filter submessage headers in fullHeaders
|
||||
BufferedReader reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
// skip first line
|
||||
reader.readLine();
|
||||
MimeHeader mimeHeader = new MimeHeader();
|
||||
@ -781,6 +792,15 @@ public class ExchangeSession {
|
||||
writeMimeMessage(reader, os, mimeHeader);
|
||||
}
|
||||
os.flush();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeMimeMessage(BufferedReader reader, OutputStream os, MimeHeader mimeHeader) throws IOException {
|
||||
@ -852,8 +872,8 @@ public class ExchangeSession {
|
||||
}
|
||||
|
||||
protected void writeAttachment(OutputStream os, MimeHeader mimeHeader, Attachment attachment) throws IOException {
|
||||
OutputStream quotedOs = null;
|
||||
try {
|
||||
OutputStream quotedOs;
|
||||
try {
|
||||
// try another base64Encoder implementation
|
||||
if ("base64".equalsIgnoreCase(mimeHeader.contentTransferEncoding)) {
|
||||
@ -896,12 +916,23 @@ public class ExchangeSession {
|
||||
wdr.retrieveSessionInstance().executeMethod(method);
|
||||
|
||||
// encode attachment
|
||||
BufferedInputStream bis = new BufferedInputStream(method.getResponseBodyAsStream());
|
||||
BufferedInputStream bis = null;
|
||||
try {
|
||||
bis = new BufferedInputStream(method.getResponseBodyAsStream());
|
||||
byte[] buffer = new byte[4096];
|
||||
int count;
|
||||
while ((count = bis.read(buffer)) >= 0) {
|
||||
quotedOs.write(buffer, 0, count);
|
||||
}
|
||||
} finally {
|
||||
if (bis != null) {
|
||||
try {
|
||||
bis.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
bis.close();
|
||||
quotedOs.flush();
|
||||
os.write('\r');
|
||||
@ -910,6 +941,14 @@ public class ExchangeSession {
|
||||
|
||||
} catch (HttpException e) {
|
||||
throw new IOException(e + " " + e.getMessage());
|
||||
} finally {
|
||||
if (quotedOs != null) {
|
||||
try {
|
||||
quotedOs.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1009,7 +1048,9 @@ public class ExchangeSession {
|
||||
|
||||
public void printHeaders(OutputStream os) throws IOException {
|
||||
String line;
|
||||
BufferedReader reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new StringReader(fullHeaders));
|
||||
// skip first line
|
||||
reader.readLine();
|
||||
line = reader.readLine();
|
||||
@ -1019,6 +1060,15 @@ public class ExchangeSession {
|
||||
os.write('\n');
|
||||
line = reader.readLine();
|
||||
}
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user