/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A helper class for properly sizing inbound byte buffers and
* redirecting I/O calls to the proper SocketChannel call.
* <P>
* Many of these calls may seem unnecessary until you consider
* that they are placeholders for the secure variant, which is much
* more involved. See ChannelIOSecure for more information.
*
* @author Brad R. Wetmore
* @author Mark Reinhold
*/
class ChannelIO {
/*
* All of the inbound request data lives here until we determine
* that we've read everything, then we pass that data back to the
* caller.
*/
throws IOException {
}
throws IOException {
return cio;
}
return sc;
}
/*
* Return a ByteBuffer with "remaining" space to work. If you have to
* reallocate the ByteBuffer, copy the existing info into the new buffer.
*/
// Expand buffer for large request
}
}
/*
* Perform any handshaking processing.
* <P>
* This variant is for Servers without SelectionKeys (e.g.
* blocking).
* <P>
* return true when we're done with handshaking.
*/
return true;
}
/*
* Perform any handshaking processing.
* <P>
* This variant is for Servers with SelectionKeys, so that
* we can register for selectable operations (e.g. selectable
* non-blocking).
* <P>
* return true when we're done with handshaking.
*/
return true;
}
/*
* Resize (if necessary) the inbound data buffer, and then read more
* data into the read buffer.
*/
/*
* Allocate more space if less than 5% remains
*/
}
/*
* All data has been read, pass back the request in one buffer.
*/
return requestBB;
}
/*
* Write the src buffer into the socket channel.
*/
}
/*
* Perform a FileChannel.TransferTo on the socket channel.
*/
}
/*
* Flush any outstanding data to the network if possible.
* <P>
* This isn't really necessary for the insecure variant, but needed
* for the secure one where intermediate buffering must take place.
* <P>
* Return true if successful.
*/
return true;
}
/*
* Start any connection shutdown processing.
* <P>
* This isn't really necessary for the insecure variant, but needed
* for the secure one where intermediate buffering must take place.
* <P>
* Return true if successful, and the data has been flushed.
*/
return true;
}
/*
* Close the underlying connection.
*/
}
}