Created
June 23, 2014 18:05
-
-
Save stebulus/63051af547bc5060910f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.Reader; | |
| import com.fasterxml.aalto.in.XmlScanner; | |
| import com.fasterxml.aalto.in.ReaderConfig; | |
| public class BufErr { | |
| public static void main(String[] args) { | |
| try { | |
| Reader rdr = new StringArrayReader(new String[] { | |
| "<foo><bar>text<", | |
| "/", | |
| "bar></foo>" | |
| }); | |
| ReaderConfig cfg = new ReaderConfig(); | |
| cfg.doCoalesceText(true); | |
| XmlScanner scan = new ReaderScanner(cfg, rdr); | |
| while (scan.nextFromTree() != XmlScanner.TOKEN_EOI) { | |
| // nop | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.Reader; | |
| public class StringArrayReader extends Reader { | |
| private String[] chunks; | |
| private int chunk, pos; | |
| public StringArrayReader(String[] chunks) { | |
| this.chunks = chunks; | |
| chunk = pos = 0; | |
| } | |
| public void close() {} | |
| public int read(char[] cbuf, int off, int len) { | |
| if (chunk >= chunks.length) | |
| return -1; | |
| while (pos >= chunks[chunk].length()) { | |
| chunk++; | |
| pos = 0; | |
| if (chunk >= chunks.length) | |
| return -1; | |
| } | |
| len = Math.min(len, chunks[chunk].length() - pos); | |
| for (int i = 0; i < len; i++) | |
| cbuf[off+i] = chunks[chunk].charAt(pos+i); | |
| pos += len; | |
| return len; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment