1 /* Copyright (c) 2008-2010, Avian Contributors 2 3 Permission to use, copy, modify, and/or distribute this software 4 for any purpose with or without fee is hereby granted, provided 5 that the above copyright notice and this permission notice appear 6 in all copies. 7 8 There is NO WARRANTY for this software. See license.txt for 9 details. */ 10 11 package java.io; 12 13 import com.badlogic.gdx.utils.Utf8Decoder; 14 15 public class InputStreamReader extends Reader { 16 private final InputStream in; 17 18 private final Utf8Decoder utf8Decoder; 19 InputStreamReader(InputStream in)20 public InputStreamReader (InputStream in) { 21 this.in = in; 22 this.utf8Decoder = new Utf8Decoder(); 23 } 24 InputStreamReader(InputStream in, String encoding)25 public InputStreamReader (InputStream in, String encoding) throws UnsupportedEncodingException { 26 this(in); 27 28 // FIXME this is bad, but some APIs seem to use "ISO-8859-1", fuckers... 29 // if (! encoding.equals("UTF-8")) { 30 // throw new UnsupportedEncodingException(encoding); 31 // } 32 } 33 read(char[] b, int offset, int length)34 public int read (char[] b, int offset, int length) throws IOException { 35 byte[] buffer = new byte[length]; 36 int c = in.read(buffer); 37 return c <= 0 ? c : utf8Decoder.decode(buffer, 0, c, b, offset); 38 } 39 close()40 public void close () throws IOException { 41 in.close(); 42 } 43 } 44