Showing the changes to java/pkg/sun/rmi/transport/proxy/HttpSendOutputStream.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | package sun.rmi.transport.proxy; | ||
| 26 | |||
| 27 | import java.io.*; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * The HttpSendOutputStream class is used by the HttpSendSocket class as | ||
| 31 | * a layer on the top of the OutputStream it returns so that it can be | ||
| 32 | * notified of attempts to write to it. This allows the HttpSendSocket | ||
| 33 | * to know when it should construct a new message. | ||
| 34 | */ | ||
| 35 | class HttpSendOutputStream extends FilterOutputStream { | ||
| 36 | |||
| 37 | /** the HttpSendSocket object that is providing this stream */ | ||
| 38 | HttpSendSocket owner; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Create new filter on a given output stream. | ||
| 42 | * @param out the OutputStream to filter from | ||
| 43 | * @param owner the HttpSendSocket that is providing this stream | ||
| 44 | */ | ||
| 45 | public HttpSendOutputStream(OutputStream out, HttpSendSocket owner) | ||
| 46 | throws IOException | ||
| 47 | { | ||
| 48 | super(out); | ||
| 49 | |||
| 50 | this.owner = owner; | ||
| 51 | } | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Mark this stream as inactive for its owner socket, so the next time | ||
| 55 | * a write is attempted, the owner will be notified and a new underlying | ||
| 56 | * output stream obtained. | ||
| 57 | */ | ||
| 58 | public void deactivate() | ||
| 59 | { | ||
| 60 | out = null; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Write a byte of data to the stream. | ||
| 65 | */ | ||
| 66 | public void write(int b) throws IOException | ||
| 67 | { | ||
| 68 | if (out == null) | ||
| 69 | out = owner.writeNotify(); | ||
| 70 | out.write(b); | ||
| 71 | } | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Write a subarray of bytes. | ||
| 75 | * @param b the buffer from which the data is to be written | ||
| 76 | * @param off the start offset of the data | ||
| 77 | * @param len the number of bytes to be written | ||
| 78 | */ | ||
| 79 | public void write(byte b[], int off, int len) throws IOException | ||
| 80 | { | ||
| 81 | if (len == 0) | ||
| 82 | return; | ||
| 83 | if (out == null) | ||
| 84 | out = owner.writeNotify(); | ||
| 85 | out.write(b, off, len); | ||
| 86 | } | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Flush the stream. | ||
| 90 | */ | ||
| 91 | public void flush() throws IOException | ||
| 92 | { | ||
| 93 | if (out != null) | ||
| 94 | out.flush(); | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Close the stream. | ||
| 99 | */ | ||
| 100 | public void close() throws IOException | ||
| 101 | { | ||
| 102 | flush(); | ||
| 103 | owner.close(); | ||
| 104 | } | ||
| 105 | } | ||