Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TimeoutString implements CharSequence {
- private final CharSequence child;
- private final long target;
- public TimeoutString(CharSequence child, long timeout) {
- this.child = child;
- this.target = System.nanoTime() + timeout*1000000;
- }
- private void checkTarget() {
- if (System.nanoTime() > target)
- throw new IllegalStateException("String operation timeout.");
- }
- @Override
- public int length() {
- checkTarget();
- return child.length();
- }
- @Override
- public char charAt(int i) {
- checkTarget();
- return child.charAt(i);
- }
- @Override
- public CharSequence subSequence(int a, int b) {
- checkTarget();
- return child.subSequence(a, b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement