@Override public int read(byte[] b) throws IOException { ensureOpened(); while (true) { try { int r = in.read(b); offset += r; return r; } catch (IOException | RuntimeException ex) { reopen(ex); } } }
@Override public void reset() throws IOException { ensureOpened(); in.reset(); offset = markedOffset; }
private void ensureOpened() throws IOException { if (in == null) { if (closed) { throw new IOException("stream closed"); } reopen(lastClosedCause); } } }
@Override public InputStreamWithHints openNextWithHints() throws IOException { if (!iterator.hasNext()) { return null; } final String key = iterator.next(); final GetObjectRequest request = new GetObjectRequest(bucket, key); S3Object object = new DefaultRetryable<S3Object>(format("Getting object '%s'", request.getKey())) { @Override public S3Object call() { return client.getObject(request); } }.executeWithCheckedException(retryExec, IOException.class); long objectSize = object.getObjectMetadata().getContentLength(); // Some plugin users are parsing this output to get file list. // Keep it for now but might be removed in the future. LOGGER.info("Open S3Object with bucket [{}], key [{}], with size [{}]", bucket, key, objectSize); InputStream inputStream = new ResumableInputStream(object.getObjectContent(), new S3InputStreamReopener(client, request, objectSize, retryExec)); return new InputStreamWithHints(inputStream, String.format("s3://%s/%s", bucket, key)); }
@Override public int available() throws IOException { ensureOpened(); return in.available(); }
@Override public int read() throws IOException { ensureOpened(); while (true) { try { int v = in.read(); offset += 1; return v; } catch (IOException | RuntimeException ex) { reopen(ex); } } }
@Override public void mark(int readlimit) { try { ensureOpened(); } catch (IOException ex) { throw new RuntimeException(ex); } in.mark(readlimit); markedOffset = offset; }
@Override public long skip(long n) throws IOException { ensureOpened(); while (true) { try { long r = in.skip(n); offset += r; return r; } catch (IOException | RuntimeException ex) { reopen(ex); } } }
@Override public boolean markSupported() { try { ensureOpened(); } catch (IOException ex) { throw new RuntimeException(ex); } return in.markSupported(); }
@Override public int read(byte[] b, int off, int len) throws IOException { ensureOpened(); while (true) { try { int r = in.read(b, off, len); offset += r; return r; } catch (IOException | RuntimeException ex) { reopen(ex); } } }