Non-Blocking call to read the Keyboard

does anyone know how to make a JAVA program make a non-blocking call to read the keyboard? eg. write a program which generates prime number until a keyboard key is pressed.

if you use a gui you can use keyListener
Would work only if your gui elements have focus right now.

Similar Messages

  • Newbie Mac user:  Selecting block of text via the keyboard only?

    Hi,
    I'm switching over to a Mac from a PC and haven't been able to find an answer to this question. How do I select a block of text only by using the keyboard?
    As an example, on the PC from wherever the cursor is in a document, if I then hit Ctrl-Shift-end, the entire rest of the document from the cursor down is selected. Another similar task would be to select all of the text from the cursor to the end of the line, which on the PC can be done with Shift-end.
    Are there Mac equivalents?
    Thanks.
    Les
    MacBook Pro Mac OS X (10.4.10)
    MacBook Pro   Mac OS X (10.4.9)  

    COMMAND-SHIFT-end to select from the cursor to the end of the line. COMMAND-SHIFT-pagedown selects from cursor to end of document, use pageup to select entire document.
    Other alternatives:
    Press SHIFT and use the right arrow key to select characters. Use OPTION-SHIFT and right arrow to select words. COMMAND-right arrow key moves cursor to end of line and OPTION-right arrow moves cursor to next word.
    See also: Mac OS X Keyboard Shortcuts.
    In many instances wherever Windows uses CTRL in a shortcut the Mac uses COMMAND (Apple Key - ⌘)

  • NIO Non-Blocking Server not Reading from Key

    I have created a NIO non blocking server (below) and it will not pick up any input from the client.... My log doesnt even show that it enters the readKey() method, so it must be something before. Any help would be appreciated.
    Scott
    package jamb.server;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.ClosedChannelException;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.logging.Logger;
    import java.util.prefs.Preferences;
    import jamb.server.client.Client;
    public class Server {
            private Selector selector;
            private ServerSocketChannel serverChannel;
            private static Logger logger = Logger.getLogger("jamb.server");
            private static Preferences prefs =  Preferences.systemRoot().node("/jamb/server");
            public void init() {
                    logger.entering("jamb.server.Server", "init");
                    //Get a selector...
                    try {
                            selector = SelectorProvider.provider().openSelector();
                            //Open the SocketChannel and make it non-blocking...
                            serverChannel = ServerSocketChannel.open();
                         serverChannel.configureBlocking(false);
                            //Bind the server to the port....
                            int port = prefs.getInt("Port", 4000);
                            logger.config("Server configured on port " + port + " (default: 4000)");
                         InetSocketAddress isa = new InetSocketAddress(
                                    InetAddress.getLocalHost(), port);       
                         serverChannel.socket().bind(isa);
                    } catch (IOException ioe) {
                            logger.severe ("IOException during server initialization!");
                    logger.exiting("jamb.server.Server", "init");
            public void run() {
                    logger.entering("jamb.server.Server", "run");
                    int bufferSize = prefs.getInt("BufferSize", 8);
                    logger.config("Buffer size set to " + bufferSize + " (default: 8)");
                    SelectionKey acceptKey = null;
                    try {
                            acceptKey = serverChannel.register(
                                    selector, SelectionKey.OP_ACCEPT);
                    } catch (ClosedChannelException cce) {
                    try {
                            while (acceptKey.selector().select() > 0) {
                                    Set readyKeys = selector.selectedKeys();
                                    Iterator i = readyKeys.iterator();
                                    while (i.hasNext()) {
                                            //logger.finest("Processing keys...");
                                            //Get the key from the set and remove it
                                            SelectionKey currentKey = (SelectionKey) i.next();
                                            i.remove();
                                            if (currentKey.isAcceptable()) {
                                                    logger.finest("Accepting key...");
                                                    acceptKey(currentKey);
                                            } else if (currentKey.isReadable()) {
                                                    logger.finest("Reading key...");
                                                    readKey(currentKey, bufferSize);
                                            } else if (currentKey.isWritable()) {
                                                    //logger.finest("Writing key...");
                                                    writeKey(currentKey);
                    } catch (IOException ioe) {
                            logger.warning("IOException during key handling!");
                    logger.exiting("jamb.server.Server", "run");
            public void flushClient (Client client) {
                    try {
                            ByteBuffer buf = ByteBuffer.wrap( client.getOutputBuffer().toString().getBytes());
                            client.getChannel().write(buf);
                    } catch (IOException ioe) {
                            System.out.println ("Error writing to player");
                    client.setOutputBuffer(new StringBuffer());
            private void acceptKey (SelectionKey acceptKey) {
                    logger.entering("jamb.server.Server", "acceptKey");
                    //Retrieve a SocketChannel for the new client, and register a new selector with
                    //read/write interests, and then register
                    try {
                            SocketChannel channel =  ((ServerSocketChannel) acceptKey.channel()).accept();
                            channel.configureBlocking(false);
                            SelectionKey readKey = channel.register(
                                    selector, SelectionKey.OP_READ|SelectionKey.OP_WRITE  );
                            readKey.attach(new Client(this, channel));
                    } catch (IOException ioe) {
                            System.out.println ("Error accepting key");
                    logger.exiting("jamb.server.Server", "acceptKey");
            private void readKey (SelectionKey readKey, int bufSize) {
                    logger.entering("jamb.server.Server", "readKey");
                    Client client = (Client) readKey.attachment();
                    try {
                            ByteBuffer byteBuffer = ByteBuffer.allocate(bufSize);
                            int nbytes = client.getChannel().read( byteBuffer );
                            byteBuffer.flip();
                            Charset charset = Charset.forName( "us-ascii" );
                            CharsetDecoder decoder = charset.newDecoder();
                            CharBuffer charBuffer = decoder.decode(byteBuffer);
                            String text = charBuffer.toString();
                            client.getInputBuffer().append(text);
                            if ( text.indexOf( "\n" ) >= 0 )
                                    client.input();
                    } catch (IOException ioe) {
                            logger.warning("Unexpected quit...");
                            client.disconnect();
                    logger.exiting("jamb.server.Server", "readKey");
            private void writeKey (SelectionKey writeKey) {
                    //logger.entering("jamb.server.Server", "writeKey");
                    Client client = (Client) writeKey.attachment();
                    if (!client.isConnected()) {
                            client.connect();
                    //logger.exiting("jamb.server.Server", "writeKey");

    From my own expierence with the NIO (Under Windows XP/ jdk1.4.1_01); you can't seem to set READ and WRITE at the same time.
    The program flow I usually end up with for a echo server is:
    When the selector.isAcceptable(): accept a connection; register for READs
    In the read event; write the incoming characters to a buffer; register for a WRITE and add the buffer as an attachment.
    In the write event; write the data to the socket If all the data was written; register for a READ; otherwise register for another WRITE so that you can write the rest.
    Not sure if that the "proper" way; but it works well for me.
    - Chris

  • Synaptics touchpad blocked & delay when using the keyboard in Windows 8.1

    Sometimes (possibly when I use the keyboard and then quickly attempt to move the mouse arrow on the screen with the Synaptics touchpad), I am unable to move the cursor for a half of second-or-so.
    Sometimes I cannot tap to click, maybe, few seconds (it is very annoying).
    There are some Mouse and touchpad settings in Windows 8.1 ("To prevent the cursor from accidentally moving while you type, change the delay before clicks work") which I set to "No Delay (always on)" but it does not work, either.
     I also checked the following registry key:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre​ntVersion\PrecisionTouchPad
    but "AAPThreshold" is set correctly to 0 (No delay).
    But I still experiences problems and touchpad does not work while typing and sometimes also few moments after.
    Using HP Zbook 14, Win 8.1 x64, Synaptics driver 17.0.18.23.

    Hi,
    If you trying connect two Universal apps through Bluetooth, can you check if the
    Windows 8.1 Bluetooth RFComm sample runs fine on both the devices? I successfully tested the Windows 8.1 Bluetooth RFComm sample on Laptop (Windows 8.1) and Windows Phone 8.1 (paired).
    Make sure the service which you are trying to advertise/listen is supported by both the devices. 
    -Sagar

  • How to read the keyboard of a smart phone with labview mobile?

    The subject about says it all. I have an HTC phone with keyboard that is running WM 6.1. Using key events I can catch the left and righ soft keys and the left-right-up-down cursor movements, but it doesn't see the keyboard.
    Mike...
    PS: as a side note... given that Microsoft has signalled that it is pretty much abandoning the WM platform due tio lack of acceptance, I wonder what NI is going to do for mobile applications?
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

    Hello, Are you using the PDA Button VIs? Take a look at the Button Input VIs- Windows Mobile.lvproj example in the example finder and let me know if you have tried this. Or the Key Events - Windows Mobiel.lvproj example.
    National Instruments

  • Non Blocking Call with OCCI

    Hi Everyone
    I have searched through the whole OCCI documentation and could not find a way to make an asynchronous call to the database. you see the issue we have is that we need to cancel a call to the database if it does not return within the timeout value set. However, OCI does have the cancelling mechanism, but we have doned some testing and the Binding and Defining parameters call take to much of memory and and CPU. Once in a while it runs out of memory.
    Has any body come across this problem, and what solutions do you have i mind

    andyman35uk wrote:
    This doesn't seem to work under 10g. Both getOCIServer and getOCIServiceContext seem to return invalid handles.
    See Oracle Bug 3616743 - Oci Svcctx Handle Derived From Occi Connection Class Is Invalid
    The invalid handle was most likely the error handle, not the service context nor server handles as kmohan indicated above. The error handle needs to be allocated first.
    For reference:
    OCIError *errhp;
    OCIHandleAlloc((dvoid *)e, (dvoid **)&errhp, (ub4)OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0);
    OCISvcCtx s = ((Connection )c)->getOCIServiceContext();
    sword r = OCIBreak(s, errhp);
    // check r and errhp for errors before reusing them
    r = OCIReset(s, errhp);
    // check r and errhp for errors
    OCIHandleFree((dvoid *)errhp, (ub4)OCI_HTYPE_ERROR);

  • I want to read the keyboard

    Hi
    i want to know that what i typed in other application using keyboard.

    Your question has nothing to do with the topic of this forum.
    Try the New to Java forum.

  • Problem about Non-blocking socket's read and write

    my aim is:when I open a socketchannel,I can use this socket which can continue send and get messages!(for example:open a socket,send a loging message,server echo,if passed,use the same socket sending other message,get echo messages....
    Here is problem sample codes:
    void ConnectServer() throws IOException
    bf = ByteBuffer.allocateDirect(1024);
    InetSocketAddress ad = new InetSocketAddress(this.servername,this.serverport);
    this.clientsocketchannel = SocketChannel.open(); //set socketchannel
    this.clientsocketchannel.configureBlocking(false);
    this.clientsocketchannel.connect(ad);
    this.slt = Selector.open();
    this.clientsocketchannel.register (this.slt,SelectionKey.OP_CONNECT|SelectionKey.OP_READ|SelectionKey.OP_WRITE);
    //send data
    private void SendMessage(byte[] SendMessage)throws IOException
    while (this.slt.select() > 0)//sth wrong!when I test,slt.select(500)=0
    Set readykey = slt.selectedKeys();
    Iterator readyitor = readykey.iterator();
    while (readyitor.hasNext())
    SelectionKey skey = (SelectionKey) readyitor.next();
    readyitor.remove();
    if (skey.isWritable())
    SocketChannel keychannel = (SocketChannel) skey.channel();
    keychannel.write(ByteBuffer.wrap(this.sendmessage));
    }//end while
    }//end while
    //get data
    private void GetEchoMessage()throws IOException
    while(this.slt.select(500) > 0)//sth wrong!when I test,slt.select(500)=0
    Set readykey = slt.selectedKeys();
    Iterator readyitor = readykey.iterator();
    while (readyitor.hasNext())
    SelectionKey skey = (SelectionKey) readyitor.next();
    readyitor.remove();
    if (skey.isWritable())
    SocketChannel keychannel = (SocketChannel) skey.channel();
    keychannel.read(bf);
    public static void main(String[] arg)
    connectserver(..);
    SendMessage(...);
    GetEchoMessage();
    SendMessage(...);
    GetEchoMessage();

    private void ConnectServer() throws IOException
    � bf = ByteBuffer.allocateDirect(1024);
    �� InetSocketAddress ad = new InetSocketAddress(this.servername,this.serverport);
    �� this.clientsocketchannel = SocketChannel.open(); //set
    socketchannel
    �� this.clientsocketchannel.configureBlocking(false);
    �� this.clientsocketchannel.connect(ad);
    �� this.slt = Selector.open(); � this.clientsocketchannel.registerthis.slt,SelectionKey.OP_CONNECT|SelectionKey.OP_READ|SelectionKey.OP_WRITE);
    <b>
    //send data</b>
    private void SendMessage(byte[] SendMessage)throws IOException
    � while (this.slt.select() > 0)//<font color="#FF0000"><i>wrong,when test,this.slt.select(500)=0,why??</i></font>
    �{
    ��� Set readykey = slt.selectedKeys();
    ��� Iterator readyitor = readykey.iterator();
    ��� while (readyitor.hasNext())
    ��� {
    ������ SelectionKey skey = (SelectionKey) readyitor.next();
    ������ readyitor.remove();
    ������ if (skey.isWritable())
    ������ {
    �������� SocketChannel keychannel = (SocketChannel) skey.channel();
    �������� keychannel.write(ByteBuffer.wrap(this.sendmessage));
    ������ }
    ��� }//end while
    � }//end while�
    <b>
    //get data</b>
    private void GetEchoMessage()throws IOException
    � while(this.slt.select(500) > 0)<font color="#FF0000"><i>//wrong,when
    test,this.slt.select(500)=0</i></font>
    � {
    ��� Set readykey = slt.selectedKeys();
    ��� Iterator readyitor = readykey.iterator();
    ��� while (readyitor.hasNext())
    ��� {
    ����� SelectionKey skey = (SelectionKey) readyitor.next();
    ����� readyitor.remove();
    ����� if (skey.isWritable())
    ����� {
    ������� SocketChannel keychannel = (SocketChannel) skey.channel();
    ������� keychannel.read(bf);
    ����� }
    ��� }
    � }
    public static void main(String[] arg)
    � ......
    � connectserver(..);
    � SendMessage(...);
    � GetEchoMessage();
    � .......
    � SendMessage(...);
    � GetEchoMessage();
    � .......

  • Non blocking stored proc call

    HI
    I have written a c application using OCI which can call stored proc. but that is using blocking call. Is it possible to call stored proc in non blocking mode? So that I can receive output in call back function. Actually stored proc take much time to execute can I associate some Subscription callback-function with my stored proc call. Any idea?
    Thanks
    Kamran

    If you want to do non-blocking calls in OCI, you just need to set the server handle (svrhp below) attribute:
    sb2 polling=1;
    OCIAttrSet((dvoid *)svrhp,
    (ub4)OCI_HTYPE_SERVER,
    (dvoid *)&polling,
    (ub4)0,
    (ub4)OCI_ATTR_NONBLOCKING_MODE,
    (OCIError *) errhp);
    And then you call you OCIExecute() as you would in blocking mode. The difference is that instead of blocking until the call is done on the server, it always returns immediately. So instead of calling it just once per statement and checking the return code, you must keep calling OCIExecute() until it does not equal OCI_STILL_EXECUTING. When the proc is done, the final call to OCIExecute() will then be OCI_SUCCESS, OCI_ERROR, whatever happened.

  • Since upgrading to 4.3.3 my iphone 3gs does not ring when receiving a call and the keyboard clicks have gone.

    I have upgraded to 4.3.3 and now the phone does not ring when receiving a call and also the keyboard clicks have disappeared.  Does anyone know the solution to this problem please.?  Thanks

    Many thanks - switch is now on and it now operates corrrectly.

  • Both blocking and non-blocking io

    I'm wondering if this scenario is possible with the new nio classes:
    I have a caching server. Clients connect to the server and occasionally send requests for objects. I'd like to use the nio non-blocking APIs to detect that there is a read pending on a socket. However, once I detect this, I'd like to go into a blocking loop to process the request. After this done, I'd like to go back into non-blocking mode and wait for another request.
    It seems like this should be possible but the (woefully lacking) documentation isn't clear. Neither is the source code, apparently.
    I've got a test case working but I was hoping someone could validate for me that this is support behavior. It's done by waiting for the isReadable() key then calling socket.keyFor(selector).cancel(); and then socket.configureBlocking(true); The reads are then done in blocking mode until the request is done and then the socket is registered with the selector again.
    Thanks for any help on this.

    I have to ask why you would want to mix blocking and non-blocking I/O.
    The only reason you would (IMHO) want to use non-blocking I/O is in a highly concurrent system, to increase the maximum load a system can handle.
    The main reason you would want to use blocking I/O rather than non-blocking I/O would be to minimise the latency for a single request.
    Unfortunately, the two don't seem to mix together very well... by switching a thread to blocking, you decrease the latency for a single request, but increase latency for the other requests due to reduced resources available. Similarly, by switching to blocking, you are requiring a dedicated thread for that request, so limiting the number of concurrent requests that can be serviced.
    That is, it seems to me that using both blocking and non-blocking I/O introduces the weaknesses of both into the system, without gaining much of the benefits of either.
    The above aside, the method you gave looks like it would work as you expect, depending on what you are doing with thread creation/delegation. Did your test case work as expected?

  • Chaining WritableByteChannels and non-blocking I/O?

    Hello all,
    Suppose I want to implement a data transformation algorithm that works in chunks of say 4 bytes.
    The algorithm would hook into existing I/O paradigms for writing and reading data.
    Ignoring the transformation algorithm for now (it is actually irrelevant for my question), let's just I need to buffer data in 4-byte chunks.
    Since I want to make as little assumptions as possible about the decorated channel, BufferingWritableByteChannel needs to work channels in blocking and in non-blocking mode.
    When the decorated channel is in non-blocking mode, BuffereingWritableByteChannel may behave as in non-blocking mode itself, which is fine by me.
    However the problem is with the residual bytes: they do not get written until the close() method is called.
    I have implemented the close() method to be blocking (the while loop with the ugly yield() calls), so even when the decorated channel is in non-blocking mode everything will get written properly.
    However, writing potentially blocking calls (busy loops) in close() methods seems like a bad idea...
    So the question is:
    Is there a better way of doing this?
    Can I avoid having to write busy loops?
    package nio;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    import static nio.ChannelUtils.*;
    public class BufferingWritableByteChannel implements WritableByteChannel {
      private final WritableByteChannel decoratedChannel;
      private final ByteBuffer buffer = ByteBuffer.allocate(4);
      private boolean buffering = true;
      public BufferingWritableByteChannel(WritableByteChannel decoratedChannel) {
        this.decoratedChannel = decoratedChannel;
      public synchronized void close() throws IOException {
        if (buffering) {
          buffer.flip();
        writeBlockingly(decoratedChannel, buffer);
        buffer.clear();
        decoratedChannel.close();
      public synchronized boolean isOpen() {
        return decoratedChannel.isOpen();
      public synchronized int write(ByteBuffer input) throws IOException {
        int bytesWritten = 0;
        if (!buffering) {
          decoratedChannel.write(buffer);
          if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
            return bytesWritten;
          buffer.clear();
          buffering = true;
        while (input.hasRemaining()) {
          bytesWritten += putAsMuchAsPossible(input, buffer);
          if (!buffer.hasRemaining()) {
            buffer.flip();
            decoratedChannel.write(buffer);
            if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
              buffering = false;
              return bytesWritten;
            buffer.clear();
        return bytesWritten;
    package nio;
    import java.io.IOException;
    import java.nio.BufferOverflowException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    public class ChannelUtils {
      private ChannelUtils() {
       * Blockingly writes data to a channel, even if the channel is in non-blocking mode.
      public static final int writeBlockingly(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
        int bytesWritten = 0;
        boolean yield = false;
        while (buffer.hasRemaining()) {
          bytesWritten += channel.write(buffer);
          if (yield)
            Thread.yield();
          else
            yield = true;
        return bytesWritten;
       * Puts as much bytes as possible from an input buffer into an output buffer, avoiding {@link BufferOverflowException}.
      public static final int putAsMuchAsPossible(ByteBuffer input, ByteBuffer output) {
        int bytesWritten = Math.min(input.remaining(), output.remaining());
        ByteBuffer inputSlice = input.slice();
        inputSlice.limit(inputSlice.position() + bytesWritten);
        output.put(inputSlice);
        input.position(input.position() + bytesWritten);
        return bytesWritten;
    }

    Hello all,
    Suppose I want to implement a data transformation algorithm that works in chunks of say 4 bytes.
    The algorithm would hook into existing I/O paradigms for writing and reading data.
    Ignoring the transformation algorithm for now (it is actually irrelevant for my question), let's just I need to buffer data in 4-byte chunks.
    Since I want to make as little assumptions as possible about the decorated channel, BufferingWritableByteChannel needs to work channels in blocking and in non-blocking mode.
    When the decorated channel is in non-blocking mode, BuffereingWritableByteChannel may behave as in non-blocking mode itself, which is fine by me.
    However the problem is with the residual bytes: they do not get written until the close() method is called.
    I have implemented the close() method to be blocking (the while loop with the ugly yield() calls), so even when the decorated channel is in non-blocking mode everything will get written properly.
    However, writing potentially blocking calls (busy loops) in close() methods seems like a bad idea...
    So the question is:
    Is there a better way of doing this?
    Can I avoid having to write busy loops?
    package nio;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    import static nio.ChannelUtils.*;
    public class BufferingWritableByteChannel implements WritableByteChannel {
      private final WritableByteChannel decoratedChannel;
      private final ByteBuffer buffer = ByteBuffer.allocate(4);
      private boolean buffering = true;
      public BufferingWritableByteChannel(WritableByteChannel decoratedChannel) {
        this.decoratedChannel = decoratedChannel;
      public synchronized void close() throws IOException {
        if (buffering) {
          buffer.flip();
        writeBlockingly(decoratedChannel, buffer);
        buffer.clear();
        decoratedChannel.close();
      public synchronized boolean isOpen() {
        return decoratedChannel.isOpen();
      public synchronized int write(ByteBuffer input) throws IOException {
        int bytesWritten = 0;
        if (!buffering) {
          decoratedChannel.write(buffer);
          if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
            return bytesWritten;
          buffer.clear();
          buffering = true;
        while (input.hasRemaining()) {
          bytesWritten += putAsMuchAsPossible(input, buffer);
          if (!buffer.hasRemaining()) {
            buffer.flip();
            decoratedChannel.write(buffer);
            if (buffer.hasRemaining()) { // May happen when decorated channel in non-blocking mode
              buffering = false;
              return bytesWritten;
            buffer.clear();
        return bytesWritten;
    package nio;
    import java.io.IOException;
    import java.nio.BufferOverflowException;
    import java.nio.ByteBuffer;
    import java.nio.channels.WritableByteChannel;
    public class ChannelUtils {
      private ChannelUtils() {
       * Blockingly writes data to a channel, even if the channel is in non-blocking mode.
      public static final int writeBlockingly(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
        int bytesWritten = 0;
        boolean yield = false;
        while (buffer.hasRemaining()) {
          bytesWritten += channel.write(buffer);
          if (yield)
            Thread.yield();
          else
            yield = true;
        return bytesWritten;
       * Puts as much bytes as possible from an input buffer into an output buffer, avoiding {@link BufferOverflowException}.
      public static final int putAsMuchAsPossible(ByteBuffer input, ByteBuffer output) {
        int bytesWritten = Math.min(input.remaining(), output.remaining());
        ByteBuffer inputSlice = input.slice();
        inputSlice.limit(inputSlice.position() + bytesWritten);
        output.put(inputSlice);
        input.position(input.position() + bytesWritten);
        return bytesWritten;
    }

  • Easy way to non-blocked sockets

    Use JSSE and NIO for a quick way to implement non-blocking communications
    October 22, 2003
    Although SSL blocking operations -- in which the socket is blocked from access while data is being read from or written to -- provide better I/O-error notification than the non-blocking counterpart, non-blocking operations allow the calling thread to continue. In this article, the author will cover both the client and server side as he describes how to create non-blocking secure connections using the Java Secure Socket Extensions (JSSE) and the Java NIO (new I/O) library, and he will explain the traditional approach to creating a non-blocking socket, as well as an alternative (and necessary) method if you want to use JSSE with NIO.
    http://www-106.ibm.com/developerworks/java/library/j-sslnb.html?ca=dgr-jw03j-sslnb

    MORE IBM SPAM Previous discussion
    I find it interesting spam, but thats a matter of taste. If the OP was truly interested in "trying to get new information out there" he would answer the mulitple questions about NIO and especially NIO mixed with traditional Sockets and NIO vs Secure Sockets. These are all on ALT, NIO is of no interest to New to Java folk.
    Given their budget I think IBM could do a better job of publishing their research.

  • Non-blocking ServerSocketChannel.accept()

    This may be a dumb question, but what would the motivation be behind utilizing a non-blocking call to the accept method of the ServerSocketChannel? I'm just having a hard time thinking of any, although I'm sure there are good reasons for doing it.
    Thanks,
    Ken

    it does seem pretty strange

  • Blocking Calls Inbound - ??

    Hello:
    Is there a way to block calls inbound on the gateway router (coming in via the Pri)coming into an ip phone?
    Or is this something that needs to be configured in the CCM for that particular phone.
    Trying to block some 1-800 numbers from calling into an ip phone.
    Thanks.

    Thank you, much.
    So based on this: I am thinking of the following configuration:
    #voice translation-rule 1
    #rule 1 reject /1800*/
    #voice translation-profile Block_1800
    #translate calling 1
    #dial-peer voice 22 pots
    #call-block translation-profile incoming Block_1800
    #call-block disconnect cause incoming call-reject incoming called-number
    #port 1/0:23
    #end
    Would this work to block any 1800 number from calling into the IP Phone?
    Thank you.

Maybe you are looking for