author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 32649 | jdk/src/java.base/share/classes/sun/security/ssl/AppOutputStream.java@2ee9017c7597 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
12428 | 2 |
* Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.io.OutputStream; |
|
29 |
import java.io.IOException; |
|
30904 | 30 |
import java.nio.ByteBuffer; |
2 | 31 |
|
32 |
/* |
|
30904 | 33 |
* OutputStream for application data as returned by SSLSocket.getOutputStream(). |
2 | 34 |
* |
35 |
* @author David Brownell |
|
36 |
*/ |
|
37 |
class AppOutputStream extends OutputStream { |
|
38 |
||
30904 | 39 |
private SSLSocketImpl socket; |
2 | 40 |
|
41 |
// One element array used to implement the write(byte) method |
|
42 |
private final byte[] oneByte = new byte[1]; |
|
43 |
||
44 |
AppOutputStream(SSLSocketImpl conn) { |
|
30904 | 45 |
this.socket = conn; |
2 | 46 |
} |
47 |
||
48 |
/** |
|
49 |
* Write the data out, NOW. |
|
50 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
12428
diff
changeset
|
51 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
52 |
public synchronized void write(byte[] b, int off, int len) |
2 | 53 |
throws IOException { |
2061 | 54 |
if (b == null) { |
55 |
throw new NullPointerException(); |
|
56 |
} else if (off < 0 || len < 0 || len > b.length - off) { |
|
57 |
throw new IndexOutOfBoundsException(); |
|
58 |
} else if (len == 0) { |
|
59 |
return; |
|
60 |
} |
|
61 |
||
2 | 62 |
// check if the Socket is invalid (error or closed) |
30904 | 63 |
socket.checkWrite(); |
2061 | 64 |
|
30904 | 65 |
// Delegate the writing to the underlying socket. |
2 | 66 |
try { |
30904 | 67 |
socket.writeRecord(b, off, len); |
68 |
socket.checkWrite(); |
|
2 | 69 |
} catch (Exception e) { |
70 |
// shutdown and rethrow (wrapped) exception as appropriate |
|
30904 | 71 |
socket.handleException(e); |
2 | 72 |
} |
73 |
} |
|
74 |
||
75 |
/** |
|
76 |
* Write one byte now. |
|
77 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
12428
diff
changeset
|
78 |
@Override |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30904
diff
changeset
|
79 |
public synchronized void write(int i) throws IOException { |
2 | 80 |
oneByte[0] = (byte)i; |
81 |
write(oneByte, 0, 1); |
|
82 |
} |
|
83 |
||
84 |
/* |
|
85 |
* Socket close is already synchronized, no need to block here. |
|
86 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
12428
diff
changeset
|
87 |
@Override |
2 | 88 |
public void close() throws IOException { |
30904 | 89 |
socket.close(); |
2 | 90 |
} |
91 |
||
92 |
// inherit no-op flush() |
|
93 |
} |