sun.misc.IoTrace Java Examples

The following examples show how to use sun.misc.IoTrace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocketOutputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes to the socket with appropriate locking of the
 * FileDescriptor.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private void socketWrite(byte b[], int off, int len) throws IOException {

    if (len <= 0 || off < 0 || off + len > b.length) {
        if (len == 0) {
            return;
        }
        throw new ArrayIndexOutOfBoundsException();
    }

    Object traceContext = IoTrace.socketWriteBegin();
    int bytesWritten = 0;
    FileDescriptor fd = impl.acquireFD();
    try {
        socketWrite0(fd, b, off, len);
        bytesWritten = len;
    } catch (SocketException se) {
        if (se instanceof sun.net.ConnectionResetException) {
            impl.setConnectionResetPending();
            se = new SocketException("Connection reset");
        }
        if (impl.isClosedOrPending()) {
            throw new SocketException("Socket closed");
        } else {
            throw se;
        }
    } finally {
        impl.releaseFD();
        IoTrace.socketWriteEnd(traceContext, impl.address, impl.port, bytesWritten);
    }
}
 
Example #2
Source File: FileInputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a byte of data from this input stream. This method blocks
 * if no input is yet available.
 *
 * @return     the next byte of data, or <code>-1</code> if the end of the
 *             file is reached.
 * @exception  IOException  if an I/O error occurs.
 */
public int read() throws IOException {
    Object traceContext = IoTrace.fileReadBegin(path);
    int b = 0;
    try {
        b = read0();
    } finally {
        IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 1);
    }
    return b;
}
 
Example #3
Source File: RandomAccessFile.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Reads a sub array as a sequence of bytes.
 * @param b the buffer into which the data is read.
 * @param off the start offset of the data.
 * @param len the number of bytes to read.
 * @exception IOException If an I/O error has occurred.
 */
private int readBytes(byte b[], int off, int len) throws IOException {
    Object traceContext = IoTrace.fileReadBegin(path);
    int bytesRead = 0;
    try {
        bytesRead = readBytes0(b, off, len);
    } finally {
        IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
    }
    return bytesRead;
}
 
Example #4
Source File: RandomAccessFile.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the specified byte to this file. The write starts at
 * the current file pointer.
 *
 * @param      b   the <code>byte</code> to be written.
 * @exception  IOException  if an I/O error occurs.
 */
public void write(int b) throws IOException {
    Object traceContext = IoTrace.fileWriteBegin(path);
    int bytesWritten = 0;
    try {
        write0(b);
        bytesWritten = 1;
    } finally {
        IoTrace.fileWriteEnd(traceContext, bytesWritten);
    }
}
 
Example #5
Source File: RandomAccessFile.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a sub array as a sequence of bytes.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private void writeBytes(byte b[], int off, int len) throws IOException {
    Object traceContext = IoTrace.fileWriteBegin(path);
    int bytesWritten = 0;
    try {
        writeBytes0(b, off, len);
        bytesWritten = len;
    } finally {
        IoTrace.fileWriteEnd(traceContext, bytesWritten);
    }
}
 
Example #6
Source File: FileOutputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes the specified byte to this file output stream. Implements
 * the <code>write</code> method of <code>OutputStream</code>.
 *
 * @param      b   the byte to be written.
 * @exception  IOException  if an I/O error occurs.
 */
public void write(int b) throws IOException {
    Object traceContext = IoTrace.fileWriteBegin(path);
    int bytesWritten = 0;
    try {
        write(b, append);
        bytesWritten = 1;
    } finally {
        IoTrace.fileWriteEnd(traceContext, bytesWritten);
    }
}
 
Example #7
Source File: FileOutputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes <code>b.length</code> bytes from the specified byte array
 * to this file output stream.
 *
 * @param      b   the data.
 * @exception  IOException  if an I/O error occurs.
 */
public void write(byte b[]) throws IOException {
    Object traceContext = IoTrace.fileWriteBegin(path);
    int bytesWritten = 0;
    try {
        writeBytes(b, 0, b.length, append);
        bytesWritten = b.length;
    } finally {
        IoTrace.fileWriteEnd(traceContext, bytesWritten);
    }
}
 
Example #8
Source File: FileOutputStream.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Writes <code>len</code> bytes from the specified byte array
 * starting at offset <code>off</code> to this file output stream.
 *
 * @param      b     the data.
 * @param      off   the start offset in the data.
 * @param      len   the number of bytes to write.
 * @exception  IOException  if an I/O error occurs.
 */
public void write(byte b[], int off, int len) throws IOException {
    Object traceContext = IoTrace.fileWriteBegin(path);
    int bytesWritten = 0;
    try {
        writeBytes(b, off, len, append);
        bytesWritten = len;
    } finally {
        IoTrace.fileWriteEnd(traceContext, bytesWritten);
    }
}
 
Example #9
Source File: SocketOutputStream.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Writes to the socket with appropriate locking of the
 * FileDescriptor.
 * @param b the data to be written
 * @param off the start offset in the data
 * @param len the number of bytes that are written
 * @exception IOException If an I/O error has occurred.
 */
