From: <pj...@us...> - 2010-04-23 05:14:56
|
Revision: 7043 http://jython.svn.sourceforge.net/jython/?rev=7043&view=rev Author: pjenvey Date: 2010-04-23 05:14:49 +0000 (Fri, 23 Apr 2010) Log Message: ----------- move more into SocketIOBase, make getChannel return types covariant Modified Paths: -------------- trunk/jython/src/org/python/core/io/DatagramSocketIO.java trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/ServerSocketIO.java trunk/jython/src/org/python/core/io/SocketIO.java trunk/jython/src/org/python/core/io/SocketIOBase.java Modified: trunk/jython/src/org/python/core/io/DatagramSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.DatagramChannel; import org.python.core.Py; @@ -13,11 +12,8 @@ * * @author Philip Jenvey */ -public class DatagramSocketIO extends SocketIOBase { +public class DatagramSocketIO extends SocketIOBase<DatagramChannel> { - /** The underlying socket */ - private DatagramChannel socketChannel; - /** * Construct a DatagramSocketIO for the given DatagramChannel. * @@ -25,8 +21,7 @@ * @param mode a raw io socket mode String */ public DatagramSocketIO(DatagramChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -47,6 +42,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long readinto(ByteBuffer[] bufs) { checkClosed(); checkReadable(); @@ -75,6 +71,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long write(ByteBuffer[] bufs) { checkClosed(); checkWritable(); @@ -84,22 +81,4 @@ throw Py.IOError(ioe); } } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/FileIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -9,7 +9,6 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.Channels; import java.nio.channels.FileChannel; @@ -423,7 +422,7 @@ } @Override - public Channel getChannel() { + public FileChannel getChannel() { return fileChannel; } } Modified: trunk/jython/src/org/python/core/io/ServerSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/ServerSocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/ServerSocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -1,9 +1,7 @@ /* Copyright (c) 2007 Jython Developers */ package org.python.core.io; -import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.ServerSocketChannel; import com.kenai.constantine.platform.Errno; @@ -14,11 +12,8 @@ * * @author Philip Jenvey */ -public class ServerSocketIO extends SocketIOBase { +public class ServerSocketIO extends SocketIOBase<ServerSocketChannel> { - /** The underlying socket */ - private ServerSocketChannel socketChannel; - /** * Construct a ServerSocketIO for the given ServerSocketChannel. * @@ -26,8 +21,7 @@ * @param mode a raw io socket mode String */ public ServerSocketIO(ServerSocketChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -43,22 +37,4 @@ checkWritable(); throw Py.IOError(Errno.EBADF); } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/SocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/SocketIO.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/SocketIO.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -3,7 +3,6 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.Channel; import java.nio.channels.SocketChannel; import org.python.core.Py; @@ -13,11 +12,8 @@ * * @author Philip Jenvey */ -public class SocketIO extends SocketIOBase { +public class SocketIO extends SocketIOBase<SocketChannel> { - /** The underlying socket */ - private SocketChannel socketChannel; - /** * Construct a SocketIO for the given SocketChannel. * @@ -25,8 +21,7 @@ * @param mode a raw io socket mode String */ public SocketIO(SocketChannel socketChannel, String mode) { - super(mode); - this.socketChannel = socketChannel; + super(socketChannel, mode); } @Override @@ -47,6 +42,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long readinto(ByteBuffer[] bufs) { checkClosed(); checkReadable(); @@ -75,6 +71,7 @@ * @param bufs {@inheritDoc} * @return {@inheritDoc} */ + @Override public long write(ByteBuffer[] bufs) { checkClosed(); checkWritable(); @@ -84,22 +81,4 @@ throw Py.IOError(ioe); } } - - @Override - public void close() { - if (closed()) { - return; - } - try { - socketChannel.close(); - } catch (IOException ioe) { - throw Py.IOError(ioe); - } - super.close(); - } - - @Override - public Channel getChannel() { - return socketChannel; - } } Modified: trunk/jython/src/org/python/core/io/SocketIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/SocketIOBase.java 2010-04-23 05:06:48 UTC (rev 7042) +++ trunk/jython/src/org/python/core/io/SocketIOBase.java 2010-04-23 05:14:49 UTC (rev 7043) @@ -1,6 +1,9 @@ /* Copyright (c) 2007 Jython Developers */ package org.python.core.io; +import java.io.IOException; +import java.nio.channels.Channel; + import org.python.core.Py; /** @@ -8,8 +11,11 @@ * * @author Philip Jenvey */ -public abstract class SocketIOBase extends RawIOBase { +public abstract class SocketIOBase<T extends Channel> extends RawIOBase { + /** The underlying socket */ + protected T socketChannel; + /** true if the socket is allowed to be read from */ private boolean readable = false; @@ -17,11 +23,13 @@ private boolean writable = false; /** - * Construct a SocketIOBase. + * Construct a SocketIOBase for the given socket Channel * + * @param socketChannel a Channel to wrap * @param mode a raw io socket mode String */ - public SocketIOBase(String mode) { + public SocketIOBase(T socketChannel, String mode) { + this.socketChannel = socketChannel; parseMode(mode); } @@ -33,7 +41,7 @@ * * @param mode a raw io socket mode String */ - private void parseMode(String mode) { + protected void parseMode(String mode) { if (mode.equals("r")) { readable = true; } else if (mode.equals("w")) { @@ -46,6 +54,24 @@ } @Override + public void close() { + if (closed()) { + return; + } + try { + socketChannel.close(); + } catch (IOException ioe) { + throw Py.IOError(ioe); + } + super.close(); + } + + @Override + public T getChannel() { + return socketChannel; + } + + @Override public boolean readable() { return readable; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |