commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commit-cp] classpath ChangeLog gnu/xml/stream/XMLParser.ja...


From: Chris Burdess
Subject: [commit-cp] classpath ChangeLog gnu/xml/stream/XMLParser.ja...
Date: Wed, 07 Jun 2006 13:06:12 +0000

CVSROOT:        /cvsroot/classpath
Module name:    classpath
Changes by:     Chris Burdess <dog>     06/06/07 13:06:11

Modified files:
        .              : ChangeLog 
        gnu/xml/stream : XMLParser.java 
Added files:
        gnu/classpath/debug: TeeInputStream.java TeeOutputStream.java 
                             TeeReader.java TeeWriter.java 

Log message:
        2006-06-07  Chris Burdess  <address@hidden>
        
                * gnu/classpath/debug/TeeInputStream.java,
                  gnu/classpath/debug/TeeOutputStream.java,
                  gnu/classpath/debug/TeeReader.java,
                  gnu/classpath/debug/TeeWriter.java: New classes for debugging 
streams.
                * gnu/xml/stream/XMLParser.java: Use tee streams for debugging. 
Don't
                  read more characters than absolutely necessary in tryRead 
method.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7693&r2=1.7694
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/classpath/debug/TeeInputStream.java?cvsroot=classpath&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/classpath/debug/TeeOutputStream.java?cvsroot=classpath&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/classpath/debug/TeeReader.java?cvsroot=classpath&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/classpath/debug/TeeWriter.java?cvsroot=classpath&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/xml/stream/XMLParser.java?cvsroot=classpath&r1=1.29&r2=1.30

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.7693
retrieving revision 1.7694
diff -u -b -r1.7693 -r1.7694
--- ChangeLog   7 Jun 2006 10:25:26 -0000       1.7693
+++ ChangeLog   7 Jun 2006 13:06:10 -0000       1.7694
@@ -1,3 +1,12 @@
+2006-06-07  Chris Burdess  <address@hidden>
+
+       * gnu/classpath/debug/TeeInputStream.java,
+         gnu/classpath/debug/TeeOutputStream.java,
+         gnu/classpath/debug/TeeReader.java,
+         gnu/classpath/debug/TeeWriter.java: New classes for debugging streams.
+       * gnu/xml/stream/XMLParser.java: Use tee streams for debugging. Don't
+         read more characters than absolutely necessary in tryRead method.
+
 2006-06-07  Robert Schuster  <address@hidden>
 
        * examples/gnu/classpath/examples/swing/Demo.java:

Index: gnu/xml/stream/XMLParser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/xml/stream/XMLParser.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- gnu/xml/stream/XMLParser.java       7 Jun 2006 08:04:49 -0000       1.29
+++ gnu/xml/stream/XMLParser.java       7 Jun 2006 13:06:11 -0000       1.30
@@ -56,6 +56,8 @@
 import java.io.BufferedInputStream;
 import java.io.EOFException;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
@@ -86,6 +88,8 @@
 import javax.xml.stream.XMLStreamReader;
 
 import gnu.java.net.CRLFInputStream;
+import gnu.classpath.debug.TeeInputStream;
+import gnu.classpath.debug.TeeReader;
 
 /**
  * An XML parser.
@@ -420,6 +424,21 @@
         ids = new HashSet();
         idrefs = new HashSet();
       }
+    String debug = System.getProperty("gnu.xml.debug.input");
+    if (debug != null)
+      {
+        try
+          {
+            File file = File.createTempFile(debug, ".xml");
+            in = new TeeInputStream(in, new FileOutputStream(file));
+          }
+        catch (IOException e)
+          {
+            RuntimeException e2 = new RuntimeException();
+            e2.initCause(e);
+            throw e2;
+          }
+      }
     pushInput(new Input(in, null, null, systemId, null, null, false, true));
   }
 
@@ -479,6 +498,21 @@
         ids = new HashSet();
         idrefs = new HashSet();
       }
+    String debug = System.getProperty("gnu.xml.debug.input");
+    if (debug != null)
+      {
+        try
+          {
+            File file = File.createTempFile(debug, ".xml");
+            reader = new TeeReader(reader, new FileWriter(file));
+          }
+        catch (IOException e)
+          {
+            RuntimeException e2 = new RuntimeException();
+            e2.initCause(e);
+            throw e2;
+          }
+      }
     pushInput(new Input(null, reader, null, systemId, null, null, false, 
true));
   }
 
@@ -1332,6 +1366,15 @@
         return false;
       }
     count += l2;
+    // check the characters we received first before doing additional reads
+    for (int i = 0; i < count; i++)
+      {
+        if (chars[i] != tmpBuf[i])
+          {
+            reset();
+            return false;
+          }
+      }
     while (count < len)
       {
         // force read
@@ -1341,15 +1384,14 @@
             reset();
             return false;
           }
-        tmpBuf[count++] = (char) c;
-      }
-    for (int i = 0; i < len; i++)
-      {
-        if (chars[i] != tmpBuf[i])
+        tmpBuf[count] = (char) c;
+        // check each character as it is read
+        if (chars[count] != tmpBuf[count])
           {
             reset();
             return false;
           }
+        count++;
       }
     return true;
   }
@@ -5073,7 +5115,6 @@
     void mark(int len)
       throws IOException
     {
-      //System.out.println("  mark:"+len);
       markOffset = offset;
       markLine = line;
       markColumn = column;
@@ -5116,7 +5157,9 @@
     {
       int ret;
       if (unicodeReader != null)
+        {
         ret = unicodeReader.read(b, off, len);
+        }
       else
         {
           byte[] b2 = new byte[len];

Index: gnu/classpath/debug/TeeInputStream.java
===================================================================
RCS file: gnu/classpath/debug/TeeInputStream.java
diff -N gnu/classpath/debug/TeeInputStream.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/debug/TeeInputStream.java     7 Jun 2006 13:06:11 -0000       
1.1
@@ -0,0 +1,98 @@
+/* TeeInputStream.java
+   Copyright (C) 2006  Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under terms
+of your choice, provided that you also meet, for each linked independent
+module, the terms and conditions of the license of that module.  An
+independent module is a module which is not derived from or based on
+this library.  If you modify this library, you may extend this exception
+to your version of the library, but you are not obligated to do so.  If
+you do not wish to do so, delete this exception statement from your
+version.  */
+
+package gnu.classpath.debug;
+
+import java.io.*;
+
+/**
+ * An input stream that copies all its input to a byte sink.
+ *
+ * @author Chris Burdess
+ */
+public class TeeInputStream
+  extends InputStream
+{
+
+  private final InputStream in;
+  private final OutputStream out;
+
+  /**
+   * Constructs a tee input stream.
+   * @param in the underlying input stream
+   * @param out the output sink
+   */
+  public TeeInputStream(InputStream in, OutputStream out)
+  {
+    this.in = in;
+    this.out = out;
+  }
+
+  public int read()
+    throws IOException
+  {
+    int ret = in.read();
+    out.write(ret);
+    out.flush();
+    return ret;
+  }
+
+  public int read(byte[] b, int off, int len)
+    throws IOException
+  {
+    int ret = in.read(b, off, len);
+    if (ret != -1)
+      {
+        out.write(b, off, ret);
+        out.flush();
+      }
+    return ret;
+  }
+
+  public void close()
+    throws IOException
+  {
+    in.close();
+    out.close();
+  }
+
+  public final boolean markSupported()
+  {
+    return false;
+  }
+  
+}

Index: gnu/classpath/debug/TeeOutputStream.java
===================================================================
RCS file: gnu/classpath/debug/TeeOutputStream.java
diff -N gnu/classpath/debug/TeeOutputStream.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/debug/TeeOutputStream.java    7 Jun 2006 13:06:11 -0000       
1.1
@@ -0,0 +1,93 @@
+/* TeeOutputStream.java
+   Copyright (C) 2006  Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under terms
+of your choice, provided that you also meet, for each linked independent
+module, the terms and conditions of the license of that module.  An
+independent module is a module which is not derived from or based on
+this library.  If you modify this library, you may extend this exception
+to your version of the library, but you are not obligated to do so.  If
+you do not wish to do so, delete this exception statement from your
+version.  */
+
+package gnu.classpath.debug;
+
+import java.io.*;
+
+/**
+ * An output stream that copies all its output to an additional byte sink.
+ *
+ * @author Chris Burdess
+ */
+public class TeeOutputStream
+  extends OutputStream
+{
+
+  private final OutputStream out;
+  private final OutputStream sink;
+
+  /**
+   * Constructs a tee output stream.
+   * @param out the underlying output stream
+   * @param sink the output sink
+   */
+  public TeeOutputStream(OutputStream out, OutputStream sink)
+  {
+    this.out = out;
+    this.sink = sink;
+  }
+
+  public void write(int c)
+    throws IOException
+  {
+    out.write(c);
+    sink.write(c);
+  }
+
+  public void write(byte[] b, int off, int len)
+    throws IOException
+  {
+    out.write(b, off, len);
+    sink.write(b, off, len);
+  }
+
+  public void flush()
+    throws IOException
+  {
+    out.flush();
+    sink.flush();
+  }
+
+  public void close()
+    throws IOException
+  {
+    out.close();
+    sink.close();
+  }
+
+}

