jdk/src/java.base/share/classes/sun/security/ssl/AppInputStream.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 30904 ec0224270f90
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2061
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2061
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2061
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2061
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2061
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.security.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    29
import java.io.InputStream;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    30
import java.io.IOException;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    31
import java.nio.ByteBuffer;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    32
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    33
import javax.net.ssl.SSLProtocolException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * InputStream for application data as returned by SSLSocket.getInputStream().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    40
final class AppInputStream extends InputStream {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    41
    // the buffer size for each read of network data
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    42
    private static final int READ_BUFFER_SIZE = 4096;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // static dummy array we use to implement skip()
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    45
    private static final byte[] SKIP_ARRAY = new byte[256];
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    46
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    47
    // the related socket of the input stream
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    48
    private final SSLSocketImpl socket;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    50
    // the temporary buffer used to read network
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    51
    private ByteBuffer buffer;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    52
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    53
    // Is application data available in the stream?
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    54
    private boolean appDataIsAvailable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // One element array used to implement the single byte read() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private final byte[] oneByte = new byte[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    AppInputStream(SSLSocketImpl conn) {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    60
        this.buffer = ByteBuffer.allocate(READ_BUFFER_SIZE);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    61
        this.socket = conn;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    62
        this.appDataIsAvailable = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Return the minimum number of bytes that can be read without blocking.
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    67
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Currently not synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 5506
diff changeset
    70
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public int available() throws IOException {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    72
        if ((!appDataIsAvailable) || socket.checkEOF()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    75
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    76
        return buffer.remaining();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Read a single byte, returning -1 on non-fault EOF status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 5506
diff changeset
    82
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public synchronized int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int n = read(oneByte, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (n <= 0) { // EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    88
        return oneByte[0] & 0xFF;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    92
     * Reads up to {@code len} bytes of data from the input stream into an
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    93
     * array of bytes. An attempt is made to read as many as {@code len} bytes,
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    94
     * but a smaller number may be read. The number of bytes actually read
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    95
     * is returned as an integer.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
    96
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * If the layer above needs more data, it asks for more, so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * are responsible only for blocking to fill at most one buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * and returning "-1" on non-fault EOF status.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 5506
diff changeset
   101
    @Override
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   102
    public synchronized int read(byte[] b, int off, int len)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            throws IOException {
2061
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   104
        if (b == null) {
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   105
            throw new NullPointerException();
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   106
        } else if (off < 0 || len < 0 || len > b.length - off) {
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   107
            throw new IndexOutOfBoundsException();
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   108
        } else if (len == 0) {
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   109
            return 0;
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   110
        }
5a32855b67d4 6697270: Inputstream dosent behave correct
xuelei
parents: 2
diff changeset
   111
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   112
        if (socket.checkEOF()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   115
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   116
        // Read the available bytes at first.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   117
        int remains = available();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   118
        if (remains > 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   119
            int howmany = Math.min(remains, len);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   120
            buffer.get(b, off, howmany);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   121
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   122
            return howmany;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   123
        }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   124
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   125
        appDataIsAvailable = false;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   126
        int volume = 0;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
             * Read data if needed ... notice that the connection guarantees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
             * that handshake, alert, and change cipher spec data streams are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
             * handled as they arrive, so we never see them here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
             */
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   134
            while(volume == 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   135
                // Clear the buffer for a new record reading.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   136
                buffer.clear();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   137
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   138
                //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   139
                // grow the buffer if needed
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   140
                //
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   141
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   142
                // Read the header of a record into the buffer, and return
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   143
                // the packet size.
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   144
                int packetLen = socket.bytesInCompletePacket();
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   145
                if (packetLen < 0) {    // EOF
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   148
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   149
                // Is this packet bigger than SSL/TLS normally allows?
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   150
                if (packetLen > SSLRecord.maxLargeRecordSize) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   151
                    throw new SSLProtocolException(
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   152
                        "Illegal packet size: " + packetLen);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   153
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   154
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   155
                if (packetLen > buffer.remaining()) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   156
                    buffer = ByteBuffer.allocate(packetLen);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   157
                }
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   158
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   159
                volume = socket.readRecord(buffer);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   160
                if (volume < 0) {    // EOF
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   161
                    return -1;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   162
                } else if (volume > 0) {
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   163
                    appDataIsAvailable = true;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   164
                    break;
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   165
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   168
            int howmany = Math.min(len, volume);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   169
            buffer.get(b, off, howmany);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return howmany;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            // shutdown and rethrow (wrapped) exception as appropriate
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   173
            socket.handleException(e);
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   174
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            // dummy for compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Skip n bytes. This implementation is somewhat less efficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * than possible, but not badly so (redundant copy). We reuse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * the read() code to keep things simpler. Note that SKIP_ARRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * is static and may garbled by concurrent use, but we are not interested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * in the data anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 5506
diff changeset
   188
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public synchronized long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        long skipped = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        while (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            int len = (int)Math.min(n, SKIP_ARRAY.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            int r = read(SKIP_ARRAY, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            if (r <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            n -= r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            skipped += r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        return skipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Socket close is already synchronized, no need to block here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
14664
e71aa0962e70 8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents: 5506
diff changeset
   206
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public void close() throws IOException {
30904
ec0224270f90 8043758: Datagram Transport Layer Security (DTLS)
xuelei
parents: 25859
diff changeset
   208
        socket.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    // inherit default mark/reset behavior (throw Exceptions) from InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}