static void checkChannelValidity ( Object channel ) throws IOException { if ( channel == null ) { /* Most common reason is that original socket does not have a channel. * So making this an IOException rather than a RuntimeException. */ throw new IOException ( "Channel is null. Check " + "how the channel or socket is created." ) ; } if ( ! ( channel instanceof SelectableChannel ) ) { throw new IOException ( "Channel should be a SelectableChannel" ) ; } }
Utility function to check if channel is ok . Mainly to throw IOException instead of runtime exception in case of mismatch . This mismatch can occur for many runtime reasons .