harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r449310 - /incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/
Date Sat, 23 Sep 2006 21:38:53 GMT
Author: ndbeyer
Date: Sat Sep 23 14:38:52 2006
New Revision: 449310

URL: http://svn.apache.org/viewvc?view=rev&rev=449310
Log:
Cleanup code; remove compiler warnings, etc

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ConsoleHandler.java
Sat Sep 23 14:38:52 2006
@@ -55,6 +55,7 @@
      * Closes this handler. The <code>System.err</code> is flushed but not
      * closed.
      */
+    @Override
     public void close() {
         super.close(false);
     }
@@ -64,6 +65,7 @@
      * 
      * @param record the log record to be logged
      */
+    @Override
     public void publish(LogRecord record) {
         super.publish(record);
         super.flush();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
Sat Sep 23 14:38:52 2006
@@ -13,7 +13,6 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 import java.io.BufferedOutputStream;
@@ -121,7 +120,7 @@
      * ---------------------------------------------
      */
     //maintain all file locks hold by this process
-    private static Hashtable<String, FileLock> allLocks = new Hashtable<String,
FileLock>();
+    private static final Hashtable<String, FileLock> allLocks = new Hashtable<String,
FileLock>();
 
     /*
      * ---------------------------------------------
@@ -560,6 +559,7 @@
      * 				and other permission like <code>FilePermission("write")</code>, 
      * 				etc.
      */
+    @Override
     public void close() {
         //release locks
         super.close();
@@ -576,6 +576,7 @@
      * 
      * @param record the log record to be published
      */
+    @Override
     public void publish(LogRecord record) {
         super.publish(record);
         flush();
@@ -608,25 +609,30 @@
             this(stream, 0);
         }
 
+        @Override
         public void write(int oneByte) throws IOException {
             wrapped.write(oneByte);
             length++;
         }
 
+        @Override
         public void write(byte[] bytes) throws IOException {
             wrapped.write(bytes);
             length += bytes.length;
         }
 
+        @Override
         public void write(byte[] b, int off, int len) throws IOException {
             wrapped.write(b, off, len);
             length += len;
         }
 
+        @Override
         public void close() throws IOException {
             wrapped.close();
         }
 
+        @Override
         public void flush() throws IOException {
             wrapped.flush();
         }
@@ -642,5 +648,3 @@
     }
 
 }
