Lazy string item (xs:string). @author BaseX Team, BSD License @author Christian Gruen
| 18 | * @author Christian Gruen |
| 19 | */ |
| 20 | public final class StrLazy extends AStr implements Lazy { |
| 21 | /** Input reference. */ |
| 22 | private final IO input; |
| 23 | /** Encoding (can be {@code null}). */ |
| 24 | private final String encoding; |
| 25 | /** Error message. */ |
| 26 | private final QueryError error; |
| 27 | /** Replace invalid input with Unicode replacement character. */ |
| 28 | private final boolean fallback; |
| 29 | /** Caching flag. */ |
| 30 | private boolean cache; |
| 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | * @param input input |
| 35 | * @param encoding encoding (can be {@code null}) |
| 36 | * @param error error message to be thrown |
| 37 | * @param fallback fallback flag |
| 38 | */ |
| 39 | public StrLazy(final IO input, final String encoding, final QueryError error, |
| 40 | final boolean fallback) { |
| 41 | this.input = input; |
| 42 | this.encoding = encoding; |
| 43 | this.error = error; |
| 44 | this.fallback = fallback; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public byte[] string(final InputInfo ii) throws QueryException { |
| 49 | cache(ii); |
| 50 | return value; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String toJava() throws QueryException { |
| 55 | return Token.string(string(null)); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public TextInput stringInput(final InputInfo ii) throws IOException, QueryException { |
| 60 | if(cache) cache(ii); |
| 61 | return isCached() ? super.stringInput(ii) : get(ii); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void cache(final boolean lazy, final InputInfo ii) throws QueryException { |
| 66 | if(lazy) cache = true; |
| 67 | else cache(ii); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void cache(final InputInfo ii) throws QueryException { |
| 72 | try { |
| 73 | if(!isCached()) value = get(ii).content(); |
| 74 | } catch(final IOException ex) { |
| 75 | Util.debug(ex); |
| 76 | throw error.get(ii, input); |
| 77 | } |
nothing calls this directly
no outgoing calls
no test coverage detected