The base class for all readers. A reader is a means of reading data from a source in a character-wise manner. Some readers also support marking a position in the input and returning to this position later. This abstract class does not provide a fully working implementation, so it needs to be sub
| 37 | * @see Writer |
| 38 | */ |
| 39 | public abstract class Reader implements Readable, Closeable { |
| 40 | /** |
| 41 | * The object used to synchronize access to the reader. |
| 42 | */ |
| 43 | protected Object lock; |
| 44 | |
| 45 | /** |
| 46 | * Constructs a new {@code Reader} with {@code this} as the object used to |
| 47 | * synchronize critical sections. |
| 48 | */ |
| 49 | protected Reader() { |
| 50 | super(); |
| 51 | lock = this; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Constructs a new {@code Reader} with {@code lock} used to synchronize |
| 56 | * critical sections. |
| 57 | * |
| 58 | * @param lock |
| 59 | * the {@code Object} used to synchronize critical sections. |
| 60 | * @throws NullPointerException |
| 61 | * if {@code lock} is {@code null}. |
| 62 | */ |
| 63 | protected Reader(Object lock) { |
| 64 | if (lock == null) { |
| 65 | throw new NullPointerException(); |
| 66 | } |
| 67 | this.lock = lock; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Closes this reader. Implementations of this method should free any |
| 72 | * resources associated with the reader. |
| 73 | * |
| 74 | * @throws IOException |
| 75 | * if an error occurs while closing this reader. |
| 76 | */ |
| 77 | public abstract void close() throws IOException; |
| 78 | |
| 79 | /** |
| 80 | * Sets a mark position in this reader. The parameter {@code readLimit} |
| 81 | * indicates how many characters can be read before the mark is invalidated. |
| 82 | * Calling {@code reset()} will reposition the reader back to the marked |
| 83 | * position if {@code readLimit} has not been surpassed. |
| 84 | * <p> |
| 85 | * This default implementation simply throws an {@code IOException}; |
| 86 | * subclasses must provide their own implementation. |
| 87 | * |
| 88 | * @param readLimit |
| 89 | * the number of characters that can be read before the mark is |
| 90 | * invalidated. |
| 91 | * @throws IllegalArgumentException |
| 92 | * if {@code readLimit < 0}. |
| 93 | * @throws IOException |
| 94 | * if an error occurs while setting a mark in this reader. |
| 95 | * @see #markSupported() |
| 96 | * @see #reset() |
nothing calls this directly
no outgoing calls
no test coverage detected