From d5df6489a078a3f871b0b3fcdb5f1b320a88b762 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 23 Apr 2009 05:10:35 +0000 Subject: [PATCH] git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3257 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- src/main/java/org/xerial/silk/SilkPullParser.java | 51 ++++++++++------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/xerial/silk/SilkPullParser.java b/src/main/java/org/xerial/silk/SilkPullParser.java index ed4c97c..0bc9653 100644 --- a/src/main/java/org/xerial/silk/SilkPullParser.java +++ b/src/main/java/org/xerial/silk/SilkPullParser.java @@ -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 eventQueue = new ArrayBlockingQueue(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) { -- 2.11.0