001 /**
002 * Copyright (C) 2009-2013 Barchart, Inc. <http://www.barchart.com/>
003 *
004 * All rights reserved. Licensed under the OSI BSD License.
005 *
006 * http://www.opensource.org/licenses/bsd-license.php
007 */
008 package com.barchart.udt.nio;
009
010 import java.io.IOException;
011 import java.io.InputStream;
012 import java.io.OutputStream;
013
014 import com.barchart.udt.ExceptionUDT;
015 import com.barchart.udt.net.NetSocketUDT;
016
017 public class NioSocketUDT extends NetSocketUDT {
018
019 protected final SocketChannelUDT channelUDT;
020
021 protected NioSocketUDT(final SocketChannelUDT channelUDT)
022 throws ExceptionUDT {
023 super(channelUDT.socketUDT());
024 this.channelUDT = channelUDT;
025 }
026
027 @Override
028 public SocketChannelUDT getChannel() {
029 return channelUDT;
030 }
031
032 @Override
033 public synchronized InputStream getInputStream() throws IOException {
034 if (inputStream == null) {
035 inputStream = new NioInputStreamUDT(channelUDT);
036 }
037 return inputStream;
038 }
039
040 @Override
041 public synchronized OutputStream getOutputStream() throws IOException {
042 if (outputStream == null) {
043 outputStream = new NioOutputStreamUDT(channelUDT);
044 }
045 return outputStream;
046 }
047
048 }