better handling of null streams

iNPUTmice created

Change summary

src/eu/siacs/conversations/xml/TagWriter.java       | 10 ++++++-
src/eu/siacs/conversations/xml/XmlReader.java       | 19 +++++++++++---
src/eu/siacs/conversations/xmpp/XmppConnection.java |  7 -----
3 files changed, 22 insertions(+), 14 deletions(-)

Detailed changes

src/eu/siacs/conversations/xml/TagWriter.java 🔗

@@ -41,12 +41,18 @@ public class TagWriter {
 	public TagWriter() {
 	}
 	
-	public void setOutputStream(OutputStream out) {
+	public void setOutputStream(OutputStream out) throws IOException {
+		if (out==null) {
+			throw new IOException();
+		}
 		this.plainOutputStream = out;
 		this.outputStream = new OutputStreamWriter(out);
 	}
 
-	public OutputStream getOutputStream() {
+	public OutputStream getOutputStream() throws IOException {
+		if (this.plainOutputStream==null) {
+			throw new IOException();
+		}
 		return this.plainOutputStream;
 	}
 

src/eu/siacs/conversations/xml/XmlReader.java 🔗

@@ -28,24 +28,33 @@ public class XmlReader {
 		this.wakeLock = wakeLock;
 	}
 	
-	public void setInputStream(InputStream inputStream) {
+	public void setInputStream(InputStream inputStream) throws IOException {
+		if (inputStream==null) {
+			throw new IOException();
+		}
 		this.is = inputStream;
 		try {
 			parser.setInput(new InputStreamReader(this.is));
 		} catch (XmlPullParserException e) {
-			Log.d(LOGTAG,"error setting input stream");
+			throw new IOException("error resetting parser");
 		}
 	}
 
-	public InputStream getInputStream() {
+	public InputStream getInputStream() throws IOException {
+		if (this.is==null) {
+			throw new IOException();
+		}
 		return is;
 	}
 
-	public void reset() {
+	public void reset() throws IOException {
+		if (this.is==null) {
+			throw new IOException();
+		}
 		try {
 			parser.setInput(new InputStreamReader(this.is));
 		} catch (XmlPullParserException e) {
-			Log.d(LOGTAG,"error resetting input stream");
+			throw new IOException("error resetting parser");
 		}
 	}
 	

src/eu/siacs/conversations/xmpp/XmppConnection.java 🔗

@@ -415,15 +415,8 @@ public class XmppConnection implements Runnable {
 			throws XmlPullParserException, IOException,
 			NoSuchAlgorithmException {
 		tagReader.readTag(); // read tag close
-
-		if (!tagWriter.isActive()) {
-			throw new IOException();
-		}
 		tagWriter.setOutputStream(new ZLibOutputStream(tagWriter
 				.getOutputStream()));
-		if (tagReader.getInputStream() == null) {
-			throw new IOException();
-		}
 		tagReader
 				.setInputStream(new ZLibInputStream(tagReader.getInputStream()));