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