mirror of https://github.com/etesync/android
* add null checks (should fix #117) * more detailed DAV exceptions for error handling * better logging (limited to 10 kB per log entry) to avoid memory problems * DavMultiget creates requests itself (instead of WebDavResource)pull/2/head
parent
ec4fedf04e
commit
6cfaad35b1
@ -0,0 +1,58 @@
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class LoggingInputStream extends FilterInputStream {
|
||||
private static final int MAX_LENGTH = 10*1024; // don't log more than 10 kB of data
|
||||
|
||||
String tag;
|
||||
|
||||
ByteArrayOutputStream log = new ByteArrayOutputStream(MAX_LENGTH);
|
||||
int logSize = 0;
|
||||
|
||||
public LoggingInputStream(String tag, InputStream proxy) {
|
||||
super(proxy);
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int b = super.read();
|
||||
if (logSize < MAX_LENGTH) {
|
||||
log.write(b);
|
||||
logSize++;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int byteOffset, int byteCount)
|
||||
throws IOException {
|
||||
int read = super.read(buffer, byteOffset, byteCount);
|
||||
int bytesToLog = read;
|
||||
if (bytesToLog + logSize > MAX_LENGTH)
|
||||
bytesToLog = MAX_LENGTH - logSize;
|
||||
if (bytesToLog > 0) {
|
||||
log.write(buffer, byteOffset, bytesToLog);
|
||||
logSize += bytesToLog;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
Log.d(tag, "Content: " + log.toString());
|
||||
super.close();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
public class DAVException extends HttpException {
|
||||
private static final long serialVersionUID = -2118919144443165706L;
|
||||
|
||||
final private static String prefix = "Invalid DAV response: ";
|
||||
|
||||
|
||||
public DAVException(String message) {
|
||||
super(prefix + message);
|
||||
}
|
||||
|
||||
public DAVException(String message, Throwable ex) {
|
||||
super(prefix + message, ex);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
public class DAVNoContentException extends DAVException {
|
||||
private static final long serialVersionUID = 6256645020350945477L;
|
||||
|
||||
private final static String message = "HTTP response entity (content) expected but not received";
|
||||
|
||||
public DAVNoContentException() {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
public class DAVNoMultiStatusException extends DAVException {
|
||||
private static final long serialVersionUID = -3600405724694229828L;
|
||||
|
||||
private final static String message = "207 Multi-Status expected but not received";
|
||||
|
||||
public DAVNoMultiStatusException() {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package at.bitfire.davdroid.webdav;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
public class InvalidDavResponseException extends HttpException {
|
||||
private static final long serialVersionUID = -2118919144443165706L;
|
||||
|
||||
public InvalidDavResponseException(String message) {
|
||||
super("Invalid DAV response: " + message);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue