/** * Reads from the Stringreader, returning the same value. Note that data will be lost for characters not in ISO * Latin 1. Clients assuming a return value in the range -1 to 255 may even fail on such input. * * @return the value of the next character in the StringReader * @exception IOException if the original StringReader fails to be read */ public int read() throws IOException { return in.read(); }
public int read(byte[] b, int off, int len) throws IOException { char[] ch = new char[len]; int r = reader.read(ch, 0, len); for (int i = 0; i < r; i++) b[off + i] = (byte) ch[i]; return r; }
public int read() throws IOException { return reader.read(); }
private static String readUntilCharacter(StringReader reader, char c) throws IOException { StringBuilder sb = new StringBuilder(); char read; do { read = (char) reader.read(); if (read != c) { sb.append(read); } } while (read != c); return sb.toString(); }
@Override public int read(char[] cbuf, int off, int len) throws IOException { if (current != null) { int ret = current.read(cbuf, off, len); if (ret > 0 || len == 0) { // If some data was read, or if no data was requested, // we're OK. Return the number of characters read. return ret; } } // No more data was found in the current element. Read data from // the next element, or return -1 if there are no more elements. if (iterator.hasNext()) { current = new StringReader(iterator.next() + '\n'); return current.read(cbuf, off, len); } else { return -1; } }
public String getWhiteSpaces() throws IOException { if (isEnded()) return ""; StringBuilder whiteSpaces = new StringBuilder(); if (buf.length() > 0) { whiteSpaces.append(buf); buf = new StringBuilder(); } int c = sr.read(); while (Character.isWhitespace((char) c)) { whiteSpaces.append((char) c); c = sr.read(); } if (c == -1) { ended = true; } else { buf.append((char) c); } return whiteSpaces.toString(); }
/** * Method changeLess32toXML * * @param string * @return normalized string * @throws IOException */ static String changeLess32toXML(String string) throws IOException { StringBuilder sb = new StringBuilder(); StringReader sr = new StringReader(string); int i = 0; while ((i = sr.read()) > -1) { if (i < 32) { sb.append('\\'); sb.append(Integer.toHexString(i)); } else { sb.append((char) i); } } return sb.toString(); }
/** * Method changeWStoXML * * @param string * @return normalized string * @throws IOException */ static String changeWStoXML(String string) throws IOException { StringBuilder sb = new StringBuilder(); StringReader sr = new StringReader(string); int i = 0; char c; while ((i = sr.read()) > -1) { c = (char) i; if (c == '\\') { char c1 = (char) sr.read(); if (c1 == ' ') { sb.append('\\'); String s = "20"; sb.append(s); } else { sb.append('\\'); sb.append(c1); } } else { sb.append(c); } } return sb.toString(); }
public void testGet_io() throws IOException { assertEquals(-1, ArbitraryInstances.get(InputStream.class).read()); assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read()); assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1))); assertEquals(-1, ArbitraryInstances.get(Reader.class).read()); assertEquals(-1, ArbitraryInstances.get(StringReader.class).read()); assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity()); assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity()); ArbitraryInstances.get(PrintStream.class).println("test"); ArbitraryInstances.get(PrintWriter.class).println("test"); assertNotNull(ArbitraryInstances.get(File.class)); assertFreshInstanceReturned( ByteArrayOutputStream.class, OutputStream.class, Writer.class, StringWriter.class, PrintStream.class, PrintWriter.class); assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class)); assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class)); assertNotNull(ArbitraryInstances.get(ByteSink.class)); assertNotNull(ArbitraryInstances.get(CharSink.class)); }