From: <pj...@us...> - 2009-04-16 23:59:54
|
Revision: 6232 http://jython.svn.sourceforge.net/jython/?rev=6232&view=rev Author: pjenvey Date: 2009-04-16 23:59:40 +0000 (Thu, 16 Apr 2009) Log Message: ----------- cleanup/coding standards Modified Paths: -------------- trunk/jython/src/org/python/core/io/StreamIO.java trunk/jython/src/org/python/core/io/UniversalIOWrapper.java Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-16 06:18:40 UTC (rev 6231) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-16 23:59:40 UTC (rev 6232) @@ -16,8 +16,8 @@ import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import org.python.core.Py; import org.python.core.imp; -import org.python.core.Py; /** * Raw I/O implementation for simple streams. @@ -82,9 +82,6 @@ * Construct a StreamIO for the given write channel. * * @param writeChannel a WritableByteChannel - * @param isatty boolean whether this io object is a tty device - * @param closefd boolean whether the underlying file is closed on - * close() (defaults to True) */ public StreamIO(WritableByteChannel writeChannel) { this(writeChannel, true); @@ -160,56 +157,62 @@ /** Unwrap one or more nested FilterInputStreams. */ private static FileDescriptor getInputFileDescriptor(InputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileInputStream) - return ((FileInputStream)stream).getFD(); - if (stream instanceof FilterInputStream) { - Field inField = null; - try { - inField = FilterInputStream.class.getDeclaredField("in"); - inField.setAccessible(true); - return getInputFileDescriptor((InputStream)inField.get(stream)); - } catch (Exception e) { - } finally { - if (inField != null && inField.isAccessible()) - inField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileInputStream) { + return ((FileInputStream)stream).getFD(); + } + if (stream instanceof FilterInputStream) { + Field inField = null; + try { + inField = FilterInputStream.class.getDeclaredField("in"); + inField.setAccessible(true); + return getInputFileDescriptor((InputStream)inField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (inField != null && inField.isAccessible()) + inField.setAccessible(false); + } + } + return null; } /** Unwrap one or more nested FilterOutputStreams. */ private static FileDescriptor getOutputFileDescriptor(OutputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileOutputStream) - return ((FileOutputStream)stream).getFD(); - if (stream instanceof FilterOutputStream) { - Field outField = null; - try { - outField = FilterOutputStream.class.getDeclaredField("out"); - outField.setAccessible(true); - return getOutputFileDescriptor((OutputStream)outField.get(stream)); - } catch (Exception e) { - } finally { - if (outField != null && outField.isAccessible()) - outField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileOutputStream) { + return ((FileOutputStream)stream).getFD(); + } + if (stream instanceof FilterOutputStream) { + Field outField = null; + try { + outField = FilterOutputStream.class.getDeclaredField("out"); + outField.setAccessible(true); + return getOutputFileDescriptor((OutputStream)outField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (outField != null && outField.isAccessible()) + outField.setAccessible(false); + } + } + return null; } /** {@inheritDoc} */ - public boolean isatty() { checkClosed(); FileDescriptor fd; try { - if ( ((fd = getInputFileDescriptor(inputStream)) == null) && - ((fd = getOutputFileDescriptor(outputStream)) == null)) - return false; + if ((fd = getInputFileDescriptor(inputStream)) == null + && (fd = getOutputFileDescriptor(outputStream)) == null) { + return false; + } } catch (IOException e) { return false; } Modified: trunk/jython/src/org/python/core/io/UniversalIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-04-16 06:18:40 UTC (rev 6231) +++ trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-04-16 23:59:40 UTC (rev 6232) @@ -3,7 +3,6 @@ import java.nio.ByteBuffer; import java.util.EnumSet; -import java.util.Iterator; import org.python.core.Py; import org.python.core.PyObject; @@ -189,7 +188,6 @@ byte[] readaheadArray; int readaheadPos; int interimBuilderPos; - String line; do { readaheadArray = readahead.array(); @@ -313,12 +311,12 @@ if (size == 0) { return Py.None; } else if (size == 1) { - Newline newline = (Newline)newlineTypes.iterator().next(); + Newline newline = newlineTypes.iterator().next(); return new PyString(newline.getValue()); } - int i = 0; PyObject[] newlines = new PyObject[size]; + int i = 0; for (Newline newline : newlineTypes) { newlines[i++] = new PyString(newline.getValue()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-17 02:22:44
|
Revision: 6233 http://jython.svn.sourceforge.net/jython/?rev=6233&view=rev Author: pjenvey Date: 2009-04-17 01:35:16 +0000 (Fri, 17 Apr 2009) Log Message: ----------- fix LineBufferedWriter.write's result, cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/io/BufferedWriter.java trunk/jython/src/org/python/core/io/LineBufferedWriter.java Modified: trunk/jython/src/org/python/core/io/BufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-04-16 23:59:40 UTC (rev 6232) +++ trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-04-17 01:35:16 UTC (rev 6233) @@ -53,10 +53,11 @@ int totalToWrite = total - toBuffer; int count = totalToWrite; + ByteBuffer[] bulk = new ByteBuffer[] {buffer, bytes}; // Prepare the buffer for writing buffer.flip(); while (count > 0) { - count -= rawIO.write(new ByteBuffer[] {buffer, bytes}); + count -= rawIO.write(bulk); } // Prepare the buffer for buffering buffer.clear(); Modified: trunk/jython/src/org/python/core/io/LineBufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-04-16 23:59:40 UTC (rev 6232) +++ trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-04-17 01:35:16 UTC (rev 6233) @@ -23,7 +23,7 @@ /** {@inheritDoc} */ public int write(ByteBuffer bytes) { - int written = 0; + int size = bytes.remaining(); while (bytes.hasRemaining()) { byte next = bytes.get(); @@ -37,11 +37,10 @@ } if (next == LF_BYTE) { - written += buffer.position(); flush(); } } - return written; + return size; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-06-06 05:25:02
|
Revision: 6455 http://jython.svn.sourceforge.net/jython/?rev=6455&view=rev Author: pjenvey Date: 2009-06-06 05:24:44 +0000 (Sat, 06 Jun 2009) Log Message: ----------- revert r6448 and part of r6449: don't emulate CPython 2.x flush for now as we're assuming py3k style in various places Modified Paths: -------------- trunk/jython/src/org/python/core/io/FileIO.java trunk/jython/src/org/python/core/io/StreamIO.java Modified: trunk/jython/src/org/python/core/io/FileIO.java =================================================================== --- trunk/jython/src/org/python/core/io/FileIO.java 2009-06-06 02:05:42 UTC (rev 6454) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-06-06 05:24:44 UTC (rev 6455) @@ -329,12 +329,6 @@ } /** {@inheritDoc} */ - public void flush() { - checkClosed(); - checkWritable(); - } - - /** {@inheritDoc} */ public void close() { if (closed()) { return; Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-06-06 02:05:42 UTC (rev 6454) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-06-06 05:24:44 UTC (rev 6455) @@ -135,8 +135,6 @@ /** {@inheritDoc} */ public void flush() { - checkClosed(); - checkWritable(); if (outputStream == null) { return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-08-29 17:54:24
|
Revision: 6724 http://jython.svn.sourceforge.net/jython/?rev=6724&view=rev Author: pjenvey Date: 2009-08-29 17:54:06 +0000 (Sat, 29 Aug 2009) Log Message: ----------- use @Override Modified Paths: -------------- trunk/jython/src/org/python/core/io/BinaryIOWrapper.java trunk/jython/src/org/python/core/io/BufferedIOMixin.java trunk/jython/src/org/python/core/io/BufferedRandom.java trunk/jython/src/org/python/core/io/BufferedReader.java trunk/jython/src/org/python/core/io/BufferedWriter.java 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/LineBufferedRandom.java trunk/jython/src/org/python/core/io/LineBufferedWriter.java trunk/jython/src/org/python/core/io/RawIOBase.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 trunk/jython/src/org/python/core/io/StreamIO.java trunk/jython/src/org/python/core/io/TextIOBase.java trunk/jython/src/org/python/core/io/TextIOWrapper.java trunk/jython/src/org/python/core/io/UniversalIOWrapper.java Modified: trunk/jython/src/org/python/core/io/BinaryIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/BinaryIOWrapper.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/BinaryIOWrapper.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -22,7 +22,7 @@ super(bufferedIO); } - /** {@inheritDoc} */ + @Override public String read(int size) { if (size < 0) { return readall(); @@ -51,7 +51,7 @@ return StringUtil.fromBytes(data); } - /** {@inheritDoc} */ + @Override public String readall() { if (!readahead.hasRemaining()) { return StringUtil.fromBytes(bufferedIO.readall()); @@ -66,7 +66,7 @@ return StringUtil.fromBytes(all); } - /** {@inheritDoc} */ + @Override public String readline(int size) { // Avoid ByteBuffer (this.readahead) and StringBuilder // (this.builder) method calls in the inner loop by reading @@ -110,7 +110,7 @@ return drainBuilder(); } - /** {@inheritDoc} */ + @Override public int write(String buf) { if (readahead.hasRemaining()) { clearReadahead(); Modified: trunk/jython/src/org/python/core/io/BufferedIOMixin.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedIOMixin.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/BufferedIOMixin.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -44,27 +44,27 @@ this.bufferSize = bufferSize; } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { return rawIO.seek(pos, whence); } - /** {@inheritDoc} */ + @Override public long tell() { return rawIO.tell(); } - /** {@inheritDoc} */ + @Override public long truncate(long size) { return rawIO.truncate(size); } - /** {@inheritDoc} */ + @Override public void flush() { rawIO.flush(); } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -80,27 +80,27 @@ rawIO.close(); } - /** {@inheritDoc} */ + @Override public RawIOBase fileno() { return rawIO.fileno(); } - /** {@inheritDoc} */ + @Override public boolean isatty() { return rawIO.isatty(); } - /** {@inheritDoc} */ + @Override public boolean readable() { return rawIO.readable(); } - /** {@inheritDoc} */ + @Override public boolean writable() { return rawIO.writable(); } - /** {@inheritDoc} */ + @Override public boolean closed() { return rawIO.closed(); } Modified: trunk/jython/src/org/python/core/io/BufferedRandom.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedRandom.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/BufferedRandom.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -37,7 +37,7 @@ this.writer = new BufferedWriter(rawIO, bufferSize); } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { flush(); // First do the raw seek, then empty the read buffer, so that @@ -47,7 +47,7 @@ return pos; } - /** {@inheritDoc} */ + @Override public long tell() { if (writer.buffered()) { return writer.tell(); @@ -55,25 +55,25 @@ return reader.tell(); } - /** {@inheritDoc} */ + @Override public ByteBuffer read(int size) { flush(); return reader.read(size); } - /** {@inheritDoc} */ + @Override public ByteBuffer readall() { flush(); return reader.readall(); } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer bytes) { flush(); return reader.readinto(bytes); } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer bytes) { if (reader.buffered()) { reader.clear(); @@ -81,19 +81,19 @@ return writer.write(bytes); } - /** {@inheritDoc} */ + @Override public ByteBuffer peek(int size) { flush(); return reader.peek(size); } - /** {@inheritDoc} */ + @Override public int read1(ByteBuffer bytes) { flush(); return reader.read1(bytes); } - /** {@inheritDoc} */ + @Override public void flush() { writer.flush(); } Modified: trunk/jython/src/org/python/core/io/BufferedReader.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedReader.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/BufferedReader.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -27,7 +27,7 @@ clear(); } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer bytes) { int size = bytes.remaining(); @@ -57,7 +57,7 @@ return (int)read; } - /** {@inheritDoc} */ + @Override public ByteBuffer readall() { ByteBuffer remaining = rawIO.readall(); @@ -73,7 +73,7 @@ return all; } - /** {@inheritDoc} */ + @Override public ByteBuffer peek(int size) { if (buffer.remaining() < Math.min(size, bufferSize)) { // Prepare to fill the buffer @@ -89,7 +89,7 @@ return buffer; } - /** {@inheritDoc} */ + @Override public int read1(ByteBuffer bytes) { int size = bytes.remaining(); if (size == 0) { @@ -106,12 +106,12 @@ return readinto(bytes); } - /** {@inheritDoc} */ + @Override public long tell() { return rawIO.tell() - buffer.remaining(); } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { if (whence == 1) { pos -= buffer.remaining(); @@ -121,17 +121,17 @@ return pos; } - /** {@inheritDoc} */ + @Override public boolean buffered() { return buffer.hasRemaining(); } - /** {@inheritDoc} */ + @Override public void clear() { buffer.clear().limit(0); } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer bytes) { // Never writable; just raise the appropriate exception checkClosed(); @@ -139,7 +139,7 @@ return -1; } - /** {@inheritDoc} */ + @Override public boolean writable() { return false; } Modified: trunk/jython/src/org/python/core/io/BufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -26,7 +26,7 @@ buffer = ByteBuffer.allocate(this.bufferSize); } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer bytes) { if (bufferSize == 0) { return rawIO.write(bytes); @@ -70,7 +70,7 @@ return totalToWrite; } - /** {@inheritDoc} */ + @Override public void flush() { if (buffer.position() > 0) { buffer.flip(); @@ -82,23 +82,23 @@ super.flush(); } - /** {@inheritDoc} */ + @Override public long tell() { return rawIO.tell() + buffer.position(); } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { flush(); return rawIO.seek(pos, whence); } - /** {@inheritDoc} */ + @Override public boolean buffered() { return buffer.position() > 0; } - /** {@inheritDoc} */ + @Override public ByteBuffer readall() { // Never readable; just raise the appropriate exception checkClosed(); @@ -106,7 +106,7 @@ return null; } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer bytes) { // Never readable; just raise the appropriate exception checkClosed(); @@ -114,7 +114,7 @@ return -1; } - /** {@inheritDoc} */ + @Override public int read1(ByteBuffer bytes) { // Never readable; just raise the appropriate exception checkClosed(); @@ -122,7 +122,7 @@ return -1; } - /** {@inheritDoc} */ + @Override public boolean readable() { return false; } Modified: trunk/jython/src/org/python/core/io/DatagramSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/DatagramSocketIO.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -29,7 +29,7 @@ this.socketChannel = socketChannel; } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); @@ -57,7 +57,7 @@ } } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); @@ -85,7 +85,7 @@ } } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -98,7 +98,7 @@ super.close(); } - /** {@inheritDoc} */ + @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 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/FileIO.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -180,7 +180,7 @@ } } - /** {@inheritDoc} */ + @Override public boolean isatty() { checkClosed(); if (file == null) { @@ -193,7 +193,7 @@ } } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); @@ -252,7 +252,7 @@ return all; } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); @@ -280,7 +280,7 @@ } } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { checkClosed(); try { @@ -303,7 +303,7 @@ } } - /** {@inheritDoc} */ + @Override public long tell() { checkClosed(); try { @@ -313,7 +313,7 @@ } } - /** {@inheritDoc} */ + @Override public long truncate(long size) { checkClosed(); checkWritable(); @@ -328,7 +328,7 @@ return size; } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -351,17 +351,17 @@ return readable() ? Channels.newInputStream(fileChannel) : super.asInputStream(); } - /** {@inheritDoc} */ + @Override public boolean readable() { return reading || plus; } - /** {@inheritDoc} */ + @Override public boolean writable() { return writing; } - /** {@inheritDoc} */ + @Override public Channel getChannel() { return fileChannel; } Modified: trunk/jython/src/org/python/core/io/LineBufferedRandom.java =================================================================== --- trunk/jython/src/org/python/core/io/LineBufferedRandom.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/LineBufferedRandom.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -19,7 +19,7 @@ super(rawIO, 1); } - /** {@inheritDoc} */ + @Override protected void initChildBuffers() { // Line buffering is for output only this.reader = new BufferedReader(rawIO, 0); Modified: trunk/jython/src/org/python/core/io/LineBufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -21,7 +21,7 @@ buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE); } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer bytes) { int size = bytes.remaining(); Modified: trunk/jython/src/org/python/core/io/RawIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/RawIOBase.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/RawIOBase.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -155,7 +155,7 @@ return count; } - /** {@inheritDoc} */ + @Override public RawIOBase fileno() { checkClosed(); return this; Modified: trunk/jython/src/org/python/core/io/ServerSocketIO.java =================================================================== --- trunk/jython/src/org/python/core/io/ServerSocketIO.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/ServerSocketIO.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -30,21 +30,21 @@ this.socketChannel = socketChannel; } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); throw Py.IOError(Errno.ENOTCONN); } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); throw Py.IOError(Errno.EBADF); } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -57,7 +57,7 @@ super.close(); } - /** {@inheritDoc} */ + @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 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/SocketIO.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -29,7 +29,7 @@ this.socketChannel = socketChannel; } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); @@ -57,7 +57,7 @@ } } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); @@ -85,7 +85,7 @@ } } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -98,7 +98,7 @@ super.close(); } - /** {@inheritDoc} */ + @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 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/SocketIOBase.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -45,12 +45,12 @@ } } - /** {@inheritDoc} */ + @Override public boolean readable() { return readable; } - /** {@inheritDoc} */ + @Override public boolean writable() { return writable; } Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -111,7 +111,7 @@ this.outputStream = outputStream; } - /** {@inheritDoc} */ + @Override public int readinto(ByteBuffer buf) { checkClosed(); checkReadable(); @@ -122,7 +122,7 @@ } } - /** {@inheritDoc} */ + @Override public int write(ByteBuffer buf) { checkClosed(); checkWritable(); @@ -133,7 +133,7 @@ } } - /** {@inheritDoc} */ + @Override public void flush() { if (outputStream == null) { return; @@ -145,7 +145,7 @@ } } - /** {@inheritDoc} */ + @Override public void close() { if (closed()) { return; @@ -217,7 +217,7 @@ return null; } - /** {@inheritDoc} */ + @Override public boolean isatty() { checkClosed(); @@ -234,12 +234,12 @@ return FileUtil.isatty(fd); } - /** {@inheritDoc} */ + @Override public boolean readable() { return readChannel != null; } - /** {@inheritDoc} */ + @Override public boolean writable() { return writeChannel != null; } @@ -266,7 +266,7 @@ return super.asInputStream(); } - /** {@inheritDoc} */ + @Override public Channel getChannel() { return readable() ? readChannel : writeChannel; } Modified: trunk/jython/src/org/python/core/io/TextIOBase.java =================================================================== --- trunk/jython/src/org/python/core/io/TextIOBase.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/TextIOBase.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -129,7 +129,7 @@ return -1; } - /** {@inheritDoc} */ + @Override public long truncate(long pos) { long initialPos = tell(); flush(); @@ -143,49 +143,49 @@ return pos; } - /** {@inheritDoc} */ + @Override public void flush() { bufferedIO.flush(); } - /** {@inheritDoc} */ + @Override public void close() { bufferedIO.close(); } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { pos = bufferedIO.seek(pos, whence); clearReadahead(); return pos; } - /** {@inheritDoc} */ + @Override public long tell() { return bufferedIO.tell() - readahead.remaining(); } - /** {@inheritDoc} */ + @Override public RawIOBase fileno() { return bufferedIO.fileno(); } - /** {@inheritDoc} */ + @Override public boolean isatty() { return bufferedIO.isatty(); } - /** {@inheritDoc} */ + @Override public boolean readable() { return bufferedIO.readable(); } - /** {@inheritDoc} */ + @Override public boolean writable() { return bufferedIO.writable(); } - /** {@inheritDoc} */ + @Override public boolean closed() { return bufferedIO.closed(); } Modified: trunk/jython/src/org/python/core/io/TextIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/TextIOWrapper.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/TextIOWrapper.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -37,7 +37,7 @@ newlineIsLF = newline.equals("\n"); } - /** {@inheritDoc} */ + @Override public String read(int size) { if (newlineIsLF) { return super.read(size); @@ -98,7 +98,7 @@ return new String(builderArray, 0, builderPos); } - /** {@inheritDoc} */ + @Override public String readall() { if (newlineIsLF) { return super.readall(); @@ -172,7 +172,7 @@ return destPos - destStartPos; } - /** {@inheritDoc} */ + @Override public String readline(int size) { if (newlineIsLF) { return super.readline(size); @@ -252,7 +252,7 @@ return drainBuilder(); } - /** {@inheritDoc} */ + @Override public int write(String buf) { if (!newlineIsLF) { buf = LF_PATTERN.matcher(buf).replaceAll(newline); Modified: trunk/jython/src/org/python/core/io/UniversalIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-08-26 10:33:22 UTC (rev 6723) +++ trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-08-29 17:54:06 UTC (rev 6724) @@ -33,7 +33,7 @@ super(bufferedIO); } - /** {@inheritDoc} */ + @Override public String read(int size) { if (size < 0) { return readall(); @@ -105,7 +105,7 @@ return new String(builderArray, 0, builderPos); } - /** {@inheritDoc} */ + @Override public String readall() { // Read the remainder of file ByteBuffer remaining = bufferedIO.readall(); @@ -179,7 +179,7 @@ return destPos - destStartPos; } - /** {@inheritDoc} */ + @Override public String readline(int size) { // Avoid ByteBuffer (this.readahead) and StringBuilder // (this.builder) method calls in the inner loop by reading @@ -268,7 +268,7 @@ return drainBuilder(); } - /** {@inheritDoc} */ + @Override public int write(String buf) { // Universal newlines doesn't support writing; just raise the // appropriate exception @@ -277,14 +277,14 @@ return -1; } - /** {@inheritDoc} */ + @Override public long seek(long pos, int whence) { pos = super.seek(pos, whence); skipNextLF = false; return pos; } - /** {@inheritDoc} */ + @Override public long tell() { long pos = super.tell(); if (skipNextLF) { @@ -305,7 +305,7 @@ return pos; } - /** {@inheritDoc} */ + @Override public PyObject getNewlines() { int size = newlineTypes.size(); if (size == 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |