better handling of null streams

This commit is contained in:
iNPUTmice 2014-08-15 13:34:55 +02:00
parent 9c18d57e07
commit f7c747ef4b
3 changed files with 22 additions and 14 deletions

View File

@ -41,12 +41,18 @@ public class TagWriter {
public 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.plainOutputStream = out;
this.outputStream = new OutputStreamWriter(out); this.outputStream = new OutputStreamWriter(out);
} }
public OutputStream getOutputStream() { public OutputStream getOutputStream() throws IOException {
if (this.plainOutputStream==null) {
throw new IOException();
}
return this.plainOutputStream; return this.plainOutputStream;
} }

View File

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

View File

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