当前位置: 首页>>代码示例>>Java>>正文


Java Platform类代码示例

本文整理汇总了Java中org.apache.harmony.luni.platform.Platform的典型用法代码示例。如果您正苦于以下问题:Java Platform类的具体用法?Java Platform怎么用?Java Platform使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Platform类属于org.apache.harmony.luni.platform包,在下文中一共展示了Platform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: available

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
@Override
protected synchronized int available() throws IOException {
    checkNotClosed();
    // we need to check if the input has been shutdown. If so
    // we should return that there is no data to be read
    if (shutdownInput) {
        return 0;
    }
    return Platform.getFileSystem().ioctlAvailable(fd);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:11,代码来源:PlainSocketImpl.java

示例2: ServerSocketChannelImpl

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
public ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
    super(sp);
    fd = new FileDescriptor();
    Platform.getNetworkSystem().createStreamSocket(fd,
            NetUtil.preferIPv4Stack());
    impl = new PlainServerSocketImpl(fd);
    socket = new ServerSocketAdapter(impl, this);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:9,代码来源:ServerSocketChannelImpl.java

示例3: test_map_LargePosition

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
/**
 * Tests map() method for the value of positions exceeding memory
 * page size and allocation granularity size.
 *
 * @tests java.nio.channels.FileChannel#map(MapMode,long,long)
 */
public void test_map_LargePosition() throws IOException {
    // Regression test for HARMONY-3085
    int[] sizes = {
        4096, // 4K size (normal page size for Linux & Windows)
        65536, // 64K size (alocation granularity size for Windows)
        Platform.getFileSystem().getAllocGranularity() // alloc granularity
    };
    final int CONTENT_LEN = 10;

    for (int i = 0; i < sizes.length; ++i) {
        // reset the file and the channel for the iterations
        // (for the first iteration it was done by setUp()
        if (i > 0 ) {
            fileOfReadOnlyFileChannel = File.createTempFile(
                    "File_of_readOnlyFileChannel", "tmp");
            fileOfReadOnlyFileChannel.deleteOnExit();
            readOnlyFileChannel = new FileInputStream(fileOfReadOnlyFileChannel)
                    .getChannel();
        }

        writeLargeDataToFile(fileOfReadOnlyFileChannel, sizes[i] + 2 * CONTENT_LEN);
        MappedByteBuffer mapped = readOnlyFileChannel.map(MapMode.READ_ONLY,
                sizes[i], CONTENT_LEN);
        assertEquals("Incorrectly mapped file channel for " + sizes[i]
                + " position (capacity)", CONTENT_LEN, mapped.capacity());
        assertEquals("Incorrectly mapped file channel for " + sizes[i]
                + " position (limit)", CONTENT_LEN, mapped.limit());
        assertEquals("Incorrectly mapped file channel for " + sizes[i]
                + " position (position)", 0, mapped.position());

        // map not change channel's position
        assertEquals(0, readOnlyFileChannel.position());

        // Close the file and the channel before the next iteration
        readOnlyFileChannel.close();
        fileOfReadOnlyFileChannel.delete();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:45,代码来源:FileChannelTest.java

示例4: getLocalAddress

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
/**
 * Gets the local IP address this socket is bound to.
 * 
 * @return the local IP address of this socket or {@code InetAddress.ANY} if
 *         the socket is unbound.
 */
public InetAddress getLocalAddress() {
    if (!isBound()) {
        return InetAddress.ANY;
    }
    return Platform.getNetworkSystem().getSocketLocalAddress(impl.fd,
            InetAddress.preferIPv6Addresses());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:14,代码来源:Socket.java

示例5: selectInternal

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
private int selectInternal(long timeout) throws IOException {
    closeCheck();
    synchronized (this) {
        synchronized (keys) {
            synchronized (selectedKeys) {
                doCancel();
                int[] readyChannels = null;
                boolean isBlock = (SELECT_NOW != timeout);
                if (keys.size() == 0) {
                    return 0;
                }
                prepareChannels();
                try {
                    if (isBlock) {
                        begin();
                    }
                    readyChannels = Platform.getNetworkSystem().select(readable, writable, timeout);
                } finally {
                    // clear results for next select
                    readableFDs.clear();
                    writableFDs.clear();                        
                    if (isBlock) {
                        end();
                    }
                }
                return processSelectResult(readyChannels);                    
            }
        }
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:31,代码来源:SelectorImpl.java

示例6: ServerSocketChannelImpl

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
public ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
    super(sp);
    status = SERVER_STATUS_OPEN;
    fd = new FileDescriptor();
    Platform.getNetworkSystem().createServerStreamSocket(fd,
            NetUtil.preferIPv4Stack());
    impl = SocketImplProvider.getServerSocketImpl(fd);
    socket = new ServerSocketAdapter(impl, this);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:10,代码来源:ServerSocketChannelImpl.java

示例7: getLocalAddress

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
/**
 * Returns an {@link InetAddress} instance representing the <i>local</i>
 * address this socket is bound to.
 * 
 * @return the local address that this socket has bound to
 */
public InetAddress getLocalAddress() {
    if (!isBound()) {
        return InetAddress.ANY;
    }
    return Platform.getNetworkSystem().getSocketLocalAddress(impl.fd,
            InetAddress.preferIPv6Addresses());
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:14,代码来源:Socket.java

示例8: cacheLocalAddress

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
private void cacheLocalAddress() {
    this.localAddress = Platform.getNetworkSystem().getSocketLocalAddress(impl.fd);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:Socket.java

示例9: selectInternal

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
private int selectInternal(long timeout) throws IOException {
    closeCheck();
    synchronized (this) {
        synchronized (unmodifiableKeys) {
            synchronized (selectedKeys) {
                doCancel();
                boolean isBlock = (SELECT_NOW != timeout);
                int readableKeysCount = 1; // first is always the wakeup channel
                int writableKeysCount = 0;
                synchronized (keysLock) {
                    for (SelectionKeyImpl key : mutableKeys) {
                        int ops = key.interestOpsNoCheck();
                        if ((ACCEPT_OR_READ & ops) != 0) {
                            readableKeysCount++;
                        }
                        if ((CONNECT_OR_WRITE & ops) != 0) {
                            writableKeysCount++;
                        }
                    }
                    prepareChannels(readableKeysCount, writableKeysCount);
                }
                boolean success;
                try {
                    if (isBlock) {
                        begin();
                    }
                    success = Platform.getNetworkSystem().select(
                            readableFDs, writableFDs, readableKeysCount, writableKeysCount, timeout, flags);
                } finally {
                    if (isBlock) {
                        end();
                    }
                }

                int selected = success ? processSelectResult() : 0;

                Arrays.fill(readableFDs, null);
                Arrays.fill(writableFDs, null);
                Arrays.fill(readyKeys, null);
                Arrays.fill(flags, 0);

                selected -= doCancel();

                return selected;
            }
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:49,代码来源:SelectorImpl.java

示例10: accept

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
@Override public SocketChannel accept() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (!isBound) {
        throw new NotYetBoundException();
    }

    // TODO: pass in the SelectorProvider used to create this ServerSocketChannelImpl?
    // Create an empty socket channel. This will be populated by ServerSocketAdapter.accept.
    SocketChannelImpl result = new SocketChannelImpl(SelectorProvider.provider(), false);
    Socket resultSocket = result.socket();

    try {
        begin();
        synchronized (acceptLock) {
            synchronized (blockingLock()) {
                boolean isBlocking = isBlocking();
                if (!isBlocking) {
                    int[] tryResult = new int[1];
                    boolean success = Platform.getNetworkSystem().select(
                            new FileDescriptor[] { fd },
                            new FileDescriptor[0], 1, 0, 0, tryResult);
                    if (!success || 0 == tryResult[0]) {
                        // no pending connections, returns immediately.
                        return null;
                    }
                }
                // do accept.
                do {
                    try {
                        socket.accept(resultSocket, result);
                        // select successfully, break out immediately.
                        break;
                    } catch (SocketTimeoutException e) {
                        // continue to accept if the channel is in blocking mode.
                    }
                } while (isBlocking);
            }
        }
    } finally {
        end(resultSocket.isConnected());
    }
    return result;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:46,代码来源:ServerSocketChannelImpl.java

示例11: selectInternal

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
private int selectInternal(long timeout) throws IOException {
    closeCheck();
    synchronized (this) {
        synchronized (unmodifiableKeys) {
            synchronized (selectedKeys) {
                doCancel();
                boolean isBlock = (SELECT_NOW != timeout);
                prepareChannels();
                boolean success;
                try {
                    if (isBlock) {
                        begin();
                    }
                    success = Platform.getNetworkSystem().select(
                            readableFDs, writableFDs, readableKeysCount, writableKeysCount, timeout, flags);
                } finally {
                    if (isBlock) {
                        end();
                    }
                }

                int selected = success ? processSelectResult() : 0;

                Arrays.fill(flags, 0);

                Set<SelectionKey> cancelledKeys = cancelledKeys();
                synchronized (cancelledKeys) {
                    if (cancelledKeys.size() > 0) {
                        for (SelectionKey currentkey : cancelledKeys) {
                            delKey((SelectionKeyImpl)currentkey);
                            mutableKeys.remove(currentkey);
                            deregister((AbstractSelectionKey) currentkey);
                            if (mutableSelectedKeys.remove(currentkey)) {
                                selected--;
                            }
                        }
                        cancelledKeys.clear();
                    }
                    limitCapacity();
                }

                return selected;
            }
        }
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:47,代码来源:SelectorImpl.java

示例12: accept

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
public SocketChannel accept() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (!isBound) {
        throw new NotYetBoundException();
    }

    SocketChannel sockChannel = new SocketChannelImpl(SelectorProvider.provider(), false);
    Socket socketGot = sockChannel.socket();

    try {
        begin();

        synchronized (acceptLock) {
                boolean isBlocking = isBlocking();
                if (!isBlocking) {
                    // for non blocking mode, use select to see whether
                    // there are any pending connections.
                    int[] tryResult = new int[1];
                    boolean success = Platform.getNetworkSystem().select(
                            new FileDescriptor[] { this.fd },
                            new FileDescriptor[0], 1, 0, 0, tryResult);
                    if (!success || 0 == tryResult[0]) {
                        // no pending connections, returns immediately.
                        return null;
                    }
                }
                // do accept.
                do {
                    try {
                        ((ServerSocketAdapter) socket).accept(socketGot,
                                (SocketChannelImpl) sockChannel);
                        // select successfully, break out immediately.
                        break;
                    } catch (SocketTimeoutException e) {
                        // continue to accept if the channel is in blocking
                        // mode.
                    }
                } while (isBlocking);
        }
    } finally {
        end(socketGot.isConnected());
    }
    return sockChannel;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:47,代码来源:ServerSocketChannelImpl.java

示例13: accept

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
public SocketChannel accept() throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (!isBound) {
        throw new NotYetBoundException();
    }

    SocketChannel sockChannel = SocketChannel.open();
    Socket socketGot = sockChannel.socket();

    try {
        begin();

        synchronized (acceptLock) {
            synchronized (blockingLock()) {
                boolean isBlocking = isBlocking();
                if (!isBlocking) {
                    // for non blocking mode, use select to see whether
                    // there are any pending connections.
                    int[] tryResult = Platform.getNetworkSystem().select(
                            new FileDescriptor[] { this.fd },
                            new FileDescriptor[0], 0);
                    if (0 == tryResult.length || 0 == tryResult[0]) {
                        // no pending connections, returns immediately.
                        return null;
                    }
                }
                // do accept.
                do {
                    try {
                        ((ServerSocketAdapter) socket).accept(socketGot,
                                (SocketChannelImpl) sockChannel);
                        // select successfully, break out immediately.
                        break;
                    } catch (SocketTimeoutException e) {
                        // continue to accept if the channel is in blocking
                        // mode.
                    }
                } while (isBlocking);
            }
        }
    } finally {
        end(socketGot.isConnected());
    }
    return sockChannel;
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:48,代码来源:ServerSocketChannelImpl.java

示例14: create

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
@Override
public void create() throws SocketException {
    Platform.getNetworkSystem().createMulticastSocket(fd, NetUtil.preferIPv4Stack());
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:5,代码来源:PlainMulticastSocketImpl.java

示例15: inheritedChannel

import org.apache.harmony.luni.platform.Platform; //导入依赖的package包/类
/**
 * Returns the channel inherited from the instance that created this
 * virtual machine.
 * 
 * @return the channel.
 * @throws IOException
 *             if an I/O error occurs.
 * @throws SecurityException
 *             if there is a security manager installed that does not permit
 *             the runtime permission labeled "selectorProvider".
 */
public Channel inheritedChannel() throws IOException {
    if (null == inheritedChannel) {
        inheritedChannel = Platform.getNetworkSystem().inheritedChannel();
    }
    return inheritedChannel;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:SelectorProvider.java


注:本文中的org.apache.harmony.luni.platform.Platform类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。