1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.squareup.okhttp.internal; 18 19 import java.io.IOException; 20 import java.io.OutputStream; 21 22 /** 23 * An output stream for an HTTP request body. 24 * 25 * <p>Since a single socket's output stream may be used to write multiple HTTP 26 * requests to the same server, subclasses should not close the socket stream. 27 */ 28 public abstract class AbstractOutputStream extends OutputStream { 29 protected boolean closed; 30 31 @Override public final void write(int data) throws IOException { 32 write(new byte[] { (byte) data }); 33 } 34 35 protected final void checkNotClosed() throws IOException { 36 if (closed) { 37 throw new IOException("stream closed"); 38 } 39 } 40 41 /** Returns true if this stream was closed locally. */ 42 public boolean isClosed() { 43 return closed; 44 } 45 } 46