You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2002/04/13 06:55:00 UTC

cvs commit: jakarta-commons-sandbox/net/src/java/org/apache/commons/io CopyStreamAdapter.java CopyStreamEvent.java CopyStreamException.java CopyStreamListener.java DotTerminatedMessageReader.java

brekke      02/04/12 21:55:00

  Modified:    net/src/java/org/apache/commons/io CopyStreamAdapter.java
                        CopyStreamEvent.java CopyStreamException.java
                        CopyStreamListener.java
                        DotTerminatedMessageReader.java
  Added:       net      project.properties
  Log:
  Started cleaning up checkstyle reported issues.  Formatting and internal
  member name changes mostly.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/net/project.properties
  
  Index: project.properties
  ===================================================================
  ##
  # Project Settings
  ##
  
  checkstyle.javadoc.scope=protected
  
  
  
  1.3       +29 -29    jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamAdapter.java
  
  Index: CopyStreamAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopyStreamAdapter.java	12 Apr 2002 04:42:45 -0000	1.2
  +++ CopyStreamAdapter.java	13 Apr 2002 04:55:00 -0000	1.3
  @@ -57,12 +57,13 @@
   import java.util.Enumeration;
   import org.apache.commons.util.ListenerList;
   
  -/***
  +/**
    * The CopyStreamAdapter will relay CopyStreamEvents to a list of listeners
    * when either of its bytesTransferred() methods are called.  Its purpose
    * is to facilitate the notification of the progress of a copy operation
  - * performed by one of the static copyStream() methods in org.apache.commons.io.Util
  - * to multiple listeners.  The static copyStream() methods invoke the
  + * performed by one of the static copyStream() methods in
  + * org.apache.commons.io.Util to multiple listeners.  The static
  + * copyStream() methods invoke the
    * bytesTransfered(long, int) of a CopyStreamListener for performance
    * reasons and also because multiple listeners cannot be registered given
    * that the methods are static.
  @@ -71,32 +72,31 @@
    * @see CopyStreamEvent
    * @see CopyStreamListener
    * @see Util
  - * @author Daniel F. Savarese
  - ***/
  -
  + * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  + * @version $Id: CopyStreamAdapter.java,v 1.3 2002/04/13 04:55:00 brekke Exp $
  + */
   public class CopyStreamAdapter implements CopyStreamListener
   {
  -    private ListenerList __listeners;
  +    private ListenerList internalListeners;
   
  -    /***
  +    /**
        * Creates a new copyStreamAdapter.
  -     ***/
  +     */
       public CopyStreamAdapter()
       {
  -        __listeners = new ListenerList();
  +        internalListeners = new ListenerList();
       }
   
  -    /***
  +    /**
        * This method is invoked by a CopyStreamEvent source after copying
        * a block of bytes from a stream.  The CopyStreamEvent will contain
        * the total number of bytes transferred so far and the number of bytes
        * transferred in the last write.  The CopyStreamAdapater will relay
        * the event to all of its registered listeners, listing itself as the
        * source of the event.
  -     * <p>
        * @param event The CopyStreamEvent fired by the copying of a block of
        *              bytes.
  -     ***/
  +     */
       public void bytesTransferred(CopyStreamEvent event)
       {
           bytesTransferred(event.getTotalBytesTransferred(),
  @@ -104,15 +104,13 @@
                            event.getStreamSize());
       }
   
  -
  -    /***
  +    /**
        * This method is not part of the JavaBeans model and is used by the
        * static methods in the org.apache.commons.io.Util class for efficiency.
        * It is invoked after a block of bytes to inform the listener of the
        * transfer.  The CopyStreamAdapater will create a CopyStreamEvent
        * from the arguments and relay the event to all of its registered
        * listeners, listing itself as the source of the event.
  -     * <p>
        * @param totalBytesTransferred  The total number of bytes transferred
        *         so far by the copy operation.
        * @param bytesTransferred  The number of bytes copied by the most recent
  @@ -120,43 +118,45 @@
        * @param streamSize The number of bytes in the stream being copied.
        *        This may be equal to CopyStreamEvent.UNKNOWN_STREAM_SIZE if
        *        the size is unknown.
  -     ***/
  +     */
       public void bytesTransferred(long totalBytesTransferred,
                                    int bytesTransferred, long streamSize)
       {
           Enumeration listeners;
           CopyStreamEvent event;
   
  -        listeners = __listeners.getListeners();
  +        listeners = internalListeners.getListeners();
   
  -        event = new CopyStreamEvent(this, totalBytesTransferred, bytesTransferred,
  +        event = new CopyStreamEvent(this,
  +                                    totalBytesTransferred,
  +                                    bytesTransferred,
                                       streamSize);
   
           while (listeners.hasMoreElements())
  -            ((CopyStreamListener)(listeners.nextElement())).bytesTransferred(event);
  +        {
  +            ((CopyStreamListener) (listeners.nextElement())).
  +                bytesTransferred(event);
  +        }
       }
   
  -
  -    /***
  +    /**
        * Registers a CopyStreamListener to receive CopyStreamEvents.
        * Although this method is not declared to be synchronized, it is
        * implemented in a thread safe manner.
  -     * <p>
        * @param listener  The CopyStreamlistener to register.
  -     ***/
  +     */
       public void addCopyStreamListener(CopyStreamListener listener)
       {
  -        __listeners.addListener(listener);
  +        internalListeners.addListener(listener);
       }
   
  -    /***
  +    /**
        * Unregisters a CopyStreamListener.  Although this method is not
        * synchronized, it is implemented in a thread safe manner.
  -     * <p>
        * @param listener  The CopyStreamlistener to unregister.
  -     ***/
  +     */
       public void removeCopyStreamListener(CopyStreamListener listener)
       {
  -        __listeners.removeListener(listener);
  +        internalListeners.removeListener(listener);
       }
   }
  
  
  
  1.3       +24 -24    jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamEvent.java
  
  Index: CopyStreamEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamEvent.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopyStreamEvent.java	12 Apr 2002 04:42:45 -0000	1.2
  +++ CopyStreamEvent.java	13 Apr 2002 04:55:00 -0000	1.3
  @@ -56,7 +56,7 @@
   
   import java.util.EventObject;
   
  -/***
  +/**
    * A CopyStreamEvent is triggered after every write performed by a
    * stream copying operation.  The event stores the number of bytes
    * transferred by the write triggering the event as well as the total
  @@ -66,19 +66,22 @@
    * @see CopyStreamListener
    * @see CopyStreamAdapter
    * @see Util
  - * @author Daniel F. Savarese
  - ***/
  -
  + * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  + * @version $Id: CopyStreamEvent.java,v 1.3 2002/04/13 04:55:00 brekke Exp $
  + */
   public class CopyStreamEvent extends EventObject
   {
  +    /**
  +     * Constant used to indicate the stream size is unknown.
  +     */
       public static final long UNKNOWN_STREAM_SIZE = -1;
   
  -    private int __bytesTransferred;
  -    private long __totalBytesTransferred, __streamSize;
  +    private int bytesTransferred;
  +    private long totalBytesTransferred;
  +    private long streamSize;
   
  -    /***
  +    /**
        * Creates a new CopyStreamEvent instance.
  -     * <p>
        * @param source  The source of the event.
        * @param totalBytesTransferred The total number of bytes transferred so
        *   far during a copy operation.
  @@ -87,49 +90,46 @@
        * @param streamSize  The number of bytes in the stream being copied.
        *          This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
        *          size is unknown.
  -     ***/
  +     */
       public CopyStreamEvent(Object source, long totalBytesTransferred,
                              int bytesTransferred, long streamSize)
       {
           super(source);
  -        __bytesTransferred = bytesTransferred;
  -        __totalBytesTransferred = totalBytesTransferred;
  +        this.bytesTransferred = bytesTransferred;
  +        this.totalBytesTransferred = totalBytesTransferred;
  +        this.streamSize = streamSize;
       }
   
  -    /***
  +    /**
        * Returns the number of bytes transferred by the write that triggered
        * the event.
  -     * <p>
        * @return The number of bytes transferred by the write that triggered
        * the vent.
  -     ***/
  +     */
       public int getBytesTransferred()
       {
  -        return __bytesTransferred;
  +        return bytesTransferred;
       }
   
  -    /***
  +    /**
        * Returns the total number of bytes transferred so far by the copy
        * operation.
  -     * <p>
        * @return The total number of bytes transferred so far by the copy
        * operation.
  -     ***/
  +     */
       public long getTotalBytesTransferred()
       {
  -        return __totalBytesTransferred;
  +        return totalBytesTransferred;
       }
   
  -    /***
  +    /**
        * Returns the size of the stream being copied.
        * This may be set to <code>UNKNOWN_STREAM_SIZE</code> if the
        * size is unknown.
  -     * <p>
        * @return The size of the stream being copied.
  -     ***/
  +     */
       public long getStreamSize()
       {
  -        return __streamSize;
  +        return streamSize;
       }
  -
   }
  
  
  
  1.3       +22 -28    jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamException.java
  
  Index: CopyStreamException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopyStreamException.java	12 Apr 2002 04:42:45 -0000	1.2
  +++ CopyStreamException.java	13 Apr 2002 04:55:00 -0000	1.3
  @@ -56,59 +56,53 @@
   
   import java.io.IOException;
   
  -/***
  +/**
    * The CopyStreamException class is thrown by the org.apache.commons.io.Util
    * copyStream() methods.  It stores the number of bytes confirmed to
    * have been transferred before an I/O error as well as the IOException
    * responsible for the failure of a copy operation.
  - * <p>
  - * <p>
    * @see Util
  - * @author Daniel F. Savarese
  - ***/
  -
  + * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  + * @version $Id: CopyStreamException.java,v 1.3 2002/04/13 04:55:00 brekke Exp $
  + */
   public class CopyStreamException extends IOException
   {
  -    private long __bytesTransferred;
  -    private IOException __exception;
  +    private long totalBytesTransferred;
  +    private IOException ioException;
   
  -    /***
  +    /**
        * Creates a new CopyStreamException instance.
  -     * <p>
        * @param message  A message describing the error.
        * @param bytesTransferred  The total number of bytes transferred before
        *        an exception was thrown in a copy operation.
        * @param exception  The IOException thrown during a copy operation.
  -     ***/
  -    public CopyStreamException(String message, long bytesTransferred,
  +     */
  +    public CopyStreamException(String message,
  +                               long bytesTransferred,
                                  IOException exception)
       {
           super(message);
  -        __bytesTransferred = bytesTransferred;
  -        __exception = exception;
  +        totalBytesTransferred = bytesTransferred;
  +        ioException = exception;
       }
   
  -    /***
  -     * Returns the total number of bytes confirmed to have been transferred by a 
  -     * failed copy operation.
  -     * <p>
  -     * @return The total number of bytes confirmed to have been transferred by a 
  -     * failed copy operation.
  -     ***/
  +    /**
  +     * Returns the total number of bytes confirmed to have
  +     * been transferred by a failed copy operation.
  +     * @return The total number of bytes confirmed to have
  +     * been transferred by a failed copy operation.
  +     */
       public long getTotalBytesTransferred()
       {
  -        return __bytesTransferred;
  +        return totalBytesTransferred;
       }
   
  -
  -    /***
  +    /**
        * Returns the IOException responsible for the failure of a copy operation.
  -     * <p>
        * @return The IOException responsible for the failure of a copy operation.
  -     ***/
  +     */
       public IOException getIOException()
       {
  -        return __exception;
  +        return ioException;
       }
  -
   }
  
  
  
  1.3       +8 -11     jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamListener.java
  
  Index: CopyStreamListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/io/CopyStreamListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CopyStreamListener.java	12 Apr 2002 04:42:45 -0000	1.2
  +++ CopyStreamListener.java	13 Apr 2002 04:55:00 -0000	1.3
  @@ -56,7 +56,7 @@
   
   import java.util.EventListener;
   
  -/***
  +/**
    * The CopyStreamListener class can accept CopyStreamEvents to keep track
    * of the progress of a stream copying operation.  However, it is currently
    * not used that way within NetComponents for performance reasons.  Rather
  @@ -74,30 +74,27 @@
    * @see CopyStreamEvent
    * @see CopyStreamAdapter
    * @see Util
  - * @author Daniel F. Savarese
  - ***/
  -
  + * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  + * @version $Id: CopyStreamListener.java,v 1.3 2002/04/13 04:55:00 brekke Exp $
  + */
   public interface CopyStreamListener extends EventListener
   {
  -
  -    /***
  +    /**
        * This method is invoked by a CopyStreamEvent source after copying
        * a block of bytes from a stream.  The CopyStreamEvent will contain
        * the total number of bytes transferred so far and the number of bytes
        * transferred in the last write.
  -     * <p>
        * @param event The CopyStreamEvent fired by the copying of a block of
        *              bytes.
  -     ***/
  +     */
       public void bytesTransferred(CopyStreamEvent event);
   
   
  -    /***
  +    /**
        * This method is not part of the JavaBeans model and is used by the
        * static methods in the org.apache.commons.io.Util class for efficiency.
        * It is invoked after a block of bytes to inform the listener of the
        * transfer.
  -     * <p>
        * @param totalBytesTransferred  The total number of bytes transferred
        *         so far by the copy operation.
        * @param bytesTransferred  The number of bytes copied by the most recent
  @@ -105,7 +102,7 @@
        * @param streamSize The number of bytes in the stream being copied.
        *        This may be equal to CopyStreamEvent.UNKNOWN_STREAM_SIZE if
        *        the size is unknown.
  -     ***/
  +     */
       public void bytesTransferred(long totalBytesTransferred,
                                    int bytesTransferred,
                                    long streamSize);
  
  
  
  1.3       +84 -80    jakarta-commons-sandbox/net/src/java/org/apache/commons/io/DotTerminatedMessageReader.java
  
  Index: DotTerminatedMessageReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/net/src/java/org/apache/commons/io/DotTerminatedMessageReader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DotTerminatedMessageReader.java	12 Apr 2002 04:42:45 -0000	1.2
  +++ DotTerminatedMessageReader.java	13 Apr 2002 04:55:00 -0000	1.3
  @@ -58,7 +58,7 @@
   import java.io.PushbackReader;
   import java.io.Reader;
   
  -/***
  +/**
    * DotTerminatedMessageReader is a class used to read messages from a
    * server that are terminated by a single dot followed by a 
    * &lt;CR&gt;&lt;LF&gt;
  @@ -70,126 +70,133 @@
    * of lines starting with a period, converts NETASCII newlines to the
    * local line separator format, truncates the end of message indicator,
    * and ensures you cannot read past the end of the message.
  - * <p>
  - * <p>
  - * @author Daniel F. Savarese
  - ***/
  -
  + * @author <a href="mailto:savarese@apache.org">Daniel F. Savarese</a>
  + * @version $Id: DotTerminatedMessageReader.java,v 1.3 2002/04/13 04:55:00 brekke Exp $
  + */
   public final class DotTerminatedMessageReader extends Reader
   {
  -    private static final String __lineSeparator;
  -    private static final char[] __lineSeparatorChars;
  +    private static final String LS;
  +    private static final char[] LS_CHARS;
   
  -    static {
  -        __lineSeparator = System.getProperty("line.separator");
  -        __lineSeparatorChars = __lineSeparator.toCharArray();
  +    static
  +    {
  +        LS = System.getProperty("line.separator");
  +        LS_CHARS = LS.toCharArray();
       }
   
  -    private boolean __atBeginning, __eof;
  -    private int __pos;
  -    private char[] __buffer;
  -    private PushbackReader __in;
  +    private boolean atBeginning;
  +    private boolean eof;
  +    private int pos;
  +    private char[] internalBuffer;
  +    private PushbackReader internalReader;
   
  -    /***
  +    /**
        * Creates a DotTerminatedMessageReader that wraps an existing Reader
        * input source.
  -     * <p>
        * @param reader  The Reader input source containing the message.
  -     ***/
  +     */
       public DotTerminatedMessageReader(Reader reader)
       {
           super(reader);
  -        __buffer = new char[__lineSeparatorChars.length + 3];
  -        __pos = __buffer.length;
  +        internalBuffer = new char[LS_CHARS.length + 3];
  +        pos = internalBuffer.length;
           // Assumes input is at start of message
  -        __atBeginning = true;
  -        __eof = false;
  -        __in = new PushbackReader(reader);
  +        atBeginning = true;
  +        eof = false;
  +        internalReader = new PushbackReader(reader);
       }
   
  -
  -    /***
  +    /**
        * Reads and returns the next character in the message.  If the end of the
        * message has been reached, returns -1.  Note that a call to this method
        * may result in multiple reads from the underlying input stream to decode
        * the message properly (removing doubled dots and so on).  All of
        * this is transparent to the programmer and is only mentioned for
        * completeness.
  -     * <p>
        * @return The next character in the message. Returns -1 if the end of the
        *          message has been reached.
        * @exception IOException If an error occurs while reading the underlying
        *            stream.
  -     ***/
  +     */
       public int read() throws IOException
       {
           int ch;
   
           synchronized (lock)
           {
  -            if (__pos < __buffer.length)
  -                return __buffer[__pos++];
  +            if (pos < internalBuffer.length)
  +            {
  +                return internalBuffer[pos++];
  +            }
   
  -            if (__eof)
  +            if (eof)
  +            {
                   return -1;
  +            }
   
  -            if ((ch = __in.read()) == -1)
  +            if ((ch = internalReader.read()) == -1)
               {
  -                __eof = true;
  +                eof = true;
                   return -1;
               }
   
  -            if (__atBeginning)
  +            if (atBeginning)
               {
  -                __atBeginning = false;
  +                atBeginning = false;
                   if (ch == '.')
                   {
  -                    ch = __in.read();
  +                    ch = internalReader.read();
   
                       if (ch != '.')
                       {
                           // read newline
  -                        __eof = true;
  -                        __in.read();
  +                        eof = true;
  +                        internalReader.read();
                           return -1;
                       }
                       else
  +                    {
                           return '.';
  +                    }
                   }
               }
   
               if (ch == '\r')
               {
  -                ch = __in.read();
  +                ch = internalReader.read();
   
                   if (ch == '\n')
                   {
  -                    ch = __in.read();
  +                    ch = internalReader.read();
   
                       if (ch == '.')
                       {
  -                        ch = __in.read();
  +                        ch = internalReader.read();
   
                           if (ch != '.')
                           {
                               // read newline and indicate end of file
  -                            __in.read();
  -                            __eof = true;
  +                            internalReader.read();
  +                            eof = true;
                           }
                           else
  -                            __buffer[--__pos] = (char)ch;
  +                        {
  +                            internalBuffer[--pos] = (char) ch;
  +                        }
                       }
                       else
  -                        __in.unread(ch);
  +                    {
  +                        internalReader.unread(ch);
  +                    }
   
  -                    __pos -= __lineSeparatorChars.length;
  -                    System.arraycopy(__lineSeparatorChars, 0, __buffer, __pos,
  -                                     __lineSeparatorChars.length);
  -                    ch = __buffer[__pos++];
  +                    pos -= LS_CHARS.length;
  +                    System.arraycopy(LS_CHARS, 0, internalBuffer, pos,
  +                                     LS_CHARS.length);
  +                    ch = internalBuffer[pos++];
                   }
                   else
                   {
  -                    __buffer[--__pos] = (char)ch;
  +                    internalBuffer[--pos] = (char) ch;
                       return '\r';
                   }
               }
  @@ -198,31 +205,27 @@
           }
       }
   
  -
  -    /***
  +    /**
        * Reads the next characters from the message into an array and
        * returns the number of characters read.  Returns -1 if the end of the
        * message has been reached.
  -     * <p>
        * @param buffer  The character array in which to store the characters.
        * @return The number of characters read. Returns -1 if the
        *          end of the message has been reached.
        * @exception IOException If an error occurs in reading the underlying
        *            stream.
  -     ***/
  +     */
       public int read(char[] buffer) throws IOException
       {
           return read(buffer, 0, buffer.length);
       }
   
  -
  -    /***
  +    /**
        * Reads the next characters from the message into an array and
        * returns the number of characters read.  Returns -1 if the end of the
        * message has been reached.  The characters are stored in the array
        * starting from the given offset and up to the length specified.
  -     * <p>
  -     * @param bufffer  The character array in which to store the characters.
  +     * @param buffer  The character array in which to store the characters.
        * @param offset   The offset into the array at which to start storing
        *              characters.
        * @param length   The number of characters to read.
  @@ -230,23 +233,25 @@
        *          end of the message has been reached.
        * @exception IOException If an error occurs in reading the underlying
        *            stream.
  -     ***/
  +     */
       public int read(char[] buffer, int offset, int length) throws IOException
       {
           int ch, off;
           synchronized (lock)
           {
               if (length < 1)
  +            {
                   return 0;
  -
  +            }
               if ((ch = read()) == -1)
  +            {
                   return -1;
  -
  +            }
               off = offset;
   
               do
               {
  -                buffer[offset++] = (char)ch;
  +                buffer[offset++] = (char) ch;
               }
               while (--length > 0 && (ch = read()) != -1);
   
  @@ -254,24 +259,21 @@
           }
       }
   
  -
  -    /***
  +    /**
        * Determines if the message is ready to be read.
  -     * <p>
        * @return True if the message is ready to be read, false if not.
        * @exception IOException If an error occurs while checking the underlying
        *            stream.
  -     ***/
  +     */
       public boolean ready() throws IOException
       {
           synchronized (lock)
           {
  -            return (__pos < __buffer.length || __in.ready());
  +            return (pos < internalBuffer.length || internalReader.ready());
           }
       }
   
  -
  -    /***
  +    /**
        * Closes the message for reading.  This doesn't actually close the
        * underlying stream.  The underlying stream may still be used for 
        * communicating with the server and therefore is not closed.
  @@ -282,27 +284,29 @@
        * for communicating with the server.  If you do not fully read
        * a message, you MUST close it, otherwise your program will likely
        * hang or behave improperly.
  -     * <p>
        * @exception IOException  If an error occurs while reading the
        *            underlying stream.
  -     ***/
  +     */
       public void close() throws IOException
       {
           synchronized (lock)
           {
  -            if (__in == null)
  -                return ;
  +            if (internalReader == null)
  +            {
  +                return;
  +            }
   
  -            if (!__eof)
  +            if (!eof)
  +            {
                   while (read() != -1)
  +                {
                       ;
  -
  -            __eof = true;
  -            __atBeginning = false;
  -            __pos = __buffer.length;
  -            __in = null;
  +                }
  +            }
  +            eof = true;
  +            atBeginning = false;
  +            pos = internalBuffer.length;
  +            internalReader = null;
           }
       }
  -
   }
  -
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>