jaroslav@595: /** jaroslav@595: * Back 2 Browser Bytecode Translator jaroslav@595: * Copyright (C) 2012 Jaroslav Tulach jaroslav@595: * jaroslav@595: * This program is free software: you can redistribute it and/or modify jaroslav@595: * it under the terms of the GNU General Public License as published by jaroslav@595: * the Free Software Foundation, version 2 of the License. jaroslav@595: * jaroslav@595: * This program is distributed in the hope that it will be useful, jaroslav@595: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@595: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@595: * GNU General Public License for more details. jaroslav@595: * jaroslav@595: * You should have received a copy of the GNU General Public License jaroslav@595: * along with this program. Look for COPYING file in the top folder. jaroslav@595: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@595: */ jaroslav@595: package org.apidesign.bck2brwsr.compact.tck; jaroslav@595: jaroslav@595: import java.io.ByteArrayInputStream; jaroslav@595: import java.io.IOException; jaroslav@595: import java.io.InputStreamReader; jaroslav@714: import java.io.UnsupportedEncodingException; jaroslav@595: import java.util.Arrays; jaroslav@595: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@595: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@595: import org.testng.annotations.Factory; jaroslav@595: jaroslav@595: /** jaroslav@595: * jaroslav@595: * @author Jaroslav Tulach jaroslav@595: */ jaroslav@595: public class ReaderTest { jaroslav@595: @Compare public String readUTFString() throws IOException { jaroslav@595: byte[] arr = { jaroslav@595: (byte)-59, (byte)-67, (byte)108, (byte)117, (byte)-59, (byte)-91, jaroslav@595: (byte)111, (byte)117, (byte)-60, (byte)-115, (byte)107, (byte)-61, jaroslav@595: (byte)-67, (byte)32, (byte)107, (byte)-59, (byte)-81, (byte)-59, jaroslav@595: (byte)-120 jaroslav@595: }; jaroslav@595: ByteArrayInputStream is = new ByteArrayInputStream(arr); lubomir@735: InputStreamReader r = new InputStreamReader(is, "UTF-8"); jaroslav@595: jaroslav@595: StringBuilder sb = new StringBuilder(); jaroslav@595: for (;;) { jaroslav@595: int ch = r.read(); jaroslav@595: if (ch == -1) { jaroslav@595: break; jaroslav@595: } jaroslav@595: sb.append((char)ch); jaroslav@595: } jaroslav@595: return sb.toString().toString(); jaroslav@595: } jaroslav@714: @Compare public String stringToBytes() throws UnsupportedEncodingException { jaroslav@714: return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8")); jaroslav@595: } jaroslav@595: jaroslav@595: @Factory public static Object[] create() { jaroslav@595: return VMTest.create(ReaderTest.class); jaroslav@595: } jaroslav@595: }