OSDN Git Service

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3257 ae02f08e...
authorleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Thu, 23 Apr 2009 05:10:35 +0000 (05:10 +0000)
committerleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Thu, 23 Apr 2009 05:10:35 +0000 (05:10 +0000)
src/main/java/org/xerial/silk/SilkPullParser.java

index ed4c97c..0bc9653 100644 (file)
@@ -29,9 +29,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.net.URL;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -43,7 +45,6 @@ import org.xerial.core.XerialError;
 import org.xerial.core.XerialErrorCode;
 import org.xerial.core.XerialException;
 import org.xerial.silk.impl.SilkDataLine;
-import org.xerial.silk.impl.SilkElement;
 import org.xerial.silk.impl.SilkFunction;
 import org.xerial.silk.impl.SilkLexer;
 import org.xerial.silk.impl.SilkNode;
@@ -74,32 +75,13 @@ public class SilkPullParser
 
     private ArrayBlockingQueue<SilkEvent> eventQueue = new ArrayBlockingQueue<SilkEvent>(eventQueueMax);
 
-    /**
-     * SilkEvents
-     * 
-     * @author leo
-     * 
-     */
-    private static class EventItem
-    {
-        SilkEventType event;
-        SilkElement element;
-
-        public EventItem(SilkEventType event, SilkElement element)
-        {
-            this.event = event;
-            this.element = element;
-        }
+    private ExecutorService threadPool;
 
-        public EventItem(SilkEventType event)
-        {
-            this.event = event;
-            this.element = null;
-        }
+    public SilkPullParser(URL resourceUrl) throws IOException
+    {
+        this(resourceUrl.openStream());
     }
 
-    private ExecutorService threadPool;
-
     public SilkPullParser(InputStream input) throws IOException
     {
         this(new InputStreamReader(input));
@@ -297,7 +279,13 @@ public class SilkPullParser
 
         try
         {
-            prefetchedEventQueue.addLast(eventQueue.take());
+            SilkEvent e = null;
+            while (!foundEOF && (e = eventQueue.poll(1, TimeUnit.MILLISECONDS)) == null)
+            {
+
+            }
+            if (e != null)
+                prefetchedEventQueue.addLast(e);
         }
         catch (InterruptedException e)
         {
@@ -311,12 +299,19 @@ public class SilkPullParser
         if (!prefetchedEventQueue.isEmpty())
             return prefetchedEventQueue.removeFirst();
 
-        if (foundEOF && eventQueue.isEmpty())
-            return null;
+        if (foundEOF)
+            return eventQueue.poll();
 
         try
         {
-            prefetchedEventQueue.addLast(eventQueue.take());
+
+            SilkEvent e = null;
+            while (!foundEOF && (e = eventQueue.poll(1, TimeUnit.MILLISECONDS)) == null)
+            {
+
+            }
+            if (e != null)
+                prefetchedEventQueue.addLast(e);
         }
         catch (InterruptedException e1)
         {