From: <es...@us...> - 2009-12-16 01:26:20
|
Revision: 438 http://columba.svn.sourceforge.net/columba/?rev=438&view=rev Author: eschman Date: 2009-12-16 01:26:09 +0000 (Wed, 16 Dec 2009) Log Message: ----------- [bug] Fix the decoder to only fallback to a different charset if really needed. If the buffer is not rewinded no chars will be read and capacity will always be 0 Modified Paths: -------------- ristretto/trunk/ristretto-common/src/main/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStream.java ristretto/trunk/ristretto-common/src/test/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStreamTest.java Modified: ristretto/trunk/ristretto-common/src/main/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStream.java =================================================================== --- ristretto/trunk/ristretto-common/src/main/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStream.java 2009-12-15 23:02:38 UTC (rev 437) +++ ristretto/trunk/ristretto-common/src/main/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStream.java 2009-12-16 01:26:09 UTC (rev 438) @@ -121,11 +121,15 @@ result = decoder.decode(inBytes, outChars, in.available() == 0); } while(outChars.position() == 0); + outChars.rewind(); ByteBuffer test = charset.encode(outChars); - while( test.capacity() == 0 && fallback()) { + // if the decoder was unable to perform decoding it returns a + // char but i get an underflow result + while( (result.isUnderflow() || test.capacity() == 0) && fallback()) { inBytes.rewind(); outChars.clear(); result = decoder.decode(inBytes, outChars, in.available() == 0); + outChars.rewind(); test = charset.encode(outChars); } Modified: ristretto/trunk/ristretto-common/src/test/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStreamTest.java =================================================================== --- ristretto/trunk/ristretto-common/src/test/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStreamTest.java 2009-12-15 23:02:38 UTC (rev 437) +++ ristretto/trunk/ristretto-common/src/test/java/org/columba/ristretto/coder/FallbackCharsetDecoderInputStreamTest.java 2009-12-16 01:26:09 UTC (rev 438) @@ -50,7 +50,7 @@ public void testISO_8859_1butwindows_1252() { String test = "\u2014mple"; try { - InputStream in = new FallbackCharsetDecoderInputStream( new ByteArrayInputStream( test.getBytes("windows-1252")), Charset.forName("ISO-8859-1") ); + InputStream in = new FallbackCharsetDecoderInputStream( new ByteArrayInputStream( test.getBytes("windows-1252")), Charset.forName("us-ascii") ); //InputStream in = new FallbackCharsetDecoderInputStream( new ByteArrayInputStream( test.getBytes("windows-1252")), Charset.forName("windows-1252") ); StringBuffer result = new StringBuffer(); int next = in.read(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |