Skip to content

Commit 361cbac

Browse files
committed
Sort members
1 parent e910218 commit 361cbac

File tree

9 files changed

+336
-336
lines changed

9 files changed

+336
-336
lines changed

src/main/java/org/apache/commons/io/build/AbstractOrigin.java

Lines changed: 166 additions & 166 deletions
Large diffs are not rendered by default.

src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ protected static ByteArrayOrigin newByteArrayOrigin(final byte[] origin) {
6161
return new ByteArrayOrigin(origin);
6262
}
6363

64+
/**
65+
* Constructs a new channel origin for a channel.
66+
*
67+
* @param origin the channel.
68+
* @return a new channel origin.
69+
* @since 2.21.0
70+
*/
71+
protected static ChannelOrigin newChannelOrigin(final Channel origin) {
72+
return new ChannelOrigin(origin);
73+
}
74+
6475
/**
6576
* Constructs a new CharSequence origin for a CharSequence.
6677
*
@@ -184,17 +195,6 @@ protected static WriterOrigin newWriterOrigin(final Writer origin) {
184195
return new WriterOrigin(origin);
185196
}
186197

187-
/**
188-
* Constructs a new channel origin for a channel.
189-
*
190-
* @param origin the channel.
191-
* @return a new channel origin.
192-
* @since 2.21.0
193-
*/
194-
protected static ChannelOrigin newChannelOrigin(final Channel origin) {
195-
return new ChannelOrigin(origin);
196-
}
197-
198198
/**
199199
* The underlying origin.
200200
*/
@@ -248,6 +248,17 @@ public B setByteArray(final byte[] origin) {
248248
return setOrigin(newByteArrayOrigin(origin));
249249
}
250250

251+
/**
252+
* Sets a new origin.
253+
*
254+
* @param origin the new origin.
255+
* @return {@code this} instance.
256+
* @since 2.21.0
257+
*/
258+
public B setChannel(final Channel origin) {
259+
return setOrigin(newChannelOrigin(origin));
260+
}
261+
251262
/**
252263
* Sets a new origin.
253264
*
@@ -381,15 +392,4 @@ public B setURI(final URI origin) {
381392
public B setWriter(final Writer origin) {
382393
return setOrigin(newWriterOrigin(origin));
383394
}
384-
385-
/**
386-
* Sets a new origin.
387-
*
388-
* @param origin the new origin.
389-
* @return {@code this} instance.
390-
* @since 2.21.0
391-
*/
392-
public B setChannel(final Channel origin) {
393-
return setOrigin(newChannelOrigin(origin));
394-
}
395395
}

src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ public int getBufferSizeDefault() {
120120
return bufferSizeDefault;
121121
}
122122

