| 37 | import java.util.function.Consumer; |
| 38 | |
| 39 | public abstract class InStream extends InputStream { |
| 40 | |
| 41 | private static final Logger LOG = LoggerFactory.getLogger(InStream.class); |
| 42 | public static final int PROTOBUF_MESSAGE_MAX_LIMIT = 1024 << 20; // 1GB |
| 43 | |
| 44 | protected final Object name; |
| 45 | protected final long offset; |
| 46 | protected long length; |
| 47 | protected DiskRangeList bytes; |
| 48 | // position in the stream (0..length) |
| 49 | protected long position; |
| 50 | |
| 51 | public InStream(Object name, long offset, long length) { |
| 52 | this.name = name; |
| 53 | this.offset = offset; |
| 54 | this.length = length; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return name.toString(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public abstract void close(); |
| 64 | |
| 65 | /** |
| 66 | * Set the current range |
| 67 | * @param newRange the block that is current |
| 68 | * @param isJump if this was a seek instead of a natural read |
| 69 | */ |
| 70 | protected abstract void setCurrent(DiskRangeList newRange, |
| 71 | boolean isJump); |
| 72 | /** |
| 73 | * Reset the input to a new set of data. |
| 74 | * @param input the input data |
| 75 | */ |
| 76 | protected void reset(DiskRangeList input) { |
| 77 | bytes = input; |
| 78 | while (input != null && |
| 79 | (input.getEnd() <= offset || |
| 80 | input.getOffset() > offset + length)) { |
| 81 | input = input.next; |
| 82 | } |
| 83 | if (input == null || input.getOffset() <= offset) { |
| 84 | position = 0; |
| 85 | } else { |
| 86 | position = input.getOffset() - offset; |
| 87 | } |
| 88 | setCurrent(input, true); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Reset the input to a new set of data with a different length. |
| 93 | * |
| 94 | * in some cases, after resetting an UncompressedStream, its actual length is longer than its initial length. |
| 95 | * Prior to ORC-516, InStream.UncompressedStream class had the 'length' field and the length was modifiable in |
| 96 | * the reset() method. It was used in SettableUncompressedStream class in setBuffers() method. |
nothing calls this directly
no outgoing calls
no test coverage detected