Navigation Menu

Skip to content

Commit

Permalink
OutputStream should never throw NPE
Browse files Browse the repository at this point in the history
An outputstream should never throw NPE even if it been invoked after it closed.
  • Loading branch information
andywen-sap committed Jan 13, 2016
1 parent 9f0b051 commit 7851cf1
Showing 1 changed file with 5 additions and 0 deletions.
Expand Up @@ -26,6 +26,7 @@ public class PacketOutputStream extends OutputStream {
boolean useCompression;
private float increasing = 1.5f;
private OutputStream outputStream;
private volatile boolean closed = false;

/**
* Initialization with server outputStream.
Expand Down Expand Up @@ -61,6 +62,9 @@ public void setUseCompression(boolean useCompression) {
* @throws IOException if any error occur during data send to server
*/
public void startPacket(int seqNo, boolean checkPacketLength) throws IOException {
if (closed){
throw new IOException("Stream has already closed");
}
if (this.seqNo != -1) {
throw new IOException("Last stream not finished");
}
Expand Down Expand Up @@ -378,6 +382,7 @@ private void writeCompressedHeader(int packetLength, int initialLength, OutputSt
public void close() throws IOException {
outputStream.close();
buffer = null;
closed = true;
}

/**
Expand Down

0 comments on commit 7851cf1

Please sign in to comment.