| Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
|
| diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
|
| index b23842377659d99bb4239b945e3279ae7651541d..86ea4652512e623c8e06490a0dcbeb84f2986674 100644
|
| --- a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
|
| +++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetOutputStream.java
|
| @@ -14,6 +14,25 @@ import java.io.OutputStream;
|
| * extend in order to be used in {@link CronetHttpURLConnection}.
|
| */
|
| abstract class CronetOutputStream extends OutputStream {
|
| + private IOException mException;
|
| + private boolean mClosed;
|
| + private boolean mRequestCompleted;
|
| +
|
| + @Override
|
| + public void write(int oneByte) throws IOException {
|
| + checkNotClosed();
|
| + }
|
| +
|
| + @Override
|
| + public void write(byte[] buffer, int offset, int count) throws IOException {
|
| + checkNotClosed();
|
| + }
|
| +
|
| + @Override
|
| + public void close() throws IOException {
|
| + mClosed = true;
|
| + }
|
| +
|
| /**
|
| * Tells the underlying implementation that connection has been established.
|
| * Used in {@link CronetHttpURLConnection}.
|
| @@ -30,4 +49,25 @@ abstract class CronetOutputStream extends OutputStream {
|
| * Returns {@link UploadDataProvider} implementation.
|
| */
|
| abstract UploadDataProvider getUploadDataProvider();
|
| +
|
| + /**
|
| + * Signals that the request is done. If there is no error,
|
| + * {@code exception} is null. Used by {@link CronetHttpURLConnection}.
|
| + */
|
| + void setRequestCompleted(IOException exception) {
|
| + mException = exception;
|
| + mRequestCompleted = true;
|
| + }
|
| +
|
| + protected void checkNotClosed() throws IOException {
|
| + if (mRequestCompleted) {
|
| + if (mException != null) {
|
| + throw mException;
|
| + }
|
| + throw new IOException("Writing after request completed.");
|
| + }
|
| + if (mClosed) {
|
| + throw new IOException("Stream has been closed.");
|
| + }
|
| + }
|
| }
|
|
|