commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trei...@apache.org
Subject cvs commit: jakarta-commons-sandbox/id/src/java/org/apache/commons/id/uuid/state ReadOnlyResourceStateImpl.java
Date Mon, 31 May 2004 06:58:55 GMT
treilly     2004/05/30 23:58:55

  Modified:    id/src/java/org/apache/commons/id/uuid/state
                        ReadOnlyResourceStateImpl.java
  Log:
  try..catch same line, close input stream, IOException compat for jdk1.5
  
  Revision  Changes    Path
  1.4       +28 -25    jakarta-commons-sandbox/id/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java
  
  Index: ReadOnlyResourceStateImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/id/src/java/org/apache/commons/id/uuid/state/ReadOnlyResourceStateImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReadOnlyResourceStateImpl.java	28 Apr 2004 03:05:06 -0000	1.3
  +++ ReadOnlyResourceStateImpl.java	31 May 2004 06:58:55 -0000	1.4
  @@ -16,6 +16,7 @@
   
   package org.apache.commons.id.uuid.state;
   
  +import java.io.IOException;
   import java.io.InputStream;
   import java.util.HashSet;
   import java.util.Set;
  @@ -45,7 +46,6 @@
       /** How often to write to stable storage - since this is read-only make it largest.
*/
       static long synchronizeInterval = Long.MAX_VALUE;
   
  -
       /** Collection of nodes to load or store. */
       static HashSet nodes = new HashSet();
   
  @@ -94,13 +94,24 @@
           }
   
           // Load the resource
  -        InputStream in = ClassLoader.getSystemResourceAsStream(resourceName);
  -        if (in == null) {
  -            throw new IllegalStateException(resourceName + " loaded as system resource
is null");
  -        }
  +        InputStream in = null;
  +        try {
  +            in = ClassLoader.getSystemResourceAsStream(resourceName);
  +            if (in == null) {
  +                throw new IllegalStateException(resourceName + " loaded as system resource
is null");
  +            }
   
  -        //Do the XML parsing
  -        parse(in);
  +            //Do the XML parsing
  +            parse(in);
  +        } catch (Throwable e) {
  +            throw new IllegalStateException(e.getMessage());
  +        } finally {
  +            try {
  +                in.close();
  +            } catch (IOException ioe) {
  +                //Nothing to do at this point.
  +            }
  +        }
       }
   
       /**
  @@ -121,7 +132,7 @@
       /**
        * @see org.apache.commons.id.uuid.state.State#store(java.util.Collection)
        */
  -    public void store(Set nodeSet) {
  +    public void store(Set nodeSet) throws IOException {
           // Nothing to do - this is a ReadOnly implementation.
           return;
       }
  @@ -147,8 +158,7 @@
           try {
               SAXParser parser = saxFactory.newSAXParser();
               parser.parse(in, handler);
  -        }
  -        catch (Throwable t) {
  +        } catch (Throwable t) {
               return;
           }
       }
  @@ -193,8 +203,7 @@
               }
               if (element.equalsIgnoreCase(UUID_STATE_TAG_STR)) {
                   currentTag = UUID_STATE_TAG;
  -            }
  -            else if (element.equalsIgnoreCase(NODE_TAG_STR)) {
  +            } else if (element.equalsIgnoreCase(NODE_TAG_STR)) {
                   currentTag = NODE_TAG;
               }
               //Process attributes
  @@ -227,8 +236,7 @@
                   if (attributeName.equalsIgnoreCase(SYNCH_INTERVAL_STR)) {
                       try {
                           synchronizeInterval = Long.parseLong(attributeValue);
  -                    }
  -                    catch (NumberFormatException nfe) {
  +                    } catch (NumberFormatException nfe) {
                           synchronizeInterval = 0;
                       }
                   }
  @@ -253,20 +261,16 @@
   
                   if (attributeName.equalsIgnoreCase(ATTR_ID_STR)) {
                       node = StateHelper.decodeMACAddress(attributeValue);
  -                }
  -                else if (attributeName.equalsIgnoreCase(ATTR_CLOCKSEQ_STR)) {
  +                } else if (attributeName.equalsIgnoreCase(ATTR_CLOCKSEQ_STR)) {
                       try {
                           lastClockSeq = Short.parseShort(attributeValue);
  -                    }
  -                    catch (NumberFormatException nfe) {
  +                    } catch (NumberFormatException nfe) {
                           lastClockSeq = 0;
                       }
  -                }
  -                else if ( attributeName.equalsIgnoreCase(ATTR_LASTIMESTAMP_STR)) {
  +                } else if ( attributeName.equalsIgnoreCase(ATTR_LASTIMESTAMP_STR)) {
                       try {
                           lastTS = Long.parseLong(attributeValue);
  -                    }
  -                    catch (NumberFormatException nfe) {
  +                    } catch (NumberFormatException nfe) {
                           lastTS = 0;
                       }
                   }
  @@ -274,8 +278,7 @@
               if (node != null) {
                   if (lastClockSeq != 0) {
                       nodes.add(new Node(node, lastTS, lastClockSeq));
  -                }
  -                else {
  +                } else {
                       nodes.add(new Node(node));
                   }
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message