embulk-input-s3 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,128 +0,0 @@
1
- package org.embulk.input.s3;
2
-
3
- import java.io.InputStream;
4
- import java.io.IOException;
5
-
6
- public class RetryableInputStream
7
- extends InputStream
8
- {
9
- public interface Opener
10
- {
11
- public InputStream open(long offset, Exception exception) throws IOException;
12
- }
13
-
14
- private final Opener opener;
15
- protected InputStream in;
16
- private long offset;
17
- private long markedOffset;
18
-
19
- public RetryableInputStream(InputStream initialInputStream, Opener reopener)
20
- {
21
- this.opener = reopener;
22
- this.in = initialInputStream;
23
- this.offset = 0L;
24
- this.markedOffset = 0L;
25
- }
26
-
27
- public RetryableInputStream(Opener opener) throws IOException
28
- {
29
- this(opener.open(0, null), opener);
30
- }
31
-
32
- private void reopen(Exception exception) throws IOException
33
- {
34
- if (in != null) {
35
- in.close();
36
- in = null;
37
- }
38
- in = opener.open(offset, exception);
39
- }
40
-
41
- @Override
42
- public int read() throws IOException
43
- {
44
- while (true) {
45
- try {
46
- int v = in.read();
47
- offset += 1;
48
- return v;
49
- } catch (IOException | RuntimeException ex) {
50
- reopen(ex);
51
- }
52
- }
53
- }
54
-
55
- @Override
56
- public int read(byte[] b) throws IOException
57
- {
58
- while (true) {
59
- try {
60
- int r = in.read(b);
61
- offset += r;
62
- return r;
63
- } catch (IOException | RuntimeException ex) {
64
- reopen(ex);
65
- }
66
- }
67
- }
68
-
69
- @Override
70
- public int read(byte[] b, int off, int len) throws IOException
71
- {
72
- while (true) {
73
- try {
74
- int r = in.read(b, off, len);
75
- offset += r;
76
- return r;
77
- } catch (IOException | RuntimeException ex) {
78
- reopen(ex);
79
- }
80
- }
81
- }
82
-
83
- @Override
84
- public long skip(long n) throws IOException
85
- {
86
- while (true) {
87
- try {
88
- long r = in.skip(n);
89
- offset += r;
90
- return r;
91
- } catch (IOException | RuntimeException ex) {
92
- reopen(ex);
93
- }
94
- }
95
- }
96
-
97
- @Override
98
- public int available() throws IOException
99
- {
100
- return in.available();
101
- }
102
-
103
- @Override
104
- public void close() throws IOException
105
- {
106
- in.close();
107
- }
108
-
109
- @Override
110
- public void mark(int readlimit)
111
- {
112
- in.mark(readlimit);
113
- markedOffset = offset;
114
- }
115
-
116
- @Override
117
- public void reset() throws IOException
118
- {
119
- in.reset();
120
- offset = markedOffset;
121
- }
122
-
123
- @Override
124
- public boolean markSupported()
125
- {
126
- return in.markSupported();
127
- }
128
- }