@Test public void readString() throws IOException { final String charset = "UTF-8"; final String s = "Have a nice day!"; byte[] input = (s + "\0").getBytes(charset); InputStream bais = new ByteArrayInputStream(input); DecoderInputStream in = new DecoderInputStream(bais); in.setLimit(input.length); String i = in.readString(Charset.forName(charset)); Assert.assertEquals(s, i); }
public String readString(Charset charset) throws IOException { byte[] buffer = new byte[getLimit()]; int pos = 0; int c; while ((c = read()) > 0) { buffer[pos++] = (byte)c; } return new String(buffer, 0, pos, charset); }
DecoderInputStream extends InputStream { public String readString(Charset charset) throws IOException { byte[] buffer = new byte[getLimit()]; int pos = 0; int c; while ((c = read()) > 0) { buffer[pos++] = (byte)c; } return new String(buffer, 0, pos, charset); } }
DecoderInputStream extends InputStream { public String readString(Charset charset) throws IOException { byte[] buffer = new byte[getLimit()]; int pos = 0; int c; while ((c = read()) > 0) { buffer[pos++] = (byte)c; } return new String(buffer, 0, pos, charset); } DecoderInputStream(InputStream in);  DecoderInputStream(InputStream in, int limit); }
DecoderInputStream extends InputStream { public String readString(Charset charset) throws IOException { byte[] buffer = new byte[getLimit()]; int pos = 0; int c; while ((c = read()) > 0) { buffer[pos++] = (byte)c; } return new String(buffer, 0, pos, charset); } DecoderInputStream(InputStream in);  DecoderInputStream(InputStream in, int limit); int available(); void close(); void mark(int readlimit); boolean markSupported(); @Override int read(); @Override int read(byte[] b, int off, int len); @Override long skip(long n); void reset(); int getLimit(); void setLimit(int limit); ByteOrder getByteOrder(); void setByteOrder(ByteOrder byteOrder); byte readByte(); int readInt(); int readUnsignedShort(); final short readShort(); String readString(Charset charset); String readString(int length, Charset charset); }
DecoderInputStream extends InputStream { public String readString(Charset charset) throws IOException { byte[] buffer = new byte[getLimit()]; int pos = 0; int c; while ((c = read()) > 0) { buffer[pos++] = (byte)c; } return new String(buffer, 0, pos, charset); } DecoderInputStream(InputStream in);  DecoderInputStream(InputStream in, int limit); int available(); void close(); void mark(int readlimit); boolean markSupported(); @Override int read(); @Override int read(byte[] b, int off, int len); @Override long skip(long n); void reset(); int getLimit(); void setLimit(int limit); ByteOrder getByteOrder(); void setByteOrder(ByteOrder byteOrder); byte readByte(); int readInt(); int readUnsignedShort(); final short readShort(); String readString(Charset charset); String readString(int length, Charset charset);  }