[teiid-commits] teiid SVN: r2766 - in branches/7.1.x/common-core/src: test/java/org/teiid/core/util and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Dec 13 10:15:36 EST 2010


Author: shawkins
Date: 2010-12-13 10:15:35 -0500 (Mon, 13 Dec 2010)
New Revision: 2766

Added:
   branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestInputStreamReader.java
Removed:
   branches/7.1.x/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java
Modified:
   branches/7.1.x/common-core/src/main/java/org/teiid/core/util/InputStreamReader.java
Log:
TEIID-1390 fix for inputstreamreader handling of multibyte chars at buffer boundaries

Modified: branches/7.1.x/common-core/src/main/java/org/teiid/core/util/InputStreamReader.java
===================================================================
--- branches/7.1.x/common-core/src/main/java/org/teiid/core/util/InputStreamReader.java	2010-12-10 18:28:27 UTC (rev 2765)
+++ branches/7.1.x/common-core/src/main/java/org/teiid/core/util/InputStreamReader.java	2010-12-13 15:15:35 UTC (rev 2766)
@@ -89,8 +89,12 @@
 	    			cr.throwException();
 	    		}
 	    		done = true;
-	    	} 
-			bb.clear();
+	    	}
+	    	if (bb.remaining() != 0) {
+	    		bb.compact();
+	    	} else {
+	    		bb.clear();
+	    	}
     		cb.flip();
 		}
 		len = Math.min(len, cb.remaining());

Deleted: branches/7.1.x/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java
===================================================================
--- branches/7.1.x/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java	2010-12-10 18:28:27 UTC (rev 2765)
+++ branches/7.1.x/common-core/src/test/java/org/teiid/core/util/FakeInputStream.java	2010-12-13 15:15:35 UTC (rev 2766)
@@ -1,68 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.core.util;
-
-import java.io.ByteArrayInputStream;
-
-/**
- * This test input stream overrides the <code>available</code>
- * to return "1" until <i>after</i> the {@link #read} method returns
- * "-1" to indicate EOF, which is how java.util.zip.ZipInputStream
- * works, which is what is used by ExtensionSourceManager to retrieve
- * Class files from JAR files.  The <code>available</code> method
- * therefore can't be relied on by ByteArrayHelper to either
- * indicate how many bytes can be read, or if more are
- * available or not.  In the latter case, ByteArrayHelper
- * relies on the <code>read</code> method returning "-1".
- */
-public class FakeInputStream extends ByteArrayInputStream {
-
-    private int available = 1;
-
-    public FakeInputStream(byte[] buf) {
-        super(buf);
-    }
-
-    /**
-     * Overriden to return "1" <i>until</i> the <code>read</code> method
-     * has returned "-1" to indicate EOF.
-     */
-    public int available(){
-        super.available();
-        return available;
-    }
-
-    /**
-     * Overriden - basically calls to super method, but checks returned
-     * number of bytes read; if "-1", then the next call to
-     * {@link #available} will return "0".
-     */
-    public int read(byte b[], int off, int len) {
-        int result = super.read(b, off, len);
-        if (result<0){
-            available = 0;
-        }
-        return result;
-    }
-
-}

Added: branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestInputStreamReader.java
===================================================================
--- branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestInputStreamReader.java	                        (rev 0)
+++ branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestInputStreamReader.java	2010-12-13 15:15:35 UTC (rev 2766)
@@ -0,0 +1,18 @@
+package org.teiid.core.util;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.Charset;
+
+import org.junit.Test;
+
+ at SuppressWarnings("nls")
+public class TestInputStreamReader {
+
+	@Test public void testMultiByte() throws Exception {
+		InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte)80, (byte)-61, (byte)-70}), Charset.forName("UTF-8").newDecoder(), 2);
+		assertEquals(80, isr.read());
+		assertEquals(250, isr.read());
+	}
+}


Property changes on: branches/7.1.x/common-core/src/test/java/org/teiid/core/util/TestInputStreamReader.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the teiid-commits mailing list