Index: gnu/classpath/debug/TeeReader.java
===================================================================
RCS file: gnu/classpath/debug/TeeReader.java
diff -N gnu/classpath/debug/TeeReader.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/debug/TeeReader.java  7 Jun 2006 13:06:11 -0000       1.1
@@ -0,0 +1,98 @@
+/* TeeReader.java
+   Copyright (C) 2006  Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under terms
+of your choice, provided that you also meet, for each linked independent
+module, the terms and conditions of the license of that module.  An
+independent module is a module which is not derived from or based on
+this library.  If you modify this library, you may extend this exception
+to your version of the library, but you are not obligated to do so.  If
+you do not wish to do so, delete this exception statement from your
+version.  */
+
+package gnu.classpath.debug;
+
+import java.io.*;
+
+/**
+ * A reader that copies all characters read to an output sink.
+ *
+ * @author Chris Burdess
+ */
+public class TeeReader
+  extends Reader
+{
+
+  private final Reader in;
+  private final Writer out;
+
+  /**
+   * Constructs a tee reader.
+   * @param in the input
+   * @param out the output sink
+   */
+  public TeeReader(Reader in, Writer out)
+  {
+    this.in = in;
+    this.out = out;
+  }
+
+  public int read()
+    throws IOException
+  {
+    int ret = in.read();
+    out.write(ret);
+    out.flush();
+    return ret;
+  }
+
+  public int read(char[] b, int off, int len)
+    throws IOException
+  {
+    int ret = in.read(b, off, len);
+    if (ret != -1)
+      {
+        out.write(b, off, ret);
+        out.flush();
+      }
+    return ret;
+  }
+
+  public void close()
+    throws IOException
+  {
+    in.close();
+    out.close();
+  }
+
+  public final boolean markSupported()
+  {
+    return false;
+  }
+  
+}

Index: gnu/classpath/debug/TeeWriter.java
===================================================================
RCS file: gnu/classpath/debug/TeeWriter.java
diff -N gnu/classpath/debug/TeeWriter.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/classpath/debug/TeeWriter.java  7 Jun 2006 13:06:11 -0000       1.1
@@ -0,0 +1,93 @@
+/* TeeWriter.java
+   Copyright (C) 2006  Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under terms
+of your choice, provided that you also meet, for each linked independent
+module, the terms and conditions of the license of that module.  An
+independent module is a module which is not derived from or based on
+this library.  If you modify this library, you may extend this exception
+to your version of the library, but you are not obligated to do so.  If
+you do not wish to do so, delete this exception statement from your
+version.  */
+
+package gnu.classpath.debug;
+
+import java.io.*;
+
+/**
+ * A writer that copies all its output to an additional character sink.
+ *
+ * @author Chris Burdess
+ */
+public class TeeWriter
+  extends Writer
+{
+
+  private final Writer out;
+  private final Writer sink;
+
+  /**
+   * Constructs a tee writer.
+   * @param out the underlying writer
+   * @param sink the output sink
+   */
+  public TeeWriter(Writer out, Writer sink)
+  {
+    this.out = out;
+    this.sink = sink;
+  }
+
+  public void write(int c)
+    throws IOException
+  {
+    out.write(c);
+    sink.write(c);
+  }
+
+  public void write(char[] b, int off, int len)
+    throws IOException
+  {
+    out.write(b, off, len);
+    sink.write(b, off, len);
+  }
+
+  public void flush()
+    throws IOException
+  {
+    out.flush();
+    sink.flush();
+  }
+
+  public void close()
+    throws IOException
+  {
+    out.close();
+    sink.close();
+  }
+
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]