1 21 22 package org.armedbear.lisp; 23 24 public abstract class CaseFrobStream extends Stream 25 { 26 protected final Stream target; 27 28 protected CaseFrobStream(Stream target) 29 throws ConditionThrowable 30 { 31 Debug.assertTrue(target.isCharacterOutputStream()); 32 this.target = target; 33 } 34 35 public LispObject getElementType() throws ConditionThrowable 36 { 37 return target.getElementType(); 38 } 39 40 public LispObject typeOf() 41 { 42 return Symbol.CASE_FROB_STREAM; 43 } 44 45 public LispClass classOf() 46 { 47 return BuiltInClass.CASE_FROB_STREAM; 48 } 49 50 public LispObject typep(LispObject type) throws ConditionThrowable 51 { 52 if (type == Symbol.CASE_FROB_STREAM) 53 return T; 54 if (type == BuiltInClass.CASE_FROB_STREAM) 55 return T; 56 return super.typep(type); 57 } 58 59 public boolean isInputStream() 60 { 61 return false; 62 } 63 64 public boolean isOutputStream() 65 { 66 return true; 67 } 68 69 public boolean isCharacterInputStream() throws ConditionThrowable 70 { 71 return false; 72 } 73 74 public boolean isBinaryInputStream() throws ConditionThrowable 75 { 76 return false; 77 } 78 79 public boolean isCharacterOutputStream() throws ConditionThrowable 80 { 81 return true; 82 } 83 84 public boolean isBinaryOutputStream() throws ConditionThrowable 85 { 86 return false; 87 } 88 89 public int getCharPos() 90 { 91 return target.getCharPos(); 92 } 93 94 public void setCharPos(int n) 95 { 96 target.setCharPos(n); 97 } 98 99 protected int _readChar() throws ConditionThrowable 101 { 102 notSupported(); 103 return -1; 105 } 106 107 protected void _unreadChar(int n) throws ConditionThrowable 108 { 109 notSupported(); 110 } 111 112 protected boolean _charReady() throws ConditionThrowable 113 { 114 notSupported(); 115 return false; 117 } 118 119 public void _writeChars(char[] chars, int start, int end) 120 throws ConditionThrowable 121 { 122 _writeString(new String (chars, start, end)); 123 } 124 125 public int _readByte() throws ConditionThrowable 127 { 128 notSupported(); 129 return -1; 131 } 132 133 public void _writeByte(int n) throws ConditionThrowable 135 { 136 notSupported(); 137 } 138 139 public void _finishOutput() throws ConditionThrowable 140 { 141 target._finishOutput(); 142 } 143 144 public void _clearInput() throws ConditionThrowable 145 { 146 notSupported(); 147 } 148 149 public LispObject close(LispObject abort) throws ConditionThrowable 150 { 151 setOpen(false); 152 return T; 153 } 154 155 public LispObject listen() throws ConditionThrowable 156 { 157 notSupported(); 158 return NIL; 160 } 161 162 public LispObject terpri() throws ConditionThrowable 163 { 164 return target.terpri(); 165 } 166 167 public LispObject freshLine() throws ConditionThrowable 168 { 169 return target.freshLine(); 170 } 171 172 public String writeToString() 173 { 174 return unreadableString("CASE-FROB-STREAM"); 175 } 176 177 private void notSupported() throws ConditionThrowable 178 { 179 signal(new TypeError("Operation is not supported for streams of type CASE-FROB-STREAM.")); 180 } 181 182 private static final Primitive2 MAKE_CASE_FROB_STREAM = 184 new Primitive2("make-case-frob-stream", PACKAGE_SYS, false, "target kind") 185 { 186 public LispObject execute(LispObject first, LispObject second) 187 throws ConditionThrowable 188 { 189 Stream target = checkCharacterOutputStream(first); 190 if (second == Keyword.UPCASE) 191 return new UpcaseStream(target); 192 if (second == Keyword.DOWNCASE) 193 return new DowncaseStream(target); 194 if (second == Keyword.CAPITALIZE) 195 return new CapitalizeStream(target); 196 if (second == Keyword.CAPITALIZE_FIRST) 197 return new CapitalizeFirstStream(target); 198 return signal(new TypeError( 199 "Kind must be :UPCASE, :DOWNCASE, :CAPITALIZE or :CAPITALIZE-FIRST.")); 200 } 201 }; 202 } 203 | Popular Tags |