List of usage examples for java.io Reader read
public int read() throws IOException
From source file:com.googlecode.batchfb.util.StringUtils.java
/** * Reads an input stream into a String, encoding with UTF-8 */// ww w. j av a 2s . c o m public static String read(InputStream input) { try { StringBuilder bld = new StringBuilder(); Reader reader = new InputStreamReader(input, "utf-8"); int ch; while ((ch = reader.read()) >= 0) bld.append((char) ch); return bld.toString(); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static char skipWhitespace(Reader reader) throws IOException { if (DEBUG)//from w w w . j ava2 s . c om System.out.println("XMLParserUtilities.skipWhitespace( " + reader + ")"); char c = (char) reader.read(); while (Character.isWhitespace(c)) { c = (char) reader.read(); } return c; }
From source file:erainformatica.utility.JSONHelper.java
private static TelegramRequestResult<String> readAll(Reader rd) { try {/*from w w w.ja v a2 s. c o m*/ StringBuilder sb = new StringBuilder(); int cp; while ((cp = rd.read()) != -1) { sb.append((char) cp); } return new TelegramRequestResult<>(true, null, sb.toString()); } catch (Exception e) { return new TelegramRequestResult<>(true, e.toString(), null); } }
From source file:Main.java
public static boolean contentEquals(Reader input1, Reader input2) throws IOException { input1 = toBufferedReader(input1);/*from ww w . ja v a 2 s . c o m*/ input2 = toBufferedReader(input2); int ch = input1.read(); while (-1 != ch) { int ch2 = input2.read(); if (ch != ch2) { return false; } ch = input1.read(); } int ch2 = input2.read(); return ch2 == -1; }
From source file:dk.laundav.locationservice.service.ReverseGeocoder.java
private static String readAll(Reader rd) throws IOException { int cp;// w w w. j a v a 2 s .c o m StringBuilder sb = new StringBuilder(); while ((cp = rd.read()) != -1) { sb.append((char) cp); } return sb.toString(); }
From source file:com.facebook.fresco.sample.urlsfetcher.ImageUrlsFetcher.java
/** Reads an InputStream and converts it to a String. */ private static String readAsString(InputStream stream) throws IOException { StringWriter writer = new StringWriter(); Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); while (true) { int c = reader.read(); if (c < 0) { break; }/*w w w .j a v a 2 s . co m*/ writer.write(c); } return writer.toString(); }
From source file:Main.java
public static String parseString(Reader reader, char delim) throws IOException { // System.out.println("XMLParserUtilities.parseString( "+reader+", "+delim+")"); StringBuffer buffer = new StringBuffer(); char c = (char) reader.read(); while (c != delim) { buffer.append(c);/*from w ww . j av a 2s . com*/ ; c = (char) reader.read(); } String result = buffer.toString(); if (DEBUG) System.out.println("XMLParserUtilities.parseString( " + reader + ", " + delim + ") [" + result + "]"); return result; }
From source file:com.prowidesoftware.swift.utils.Lib.java
/** * Read the content of the given stream into a string. * * @param stream the contents to read/*w w w . j av a 2 s . c om*/ * @param enconding optional encoding to use, if null "UTF-8" is used as default * @return the read content * @throws IOException * @since 7.7 */ public static String readStream(final InputStream stream, final String enconding) throws IOException { if (stream == null) { return null; } final StringBuilder out = new StringBuilder(); final String enc = enconding != null ? enconding : "UTF-8"; final Reader in = new InputStreamReader(stream, enc); try { int c = 0; while ((c = in.read()) != -1) { out.append((char) c); } } finally { in.close(); } return out.toString(); }
From source file:Main.java
private static Reader getReader(InputStream is) throws IOException { Reader reader = new BufferedReader(new InputStreamReader(is)); char c[] = "<?".toCharArray(); int pos = 0;//from w w w. java2s .c om reader.mark(LOOKAHEAD); while (true) { int value = reader.read(); // Check to see if we hit the end of the stream. if (value == -1) { throw new IOException("Encounter end of stream before start of XML."); } else if (value == c[pos]) { pos++; } else { if (pos > 0) { pos = 0; } reader.mark(LOOKAHEAD); } if (pos == c.length) { // We found the character set we were looking for. reader.reset(); break; } } return reader; }
From source file:Access.Downloader.java
private static String readAll(Reader rd) throws IOException { StringBuilder sb = new StringBuilder(); int cp;//w w w .j a v a 2 s . com while ((cp = rd.read()) != -1) { sb.append((char) cp); } return sb.toString(); }