123+
/**
124+
* Gets a Channel from the origin with OpenOption[].
125+
*
126+
* @param channelType The channel type, not null.
127+
* @return A channel of the specified type.
128+
* @param <C> The channel type.
129+
* @throws IllegalStateException if the {@code origin} is {@code null}.
130+
* @throws UnsupportedOperationException if the origin cannot be converted to a {@link ReadableByteChannel}.
131+
* @throws IOException if an I/O error occurs.
132+
* @see AbstractOrigin#getChannel
133+
* @see #getOpenOptions()
134+
* @since 2.21.0
135+
*/
136+
public <C extends Channel> C getChannel(final Class<C> channelType) throws IOException {
137+
return checkOrigin().getChannel(channelType, getOpenOptions());
138+
}
139+
123140
/**
124141
* Gets a CharSequence from the origin with a Charset.
125142
*
@@ -260,23 +277,6 @@ public Writer getWriter() throws IOException {
260277
return checkOrigin().getWriter(getCharset(), getOpenOptions());
261278
}
262279

263-
/**
264-
* Gets a Channel from the origin with OpenOption[].
265-
*
266-
* @param channelType The channel type, not null.
267-
* @return A channel of the specified type.
268-
* @param <C> The channel type.
269-
* @throws IllegalStateException if the {@code origin} is {@code null}.
270-
* @throws UnsupportedOperationException if the origin cannot be converted to a {@link ReadableByteChannel}.
271-
* @throws IOException if an I/O error occurs.
272-
* @see AbstractOrigin#getChannel
273-
* @see #getOpenOptions()
274-
* @since 2.21.0
275-
*/
276-
public <C extends Channel> C getChannel(final Class<C> channelType) throws IOException {
277-
return checkOrigin().getChannel(channelType, getOpenOptions());
278-
}
279-
280280
/**
281281
* Sets the buffer size. Invalid input (bufferSize &lt;= 0) resets the value to its default.
282282
* <p>

src/main/java/org/apache/commons/io/channels/ByteArraySeekableByteChannel.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ public ByteArraySeekableByteChannel() {
8484
this(IOUtils.DEFAULT_BUFFER_SIZE);
8585
}
8686

87+
private ByteArraySeekableByteChannel(final byte[] data) {
88+
this.data = data;
89+
this.position = 0;
90+
this.size = data.length;
91+
}
92+
8793
/**
8894
* Constructs a new instance, with an internal buffer of the given capacity, in bytes.
8995
* <p>
@@ -102,12 +108,6 @@ public ByteArraySeekableByteChannel(final int size) {
102108
this.size = 0;
103109
}
104110

105-
private ByteArraySeekableByteChannel(final byte[] data) {
106-
this.data = data;
107-
this.position = 0;
108-
this.size = data.length;
109-
}
110-
111111
/**
112112
* Gets the raw byte array backing this channel, <em>this is not a copy</em>.
113113
* <p>
@@ -120,18 +120,6 @@ public byte[] array() {
120120
return data;
121121
}
122122

123-
/**
124-
* Gets a copy of the data stored in this channel.
125-
* <p>
126-
* The returned array is a copy of the internal buffer, sized to the actual data stored in this channel.
127-
* </p>
128-
*
129-
* @return a new byte array containing the data stored in this channel.
130-
*/
131-
public byte[] toByteArray() {
132-
return Arrays.copyOf(data, size);
133-
}
134-
135123
private void checkOpen() throws ClosedChannelException {
136124
if (!isOpen()) {
137125
throw new ClosedChannelException();
@@ -235,6 +223,18 @@ public long size() throws ClosedChannelException {
235223
}
236224
}
237225

226+
/**
227+
* Gets a copy of the data stored in this channel.
228+
* <p>
229+
* The returned array is a copy of the internal buffer, sized to the actual data stored in this channel.
230+
* </p>
231+
*
232+
* @return a new byte array containing the data stored in this channel.
233+
*/
234+
public byte[] toByteArray() {
235+
return Arrays.copyOf(data, size);
236+
}
237+
238238
@Override
239239
public SeekableByteChannel truncate(final long newSize) throws ClosedChannelException {
240240
checkOpen();

src/test/java/org/apache/commons/io/build/AbstractOriginTest.java

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ void beforeEach() throws IOException {
7979
setOriginRw(newOriginRw());
8080
}
8181

82+
private void checkRead(final ReadableByteChannel channel) throws IOException {
83+
final ByteBuffer buffer = ByteBuffer.allocate(RO_LENGTH);
84+
int read = channel.read(buffer);
85+
assertEquals(RO_LENGTH, read);
86+
assertArrayEquals(getFixtureByteArray(), buffer.array());
87+
// Channel is at EOF
88+
buffer.clear();
89+
read = channel.read(buffer);
90+
assertEquals(-1, read);
91+
}
92+
93+
private void checkWrite(final WritableByteChannel channel) throws IOException {
94+
final ByteBuffer buffer = ByteBuffer.wrap(getFixtureByteArray());
95+
final int written = channel.write(buffer);
96+
assertEquals(RO_LENGTH, written);
97+
}
98+
8299
@AfterEach
83100
void cleanup() {
84101
final T originRo = getOriginRo().get();
@@ -91,6 +108,14 @@ void cleanup() {
91108
}
92109
}
93110

111+
byte[] getFixtureByteArray() throws IOException {
112+
return IOUtils.resourceToByteArray(FILE_RES_RO);
113+
}
114+
115+
String getFixtureString() throws IOException {
116+
return IOUtils.resourceToString(FILE_RES_RO, StandardCharsets.UTF_8);
117+
}
118+
94119
protected AbstractOrigin<T, B> getOriginRo() {
95120
return Objects.requireNonNull(originRo, "originRo");
96121
}
@@ -108,24 +133,16 @@ private boolean isValid(final RandomAccessFile raf) throws IOException {
108133

109134
protected abstract B newOriginRw() throws IOException;
110135

111-
protected void setOriginRo(final AbstractOrigin<T, B> origin) {
112-
this.originRo = origin;
113-
}
114-
115-
protected void setOriginRw(final AbstractOrigin<T, B> origin) {
116-
this.originRw = origin;
117-
}
118-
119136
protected void resetOriginRw() throws IOException {
120137
// No-op
121138
}
122139

123-
byte[] getFixtureByteArray() throws IOException {
124-
return IOUtils.resourceToByteArray(FILE_RES_RO);
140+
protected void setOriginRo(final AbstractOrigin<T, B> origin) {
141+
this.originRo = origin;
125142
}
126143

127-
String getFixtureString() throws IOException {
128-
return IOUtils.resourceToString(FILE_RES_RO, StandardCharsets.UTF_8);
144+
protected void setOriginRw(final AbstractOrigin<T, B> origin) {
145+
this.originRw = origin;
129146
}
130147

131148
@Test
@@ -258,33 +275,6 @@ void testGetRandomAccessFile(final OpenOption openOption) throws IOException {
258275
}
259276
}
260277

261-
@Test
262-
void testGetReader() throws IOException {
263-
try (Reader reader = getOriginRo().getReader(Charset.defaultCharset())) {
264-
assertNotNull(reader);
265-
}
266-
setOriginRo(newOriginRo());
267-
try (Reader reader = getOriginRo().getReader(null)) {
268-
assertNotNull(reader);
269-
}
270-
setOriginRo(newOriginRo());
271-
try (Reader reader = getOriginRo().getReader(StandardCharsets.UTF_8)) {
272-
assertNotNull(reader);
273-
assertEquals(getFixtureString(), IOUtils.toString(reader));
274-
}
275-
}
276-
277-
@Test
278-
void testGetWriter() throws IOException {
279-
try (Writer writer = getOriginRw().getWriter(Charset.defaultCharset())) {
280-
assertNotNull(writer);
281-
}
282-
setOriginRw(newOriginRw());
283-
try (Writer writer = getOriginRw().getWriter(null)) {
284-
assertNotNull(writer);
285-
}
286-
}
287-
288278
@Test
289279
void testGetReadableByteChannel() throws IOException {
290280
try (ReadableByteChannel channel =
@@ -304,15 +294,20 @@ void testGetReadableByteChannel() throws IOException {
304294
}
305295
}
306296

307-
private void checkRead(final ReadableByteChannel channel) throws IOException {
308-
final ByteBuffer buffer = ByteBuffer.allocate(RO_LENGTH);
309-
int read = channel.read(buffer);
310-
assertEquals(RO_LENGTH, read);
311-
assertArrayEquals(getFixtureByteArray(), buffer.array());
312-
// Channel is at EOF
313-
buffer.clear();
314-
read = channel.read(buffer);
315-
assertEquals(-1, read);
297+
@Test
298+
void testGetReader() throws IOException {
299+
try (Reader reader = getOriginRo().getReader(Charset.defaultCharset())) {
300+
assertNotNull(reader);
301+
}
302+
setOriginRo(newOriginRo());
303+
try (Reader reader = getOriginRo().getReader(null)) {
304+
assertNotNull(reader);
305+
}
306+
setOriginRo(newOriginRo());
307+
try (Reader reader = getOriginRo().getReader(StandardCharsets.UTF_8)) {
308+
assertNotNull(reader);
309+
assertEquals(getFixtureString(), IOUtils.toString(reader));
310+
}
316311
}
317312

318313
@Test
@@ -367,10 +362,15 @@ void testGetWritableByteChannel() throws IOException {
367362
}
368363
}
369364

370-
private void checkWrite(final WritableByteChannel channel) throws IOException {
371-
final ByteBuffer buffer = ByteBuffer.wrap(getFixtureByteArray());
372-
final int written = channel.write(buffer);
373-
assertEquals(RO_LENGTH, written);
365+
@Test
366+
void testGetWriter() throws IOException {
367+
try (Writer writer = getOriginRw().getWriter(Charset.defaultCharset())) {
368+
assertNotNull(writer);
369+
}
370+
setOriginRw(newOriginRw());
371+
try (Writer writer = getOriginRw().getWriter(null)) {
372+
assertNotNull(writer);
373+
}
374374
}
375375

376376
@Test

0 commit comments

Comments
 (0)