[armedbear-cvs] r11419 - branches/open-external-format/src/org/armedbear/lisp

Erik Huelsmann ehuelsmann at common-lisp.net
Fri Dec 5 22:58:22 UTC 2008


Author: ehuelsmann
Date: Fri Dec  5 22:58:19 2008
New Revision: 11419

Log:
Make one variable out of reader and pushbackReader: they need to point to the exact same stream anyway.

Modified:
   branches/open-external-format/src/org/armedbear/lisp/Stream.java

Modified: branches/open-external-format/src/org/armedbear/lisp/Stream.java
==============================================================================
--- branches/open-external-format/src/org/armedbear/lisp/Stream.java	(original)
+++ branches/open-external-format/src/org/armedbear/lisp/Stream.java	Fri Dec  5 22:58:19 2008
@@ -67,8 +67,7 @@
   private boolean open = true;
 
   // Character input.
-  private Reader reader;
-  private PushbackReader pushbackReader;
+  private PushbackReader reader;
   protected int offset;
   protected int lineNumber;
 
@@ -89,7 +88,7 @@
     LF
   }
 
-  static final private Symbol keywordDefault = Packages.internKeyword("DEFAULT");
+  static final protected Symbol keywordDefault = Packages.internKeyword("DEFAULT");
   
   static final private Symbol keywordCodePage = Packages.internKeyword("CODE-PAGE");
   static final private Symbol keywordID = Packages.internKeyword("ID");
@@ -106,6 +105,7 @@
   protected char eolChar = (eolStyle == EolStyle.CR) ? '\r' : '\n';
   protected LispObject externalFormat = LispObject.NIL;
   protected String encoding = null;
+  protected char lastChar = 0;
   
   // Binary input.
   private InputStream in;
@@ -144,9 +144,7 @@
             inputStreamReader =
               new InputStreamReader(inputStream);
           }
-        pushbackReader = new PushbackReader(new BufferedReader(inputStreamReader),
-					    2);
-	initAsCharacterInputStream(pushbackReader);
+        initAsCharacterInputStream(new BufferedReader(inputStreamReader));
       }
     else
       {
@@ -204,7 +202,11 @@
 
   protected void initAsCharacterInputStream(Reader reader)
   {
-    this.reader = reader;
+    if (! (reader instanceof PushbackReader))
+        this.reader = new PushbackReader(reader, 2);
+    else
+        this.reader = (PushbackReader)reader;
+    
     isInputStream = true;
     isCharacterStream = true;
   }
@@ -1823,7 +1825,7 @@
   {
     try
       {
-        pushbackReader.unread(n);
+        reader.unread(n);
         --offset;
         if (n == eolChar)
           --lineNumber;
@@ -1874,15 +1876,16 @@
     try
       {
         if (c == '\n') {
-	  if (eolStyle == EolStyle.CRLF)
-              writer.write("\r\n");
-          else
-              writer.write(eolChar);
-          
+	  if (eolStyle == EolStyle.CRLF && lastChar != '\r')
+              writer.write('\r');
+
+          writer.write(eolChar);
+          lastChar = eolChar;
           writer.flush();
           charPos = 0;
         } else {
           writer.write(c);
+          lastChar = c;
           ++charPos;
         }
       }
@@ -1915,10 +1918,11 @@
             //###FIXME: the number of writes can be greatly reduced by
             // writing the space between newlines as chunks.
             _writeChar(chars[i]);
-          
-        } else
-        writer.write(chars, start, end - start);
+          return;
+        }
         
+        writer.write(chars, start, end - start);
+        lastChar = chars[end-1];
         int index = -1;
         for (int i = end; i-- > start;)
           {
@@ -2137,6 +2141,7 @@
       {
         writer.write(sw.toString());
         writer.write('\n');
+        lastChar = '\n';
         writer.flush();
         charPos = 0;
       }




More information about the armedbear-cvs mailing list