Changeset 12321
- Timestamp:
- 01/01/10 18:26:24 (11 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp/util
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/util/RandomAccessCharacterFile.java
r12318 r12321 281 281 fcn = raf.getChannel(); 282 282 283 cset = (encoding == null) ? Charset.defaultCharset() : Charset.forName(encoding); 283 setEncoding(encoding); 284 bbuf = ByteBuffer.allocate(BUFSIZ); 285 286 // there is no readable data available in the buffers. 287 bbuf.flip(); 288 289 // there is no write pending data in the buffers. 290 bbufIsDirty = false; 291 292 bbufIsReadable = false; 293 294 bbufpos = fcn.position(); 295 296 reader = new RandomAccessReader(); 297 writer = new RandomAccessWriter(); 298 inputStream = new RandomAccessInputStream(); 299 outputStream = new RandomAccessOutputStream(); 300 } 301 302 public void setEncoding(String encoding) { 303 cset = (encoding == null) 304 ? Charset.defaultCharset() : Charset.forName(encoding); 284 305 cdec = cset.newDecoder(); 285 306 cdec.onMalformedInput(CodingErrorAction.REPLACE); 286 307 cdec.onUnmappableCharacter(CodingErrorAction.REPLACE); 287 308 cenc = cset.newEncoder(); 288 289 bbuf = ByteBuffer.allocate(BUFSIZ);290 291 // there is no readable data available in the buffers.292 bbuf.flip();293 294 // there is no write pending data in the buffers.295 bbufIsDirty = false;296 297 bbufIsReadable = false;298 299 bbufpos = fcn.position();300 301 reader = new RandomAccessReader();302 writer = new RandomAccessWriter();303 inputStream = new RandomAccessInputStream();304 outputStream = new RandomAccessOutputStream();305 309 } 306 310 … … 366 370 CoderResult r = cdec.decode(bbuf, cbuf, atEof ); 367 371 decodeWasUnderflow = (CoderResult.UNDERFLOW == r); 372 if (r.isMalformed()) 373 // When reading encoded Unicode, we'd expect to require 374 // catching MalformedInput 375 throw new RACFMalformedInputException(bbuf.position(), 376 bbuf.get(bbuf.position()), 377 cset.name()); 378 if (r.isUnmappable()) 379 // Since we're mapping TO unicode, we'd expect to be able 380 // to map all characters 381 Debug.assertTrue(false); 382 if (CoderResult.OVERFLOW == r) 383 Debug.assertTrue(false); 368 384 } 369 385 if (cbuf.remaining() == len) { … … 388 404 } 389 405 390 private final void encodeAndWrite(CharBuffer cbuf, boolean flush, boolean endOfFile) throws IOException { 406 private final void encodeAndWrite(CharBuffer cbuf, boolean flush, 407 boolean endOfFile) throws IOException { 391 408 while (cbuf.remaining() > 0) { 392 409 CoderResult r = cenc.encode(cbuf, bbuf, endOfFile); … … 396 413 bbuf.clear(); 397 414 } 415 if (r.isUnmappable()) { 416 throw new RACFUnmappableCharacterException(cbuf.position(), 417 cbuf.charAt(cbuf.position()), 418 cset.name()); 419 } 420 if (r.isMalformed()) { 421 // We don't really expect Malformed, but not handling it 422 // will cause an infinite loop if we don't... 423 throw new RACFMalformedInputException(cbuf.position(), 424 cbuf.charAt(cbuf.position()), 425 cset.name()); 426 } 427 if (CoderResult.UNDERFLOW == r) 428 Debug.assertTrue(false); 398 429 } 399 430 if (bbuf.position() > 0 && bbufIsDirty && flush) {
Note: See TracChangeset
for help on using the changeset viewer.