-
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogRecord.java
Sat Sep 23 14:38:52 2006
@@ -13,7 +13,6 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 import java.io.IOException;
@@ -45,12 +44,6 @@
 public class LogRecord implements Serializable {
 
     private static final long serialVersionUID = 5372048053134512534L;
-    
-    /*
-     * -------------------------------------------------------------------
-     * Constants
-     * -------------------------------------------------------------------
-     */
 
     // The major byte used in serialization.
     private static final int MAJOR = 1;
@@ -58,12 +51,6 @@
     // The minor byte used in serialization.
     private static final int MINOR = 4;
 
-    /*
-     * ------------------------------------------------------------------- Class
-     * variables
-     * -------------------------------------------------------------------
-     */
-
     // Store the current value for the sequence number.
     private static long currentSequenceNumber = 0;
 
@@ -73,12 +60,6 @@
     // The base id as the starting point for thread ID allocation.
     private static int initThreadId = 0;
 
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
     /**
      * The logging level.
      * 
@@ -156,13 +137,7 @@
     private transient Object[] parameters;
 
     // If the source method and source class has been initialized
-    private transient boolean sourceInited = false;
-
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
+    private transient boolean sourceInited;
 
     /**
      * Constructs a <code>LogRecord</code> object using the supplied the
@@ -187,12 +162,12 @@
 
         synchronized (LogRecord.class) {
             this.sequenceNumber = currentSequenceNumber++;
-            Object id = currentThreadId.get();
+            Integer id = currentThreadId.get();
             if (null == id) {
                 this.threadID = initThreadId;
-                currentThreadId.set(new Integer(initThreadId++));
+                currentThreadId.set(Integer.valueOf(initThreadId++));
             } else {
-                this.threadID = ((Integer) id).intValue();
+                this.threadID = id.intValue();
             }
         }
 
@@ -205,12 +180,6 @@
         this.thrown = null;
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Gets the logging level.
      * 
@@ -526,4 +495,3 @@
         }
     }
 }
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/MemoryHandler.java
Sat Sep 23 14:38:52 2006
@@ -13,7 +13,6 @@
  * limitations under the License.
  */
 
-
 package java.util.logging;
 
 import java.security.AccessController;
@@ -66,38 +65,25 @@
  */
 public class MemoryHandler extends Handler {
 
-    /*
-     * ------------------------------------
-     * consts
-     * ------------------------------------
-     */
     //default maximum buffered number of LogRecord 
     private static final int DEFAULT_SIZE = 1000;
-    //default push level
-    private static final Level DEFAULT_PUSH = Level.SEVERE;
-    
-    /*
-     * ------------------------------------
-     * instance variables
-     * ------------------------------------
-     */
     //target handler
-    private Handler target = null;
+    private Handler target;
     
     //buffer size
     private int size = DEFAULT_SIZE;
     
     //push level
-    private Level push = DEFAULT_PUSH;
+    private Level push = Level.SEVERE;
 
     //LogManager instance for convenience
-    private LogManager manager = LogManager.getLogManager();
+    private final LogManager manager = LogManager.getLogManager();
     
     //buffer
-    private LogRecord[] buffer = null;
+    private LogRecord[] buffer;
     
     //current position in buffer
-    private int cursor = 0;
+    private int cursor;
     
     /**
      * Default constructor, construct and init a <code>MemoryHandler</code> using

@@ -184,6 +170,7 @@
      * 				if security manager exists and it determines that caller 
      * 				does not have the required permissions to control this handler
      */
+    @Override
     public void close() {
         manager.checkAccess();
         target.close();
@@ -196,6 +183,7 @@
      * Note that this doesn't cause this <code>MemoryHandler</code> to push.
      * 
      */
+    @Override
     public void flush() {
         target.flush();
     }
@@ -210,6 +198,7 @@
      * 
      * @param record the log record.
      */
+    @Override
     public void publish(LogRecord record) {
         if (!isLoggable(record)) {
             return;
@@ -248,6 +237,7 @@
      * 				the given <code>LogRecord</code>
      * @return 		if the given <code>LogRecord</code> should be logged
      */
+    @Override
     public boolean isLoggable(LogRecord record) {
         return super.isLoggable(record);
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SimpleFormatter.java
Sat Sep 23 14:38:52 2006
@@ -28,13 +28,6 @@
  * 
  */
 public class SimpleFormatter extends Formatter {
-
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Constructs a <code>SimpleFormatter</code> object.
      */
@@ -42,14 +35,9 @@
         super();
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods overriding parent class Formatter
-     * -------------------------------------------------------------------
-     */
-
+    @Override
     public String format(LogRecord r) {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append(MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
                 new Object[] { new Date(r.getMillis()) }));
         sb.append(r.getLevel().getName()).append(" "); //$NON-NLS-1$

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/SocketHandler.java
Sat Sep 23 14:38:52 2006
@@ -57,34 +57,15 @@
  * 
  */
 public class SocketHandler extends StreamHandler {
-
-    /*
-     * -------------------------------------------------------------------
-     * Constants
-     * -------------------------------------------------------------------
-     */
-
     // default level
     private static final String DEFAULT_LEVEL = "ALL"; //$NON-NLS-1$
 
     // default formatter
     private static final String DEFAULT_FORMATTER = "java.util.logging.XMLFormatter"; //$NON-NLS-1$
 
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
     // the socket connection
     private Socket socket;
 
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Constructs a <code>SocketHandler</code> object using the properties
      * read by the log manager, including the host name and port number.
@@ -127,12 +108,6 @@
         initSocket(host, String.valueOf(port));
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     // Initialize the socket connection and prepare the output stream
     private void initSocket(String host, String port) throws IOException {
         // check the validity of the host name
@@ -172,6 +147,7 @@
      *             If a security manager determines that the caller does not
      *             have the required permission to control this handler.
      */
+    @Override
     public void close() {
         try {
             super.close();
@@ -180,7 +156,7 @@
 	            this.socket = null;
             }
         } catch (Exception e) {
-            // logging.F=Exception occured when closing the socket handler.
+            // logging.F=Exception occurred when closing the socket handler.
             getErrorManager().error(Messages.getString("logging.F"), e, //$NON-NLS-1$
                     ErrorManager.CLOSE_FAILURE);
         }
@@ -192,11 +168,10 @@
      * @param record
      *            the log record to be logged
      */
+    @Override
     public void publish(LogRecord record) {
         super.publish(record);
         super.flush();
     }
 
 }
-
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/StreamHandler.java
Sat Sep 23 14:38:52 2006
@@ -51,13 +51,6 @@
  * 
  */
 public class StreamHandler extends Handler {
-
-    /*
-     * -------------------------------------------------------------------
-     * Instance variables
-     * -------------------------------------------------------------------
-     */
-
     // the output stream this handler writes to
     private OutputStream os;
 
@@ -67,12 +60,6 @@
     // the flag indicating whether the writer has been initialized
     private boolean writerNotInitialized;
 
-    /*
-     * -------------------------------------------------------------------
-     * Constructors
-     * -------------------------------------------------------------------
-     */
-
     /**
      * Constructs a <code>StreamHandler</code> object. The new stream handler
      * does not have an associated output stream.
@@ -97,7 +84,7 @@
         this.os = os;
     }
 
-    /*
+    /**
      * Constructs a <code>StreamHandler</code> object. Specified default
      * values will be used if the corresponding properties are found in log
      * manager's properties.
@@ -134,12 +121,6 @@
         internalSetFormatter(formatter);
     }
 
-    /*
-     * -------------------------------------------------------------------
-     * Methods
-     * -------------------------------------------------------------------
-     */
-
     // initialize the writer
     private void initializeWritter() {
         this.writerNotInitialized = false;
@@ -214,6 +195,7 @@
      * @throws UnsupportedEncodingException
      *             If the specified encoding is not supported by the runtime.
      */
+    @Override
     public void setEncoding(String encoding) throws SecurityException,
             UnsupportedEncodingException {
 		//flush first before set new encoding
@@ -231,6 +213,7 @@
                      * Should not happen because it's checked in
                      * super.initProperties().
                      */
+                    throw new AssertionError(e);
                 }
             }
         }
@@ -274,6 +257,7 @@
      *             If a security manager determines that the caller does not
      *             have the required permission.
      */
+    @Override
     public void close() {
         LogManager.getLogManager().checkAccess();
         close(true);
@@ -282,6 +266,7 @@
     /**
      * Flushes any buffered output.
      */
+    @Override
     public void flush() {
         if (null != this.os) {
             try {
@@ -315,6 +300,7 @@
      * @param record
      *            the log record to be logged
      */
+    @Override
     public void publish(LogRecord record) {
         try {
             if (this.isLoggable(record)) {
@@ -348,6 +334,7 @@
      * @return <code>true</code> if the supplied log record need to be logged,
      *         otherwise <code>false</code>
      */
+    @Override
     public boolean isLoggable(LogRecord record) {
     	if (null == record) {
 			return false;
@@ -359,5 +346,3 @@
     }
 
 }
-
-

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java?view=diff&rev=449310&r1=449309&r2=449310
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/XMLFormatter.java
Sat Sep 23 14:38:52 2006
@@ -32,23 +32,11 @@
  */
 public class XMLFormatter extends Formatter {
 
-    /*
-     * ---------------------------------------
-     * Constants
-     * ---------------------------------------
-     */
-
     private static final String lineSeperator = LogManager
             .getSystemLineSeparator();
 
     private static final String indent = "    "; //$NON-NLS-1$
 
-    /*
-     * ---------------------------------------
-     * Constructor
-     * ---------------------------------------
-     */
-
     /**
      * Default constructor
      */
@@ -56,17 +44,13 @@
         super();
     }
 
-    /*
-     * ---------------------------------------
-     * Abstract method implementation of Formatter  
-     * ---------------------------------------
-     */
     /**
      * Format a <code>LogRecord</code> into string which represents XML 
      * 
      * @param r the given LogRecord instance to be formatted
      * @return string which represents XML 
      */
+    @Override
     public String format(LogRecord r) {
         //call a method of LogRecord to ensure not null
         long time = r.getMillis();
@@ -74,7 +58,7 @@
         String date = MessageFormat.format("{0, date} {0, time}", //$NON-NLS-1$
                 new Object[] { new Date(time) });
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append(("<record>")).append(lineSeperator); //$NON-NLS-1$
         sb.append(indent).append(("<date>")).append(date).append(("</date>"))
//$NON-NLS-1$ //$NON-NLS-2$
                 .append(lineSeperator);
@@ -103,8 +87,8 @@
         formatMessages(r, sb);
         Object[] params;
         if ((params = r.getParameters()) != null) {
-            for (int i = 0; i < params.length; i++) {
-                sb.append(indent).append(("<param>")).append(params[i]).append( //$NON-NLS-1$
+            for (Object element : params) {
+                sb.append(indent).append(("<param>")).append(element).append( //$NON-NLS-1$
                         ("</param>")).append(lineSeperator); //$NON-NLS-1$
             }
         }
@@ -113,13 +97,7 @@
         return sb.toString();
     }
 
-    /*
-     * ---------------------------------------
-     * Methods override Formatter 
-     * ---------------------------------------
-     */
-
-    private void formatMessages(LogRecord r, StringBuffer sb) {
+    private void formatMessages(LogRecord r, StringBuilder sb) {
         //get localized message if has, but don't call Formatter.formatMessage to parse pattern
string
         ResourceBundle rb = r.getResourceBundle();
         String pattern = r.getMessage();
@@ -152,7 +130,7 @@
         }
     }
 
-    private void formatThrowable(LogRecord r, StringBuffer sb) {
+    private void formatThrowable(LogRecord r, StringBuilder sb) {
         Throwable t;
         if ((t = r.getThrown()) != null) {
             sb.append(indent).append("<exception>").append(lineSeperator); //$NON-NLS-1$
@@ -160,8 +138,7 @@
                     t.toString()).append("</message>").append(lineSeperator); //$NON-NLS-1$
             //format throwable's stack trace
             StackTraceElement[] elements = t.getStackTrace();
-            for (int i = 0; i < elements.length; i++) {
-                StackTraceElement e = elements[i];
+            for (StackTraceElement e : elements) {
                 sb.append(indent).append(indent).append("<frame>").append( //$NON-NLS-1$
                         lineSeperator);
                 sb.append(indent).append(indent).append(indent).append(
@@ -187,6 +164,7 @@
      * @param h the given handler
      * @return the header string for XML
      */
+    @Override
     public String getHead(Handler h) {
         String encoding = null;
         if(null != h) {
@@ -195,7 +173,7 @@
         if (null == encoding) {
             encoding = getSystemProperty("file.encoding"); //$NON-NLS-1$
         }
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append("<?xml version=\"1.0\" encoding=\"").append(encoding).append( //$NON-NLS-1$
                 "\" standalone=\"no\"?>").append(lineSeperator); //$NON-NLS-1$
         sb.append("<!DOCTYPE log SYSTEM \"logger.dtd\">").append(lineSeperator); //$NON-NLS-1$
@@ -209,13 +187,14 @@
      * @param h the given handler
      * @return the tail string for XML
      */
+    @Override
     public String getTail(Handler h) {
         return "</log>"; //$NON-NLS-1$
     }
 
     //use privilege code to get system property
     private static String getSystemProperty(final String key) {
-        return (String) AccessController.doPrivileged(
+        return AccessController.doPrivileged(
           new PrivilegedAction<String>() {
             public String run() {
                 return System.getProperty(key);



Mime
View raw message