List of utility methods to do InputStream Read by Charset
String | inputstreamToString(InputStream input, CharsetDecoder decoder) Reads an input stream into a string. CharsetDecoder charsetDecoder = decoder; if (decoder == null) { charsetDecoder = Charset.defaultCharset().newDecoder(); BufferedReader reader = new BufferedReader(new InputStreamReader(input, charsetDecoder)); StringBuilder stringBuffer = new StringBuilder(); String line = reader.readLine(); while (line != null) { ... |
String | inputStreamToString(InputStream inputStream, Charset charset) Convert an InputStream into a String. if (inputStream != null && inputStream.available() != -1) { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) != -1) { result.write(buffer, 0, length); if (charset != null) { ... |
String | inputStreamToString(InputStream inputStream, String charset) input Stream To String return inputStreamToString(inputStream, Charset.forName(charset));
|
String | inputStreamToString(InputStream is, Charset charset) input Stream To String if (is == null) { throw new IllegalArgumentException("input stream MUST NOT be null"); if (charset == null) { throw new IllegalArgumentException("charset MUST NOT be null"); ByteArrayOutputStream result = new ByteArrayOutputStream(); int readLen; ... |
boolean | isCharsetMisInterpreted(String input, String encoding) is Charset Mis Interpreted CharsetDecoder decoder = Charset.forName("ascii").newDecoder(); CharsetEncoder encoder = Charset.forName(encoding).newEncoder(); ByteBuffer tmp; try { tmp = encoder.encode(CharBuffer.wrap(input)); } catch (CharacterCodingException e) { return false; try { decoder.decode(tmp); return true; } catch (CharacterCodingException e) { return false; |
Stream | lines(InputStream in, Charset cs) Read all lines lazily from an InputStream as a Stream . InputStreamReader reader = new InputStreamReader(in, cs); BufferedReader br = new BufferedReader(reader); try { return br.lines().onClose(asUncheckedRunnable(br)); } catch (Error | RuntimeException e) { try { br.close(); } catch (IOException ex) { ... |
String | loadInputStream(InputStream in, Charset cs) Load an input stream BufferedInputStream buffIn = null; InputStreamReader reader = null; try { buffIn = new BufferedInputStream(in); reader = new InputStreamReader(buffIn, cs); StringWriter dest = new StringWriter(); int ch; while ((ch = reader.read()) >= 0) { ... |
boolean | processSubstitute(CharBuffer cb, String replacement, boolean endOfInput, String outputCharset, OutputStream os) Scan the characters in the buffer and do replacement. int remaining = cb.remaining(); if (remaining == 0) { cb.clear(); return false; String result = SEARCH_PATTERN.matcher(cb).replaceFirst(replacement); cb.clear(); if (result.length() != remaining) { ... |
String | stream2Bytes(InputStream is, Charset charset) stream Bytes String result = null; try { int total = is.available(); byte[] bs = new byte[total]; is.read(bs); result = new String(bs, charset.name()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); ... |
String | streamString(InputStream in, boolean closeIn, String charset) stream String return new String(streamBytes(in, closeIn), Charset.forName(charset)); |