MyStreamReader.java (643B)
1 package de.openrat.android.blog; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.io.Reader; 6 7 public class MyStreamReader extends Reader 8 { 9 10 private InputStream stream; 11 12 public MyStreamReader(InputStream inputStream) 13 { 14 this.stream = inputStream; 15 } 16 17 @Override 18 public void close() throws IOException 19 { 20 stream.close(); 21 } 22 23 @Override 24 public int read(char[] buf, int offset, int count) throws IOException 25 { 26 if (count != 1 || buf.length != 1 || offset != 0) 27 throw new IOException("Buffer size must be 1"); 28 byte[] b = new byte[1]; 29 this.stream.read(b); 30 char c = (char) b[0]; 31 buf[0] = c; 32 return 1; 33 } 34 35 }