private void socketWrite(byte b[], int off, int len) throws IOException {

    if (len <= 0 || off < 0 || off + len > b.length) {
        if (len == 0) {
            return;
        }
        throw new ArrayIndexOutOfBoundsException();
    }

    Object traceContext = IoTrace.socketWriteBegin();
    int bytesWritten = 0;
    FileDescriptor fd = impl.acquireFD();
    try {
        BlockGuard.getThreadPolicy().onNetwork();
        socketWrite0(fd, b, off, len);
        bytesWritten = len;
    } catch (SocketException se) {
        if (se instanceof sun.net.ConnectionResetException) {
            impl.setConnectionResetPending();
            se = new SocketException("Connection reset");
        }
        if (impl.isClosedOrPending()) {
            throw new SocketException("Socket closed");
        } else {
            throw se;
        }
    } finally {
        IoTrace.socketWriteEnd(traceContext, impl.address, impl.port, bytesWritten);
    }
}
 
Example #10
Source File: SocketAdaptor.java    From j2objc with Apache License 2.0 4 votes vote down vote up
protected int read(ByteBuffer bb)
    throws IOException
{
    synchronized (sc.blockingLock()) {
        if (!sc.isBlocking())
            throw new IllegalBlockingModeException();
        if (timeout == 0)
            return sc.read(bb);

        // Implement timeout with a selector
        SelectionKey sk = null;
        Selector sel = null;
        sc.configureBlocking(false);
        int n = 0;
        Object traceContext = IoTrace.socketReadBegin();
        try {
            if ((n = sc.read(bb)) != 0)
                return n;
            sel = Util.getTemporarySelector(sc);
            sk = sc.register(sel, SelectionKey.OP_READ);
            long to = timeout;
            for (;;) {
                if (!sc.isOpen())
                    throw new ClosedChannelException();
                long st = System.currentTimeMillis();
                int ns = sel.select(to);
                if (ns > 0 && sk.isReadable()) {
                    if ((n = sc.read(bb)) != 0)
                        return n;
                }
                sel.selectedKeys().remove(sk);
                to -= System.currentTimeMillis() - st;
                if (to <= 0)
                    throw new SocketTimeoutException();
            }
        } finally {
            IoTrace.socketReadEnd(traceContext, getInetAddress(),
                                  getPort(), timeout, n > 0 ? n : 0);
            if (sk != null)
                sk.cancel();
            if (sc.isOpen())
                sc.configureBlocking(true);
            if (sel != null)
                Util.releaseTemporarySelector(sel);
        }

    }
}
 
Example #11
Source File: FileInputStream.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Reads up to <code>b.length</code> bytes of data from this input
 * stream into an array of bytes. This method blocks until some input
 * is available.
 *
 * @param      b   the buffer into which the data is read.
 * @return     the total number of bytes read into the buffer, or
 *             <code>-1</code> if there is no more data because the end of
 *             the file has been reached.
 * @exception  IOException  if an I/O error occurs.
 */
public int read(byte b[]) throws IOException {
    Object traceContext = IoTrace.fileReadBegin(path);
    int bytesRead = 0;
    try {
        bytesRead = readBytes(b, 0, b.length);
    } finally {
        IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
    }
    return bytesRead;
}
 
Example #12
Source File: FileInputStream.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Reads up to <code>len</code> bytes of data from this input stream
 * into an array of bytes. If <code>len</code> is not zero, the method
 * blocks until some input is available; otherwise, no
 * bytes are read and <code>0</code> is returned.
 *
 * @param      b     the buffer into which the data is read.
 * @param      off   the start offset in the destination array <code>b</code>
 * @param      len   the maximum number of bytes read.
 * @return     the total number of bytes read into the buffer, or
 *             <code>-1</code> if there is no more data because the end of
 *             the file has been reached.
 * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 * <code>len</code> is negative, or <code>len</code> is greater than
 * <code>b.length - off</code>
 * @exception  IOException  if an I/O error occurs.
 */
public int read(byte b[], int off, int len) throws IOException {
    Object traceContext = IoTrace.fileReadBegin(path);
    int bytesRead = 0;
    try {
        bytesRead = readBytes(b, off, len);
    } finally {
        IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
    }
    return bytesRead;
}
 
Example #13
Source File: RandomAccessFile.java    From jdk-1.7-annotated with Apache License 2.0 3 votes vote down vote up
/**
 * Reads a byte of data from this file. The byte is returned as an
 * integer in the range 0 to 255 (<code>0x00-0x0ff</code>). This
 * method blocks if no input is yet available.
 * <p>
 * Although <code>RandomAccessFile</code> is not a subclass of
 * <code>InputStream</code>, this method behaves in exactly the same
 * way as the {@link InputStream#read()} method of
 * <code>InputStream</code>.
 *
 * @return     the next byte of data, or <code>-1</code> if the end of the
 *             file has been reached.
 * @exception  IOException  if an I/O error occurs. Not thrown if
 *                          end-of-file has been reached.
 */
public int read() throws IOException {
    Object traceContext = IoTrace.fileReadBegin(path);
    int b = 0;
    try {
        b = read0();
    } finally {
        IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 1);
    }
    return b;
}