2
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
28
import java.io.FileDescriptor;
29
import java.io.IOException;
31
import java.nio.ByteBuffer;
32
import java.nio.channels.*;
33
import java.nio.channels.spi.*;
37
* File-descriptor based I/O utilities that are shared by NIO classes.
42
private IOUtil() { } // No instantiation
44
static boolean randomBytes(byte[] someBytes)
48
if (false) throw new cli.System.Security.Cryptography.CryptographicException();
49
cli.System.Security.Cryptography.RNGCryptoServiceProvider csp = new cli.System.Security.Cryptography.RNGCryptoServiceProvider();
50
csp.GetBytes(someBytes);
53
catch (cli.System.Security.Cryptography.CryptographicException _)
59
static void configureBlocking(FileDescriptor fd, boolean blocking) throws IOException
61
fd.setSocketBlocking(blocking);
64
// this is a dummy method to allow us to use unmodified socket channel impls
65
static int fdVal(FileDescriptor fd)
70
static int read(FileDescriptor fd, ByteBuffer dst, long position,
71
NativeDispatcher nd, Object lock)
75
throw new IllegalArgumentException("Read-only buffer");
81
long prevpos = fd.getFilePointer();
85
return read(fd, dst, -1, nd, null);
96
byte[] buf = dst.array();
97
int len = nd.read(fd, buf, dst.arrayOffset() + dst.position(), dst.remaining());
100
dst.position(dst.position() + len);
106
byte[] buf = new byte[dst.remaining()];
107
int len = nd.read(fd, buf, 0, buf.length);
110
dst.put(buf, 0, len);
116
static long read(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length, NativeDispatcher nd)
119
return nd.read(fd, bufs, offset, length);
122
static int write(FileDescriptor fd, ByteBuffer src, long position,
123
NativeDispatcher nd, Object lock)
130
long prevpos = fd.getFilePointer();
134
return write(fd, src, -1, nd, null);
145
byte[] buf = src.array();
146
int len = nd.write(fd, buf, src.arrayOffset() + src.position(), src.remaining());
149
src.position(src.position() + len);
155
int pos = src.position();
156
byte[] buf = new byte[src.remaining()];
159
int len = nd.write(fd, buf, 0, buf.length);
162
src.position(pos + len);
168
static long write(FileDescriptor fd, ByteBuffer[] bufs, NativeDispatcher nd)
171
return nd.write(fd, bufs, 0, bufs.length);
174
static long write(FileDescriptor fd, ByteBuffer[] bufs, int offset, int length, NativeDispatcher nd)
177
return nd.write(fd, bufs, offset, length);