List of utility methods to do InputStream Read by Charset
String | forceEncoding(String inputString, String targetCharset) Converts a given string to use the given encoding, e.g. String returnString = ""; Charset charset = Charset.forName(targetCharset); CharsetDecoder decoder = charset.newDecoder(); CharsetEncoder encoder = charset.newEncoder(); encoder.onUnmappableCharacter(CodingErrorAction.REPLACE); encoder.replaceWith(" ".getBytes()); ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(inputString)); CharBuffer cbuf = decoder.decode(bbuf); ... |
String | fromUnicode(String charset, String input) from Unicode StringBuffer ret = new StringBuffer(); Matcher matcher = UNICODE_PATTERN.matcher(input); String error = null; while (matcher.find()) { try { String uniValue = matcher.group().substring(2); String newValue = new String(new char[] { (char) Integer.parseInt(uniValue, 16) }); if (charset != null) { ... |
String | getContentFromInputStream(InputStream in, String charset) get string content form inputStream with given charset StringBuffer dist = new StringBuffer(); byte[] data = new byte[1024]; int readNum = -1; try { while ((readNum = in.read(data)) != -1) { dist.append(new String(data, 0, readNum, charset)); in.close(); ... |
long | getHeaderLen(FileInputStream in, Charset encoding) get Header Len byte[] expectedHeader = getHeader(encoding); byte[] magic = new byte[expectedHeader.length]; int read = readGuaranteed(magic, in); if (read != expectedHeader.length) { return 0; for (int i = 0; i < magic.length; i++) { if (magic[i] != expectedHeader[i]) { ... |
Charset | getInputCharset() get Input Charset if (inputCharset == null) inputCharset = getDefaultCharset(); return inputCharset; |
String | getStreamAsString(InputStream source, Charset charset) get Stream As String String result = getReaderAsString(new InputStreamReader(source, charset)); source.close(); return result; |
String | getText(InputStream stream, Charset charset) Read an InputStream completely, using the specified encoding. BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(stream, charset)); StringWriter sw = new StringWriter(); int n; char[] cbuf = new char[1024]; while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sw.write(cbuf, 0, n); ... |
String | input2String(InputStream input, Charset encoding) input String byte[] bytes = new byte[input.available()]; input.read(bytes); return new String(bytes, encoding); |
String | inputStreamAsString(InputStream stream, Charset cs) input Stream As String BufferedReader br = new BufferedReader(new InputStreamReader(stream, cs)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); br.close(); return sb.toString(); ... |
String | inputStreamToString(final InputStream inputStream, final String charsetName) Read from an java.io.InputStream to a java.lang.String . final Scanner scanner = new Scanner(inputStream, charsetName).useDelimiter("\\A"); String nextToken = ""; if (scanner.hasNext()) { nextToken = scanner.next(); return nextToken; |