Changeset 14857
- Timestamp:
- 09/04/16 07:01:02 (6 years ago)
- Location:
- trunk/abcl
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/build.xml
r14846 r14857 947 947 <arg value="org.armedbear.lisp.PathnameTest"/> 948 948 <arg value="org.armedbear.lisp.StreamTest"/> 949 <arg value="org.armedbear.lisp.SeekableStringWriterTest"/> 949 950 <arg value="org.armedbear.lisp.UtilitiesTest"/> 950 951 <!-- currently hangs(!) the running process -
trunk/abcl/src/org/armedbear/lisp/StringInputStream.java
r13442 r14857 36 36 import static org.armedbear.lisp.Lisp.*; 37 37 38 import java.io.IOException; 38 39 import java.io.StringReader; 39 40 … … 42 43 private final StringReader stringReader; 43 44 private final int start; 45 private final String subString; 44 46 45 47 public StringInputStream(String s) … … 61 63 62 64 this.start = start; 63 64 stringReader = new StringReader(s.substring(start, end)); 65 66 subString = s.substring(start, end); 67 stringReader = new StringReader(subString); 65 68 initAsCharacterInputStream(stringReader); 66 69 } … … 94 97 @Override 95 98 public int getOffset() { 96 return start + super.getOffset(); 99 return start + offset; 100 } 101 102 @Override 103 protected long _getFilePosition() { 104 return getOffset(); 105 } 106 107 @Override 108 protected boolean _setFilePosition(LispObject arg) { 109 try { 110 int offset; 111 112 if (arg == Keyword.START) 113 offset = 0; 114 else if (arg == Keyword.END) 115 offset = subString.length(); 116 else { 117 long n = Fixnum.getValue(arg); 118 if (n < 0 || n > subString.length()) 119 error(new StreamError(this, "FILE-POSITION got out of bounds argument.")); 120 offset = (int) n; // FIXME arg might be a bignum 121 } 122 123 stringReader.reset(); 124 stringReader.skip(offset); 125 initAsCharacterInputStream(stringReader); 126 127 this.offset = offset; 128 } 129 catch (IOException e) { 130 error(new StreamError(this, e)); 131 } 132 133 return true; 97 134 } 98 135 -
trunk/abcl/src/org/armedbear/lisp/StringOutputStream.java
r13442 r14857 36 36 import static org.armedbear.lisp.Lisp.*; 37 37 38 import java.io.IOException; 38 39 import java.io.StringWriter; 39 40 40 41 public final class StringOutputStream extends Stream 41 42 { 42 private final S tringWriter stringWriter;43 private final SeekableStringWriter stringWriter; 43 44 44 45 public StringOutputStream() … … 52 53 this.elementType = elementType; 53 54 this.eolStyle = EolStyle.RAW; 54 initAsCharacterOutputStream(stringWriter = new S tringWriter());55 initAsCharacterOutputStream(stringWriter = new SeekableStringWriter()); 55 56 } 56 57 … … 86 87 if (elementType == NIL) 87 88 return 0; 88 return stringWriter.getBuffer().length(); 89 return offset; 90 } 91 92 @Override 93 protected boolean _setFilePosition(LispObject arg) { 94 if (elementType == NIL) 95 return false; 96 97 try { 98 int offset; 99 100 if (arg == Keyword.START) 101 offset = 0; 102 else if (arg == Keyword.END) 103 offset = stringWriter.getBuffer().length(); 104 else { 105 long n = Fixnum.getValue(arg); 106 offset = (int) n; // FIXME arg might be a bignum 107 } 108 109 stringWriter.seek(offset); 110 111 this.offset = offset; 112 } 113 catch (IllegalArgumentException e) { 114 error(new StreamError(this, e)); 115 } 116 117 return true; 89 118 } 90 119 -
trunk/abcl/test/lisp/abcl/misc-tests.lisp
r12935 r14857 110 110 (values 42 2)))))) 111 111 42 2) 112 113 (deftest string-output-stream.seekable 114 (string= "Goodbye, World! Something." 115 (let ((stream (make-string-output-stream))) 116 (write-string "Hello, World! Something." stream) 117 (file-position stream :start) 118 (write-string "Goodbye, World!" stream) 119 (get-output-stream-string stream))) 120 T)
Note: See TracChangeset
for help on using the changeset viewer.