Skip to content

Commit 72dddfb

Browse files
committed
Polishing
1 parent dc3f953 commit 72dddfb

File tree

6 files changed

+47
-49
lines changed

6 files changed

+47
-49
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ public TypeDescriptor(Property property) {
110110
}
111111

112112
/**
113-
* Create a new type descriptor from a {@link ResolvableType}. This protected
114-
* constructor is used internally and may also be used by subclasses that support
115-
* non-Java languages with extended type systems.
113+
* Create a new type descriptor from a {@link ResolvableType}.
114+
* <p>This constructor is used internally and may also be used by subclasses
115+
* that support non-Java languages with extended type systems. It is public
116+
* as of 5.1.4 whereas it was protected before.
116117
* @param resolvableType the resolvable type
117118
* @param type the backing type (or {@code null} if it should get resolved)
118119
* @param annotations the type annotations

spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -122,7 +122,9 @@ public interface DataBuffer {
122122
* @return this buffer
123123
* @since 5.1.4
124124
*/
125-
DataBuffer ensureCapacity(int capacity);
125+
default DataBuffer ensureCapacity(int capacity) {
126+
return this;
127+
}
126128

127129
/**
128130
* Return the position from which this buffer will read.
@@ -242,18 +244,18 @@ public interface DataBuffer {
242244
* @since 5.1.4
243245
*/
244246
default DataBuffer write(CharSequence charSequence, Charset charset) {
245-
Assert.notNull(charSequence, "'charSequence' must not be null");
246-
Assert.notNull(charset, "'charset' must not be null");
247+
Assert.notNull(charSequence, "CharSequence must not be null");
248+
Assert.notNull(charset, "Charset must not be null");
247249
CharsetEncoder charsetEncoder = charset.newEncoder()
248250
.onMalformedInput(CodingErrorAction.REPLACE)
249251
.onUnmappableCharacter(CodingErrorAction.REPLACE);
250252
CharBuffer inBuffer = CharBuffer.wrap(charSequence);
251253
int estimatedSize = (int) (inBuffer.remaining() * charsetEncoder.averageBytesPerChar());
252254
ByteBuffer outBuffer = ensureCapacity(estimatedSize)
253255
.asByteBuffer(writePosition(), writableByteCount());
254-
for (; ; ) {
255-
CoderResult cr = inBuffer.hasRemaining() ?
256-
charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW;
256+
while (true) {
257+
CoderResult cr = (inBuffer.hasRemaining() ?
258+
charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW);
257259
if (cr.isUnderflow()) {
258260
cr = charsetEncoder.flush(outBuffer);
259261
}

spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
*
3838
* @author Arjen Poutsma
3939
* @author Juergen Hoeller
40+
* @author Brian Clozel
4041
* @since 5.0
4142
* @see DefaultDataBufferFactory
4243
*/
@@ -99,8 +100,7 @@ public DefaultDataBufferFactory factory() {
99100

100101
@Override
101102
public int indexOf(IntPredicate predicate, int fromIndex) {
102-
Assert.notNull(predicate, "'predicate' must not be null");
103-
103+
Assert.notNull(predicate, "IntPredicate must not be null");
104104
if (fromIndex < 0) {
105105
fromIndex = 0;
106106
}
@@ -118,7 +118,7 @@ else if (fromIndex >= this.writePosition) {
118118

119119
@Override
120120
public int lastIndexOf(IntPredicate predicate, int fromIndex) {
121-
Assert.notNull(predicate, "'predicate' must not be null");
121+
Assert.notNull(predicate, "IntPredicate must not be null");
122122
int i = Math.min(fromIndex, this.writePosition - 1);
123123
for (; i >= 0; i--) {
124124
byte b = this.byteBuffer.get(i);
@@ -149,7 +149,6 @@ public DefaultDataBuffer readPosition(int readPosition) {
149149
assertIndex(readPosition >= 0, "'readPosition' %d must be >= 0", readPosition);
150150
assertIndex(readPosition <= this.writePosition, "'readPosition' %d must be <= %d",
151151
readPosition, this.writePosition);
152-
153152
this.readPosition = readPosition;
154153
return this;
155154
}
@@ -165,7 +164,6 @@ public DefaultDataBuffer writePosition(int writePosition) {
165164
writePosition, this.readPosition);
166165
assertIndex(writePosition <= this.capacity, "'writePosition' %d must be <= %d",
167166
writePosition, this.capacity);
168-
169167
this.writePosition = writePosition;
170168
return this;
171169
}
@@ -177,9 +175,9 @@ public int capacity() {
177175

178176
@Override
179177
public DefaultDataBuffer capacity(int newCapacity) {
180-
Assert.isTrue(newCapacity > 0,
181-
String.format("'newCapacity' %d must be higher than 0", newCapacity));
182-
178+
if (newCapacity <= 0) {
179+
throw new IllegalArgumentException(String.format("'newCapacity' %d must be higher than 0", newCapacity));
180+
}
183181
int readPosition = readPosition();
184182
int writePosition = writePosition();
185183
int oldCapacity = capacity();
@@ -225,15 +223,13 @@ public DataBuffer ensureCapacity(int length) {
225223
}
226224

227225
private static ByteBuffer allocate(int capacity, boolean direct) {
228-
return direct ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity);
226+
return (direct ? ByteBuffer.allocateDirect(capacity) : ByteBuffer.allocate(capacity));
229227
}
230228

231229
@Override
232230
public byte getByte(int index) {
233231
assertIndex(index >= 0, "index %d must be >= 0", index);
234-
assertIndex(index <= this.writePosition - 1, "index %d must be <= %d",
235-
index, this.writePosition - 1);
236-
232+
assertIndex(index <= this.writePosition - 1, "index %d must be <= %d", index, this.writePosition - 1);
237233
return this.byteBuffer.get(index);
238234
}
239235

@@ -249,14 +245,14 @@ public byte read() {
249245

250246
@Override
251247
public DefaultDataBuffer read(byte[] destination) {
252-
Assert.notNull(destination, "'destination' must not be null");
248+
Assert.notNull(destination, "Byte array must not be null");
253249
read(destination, 0, destination.length);
254250
return this;
255251
}
256252

257253
@Override
258254
public DefaultDataBuffer read(byte[] destination, int offset, int length) {
259-
Assert.notNull(destination, "'destination' must not be null");
255+
Assert.notNull(destination, "Byte array must not be null");
260256
assertIndex(this.readPosition <= this.writePosition - length,
261257
"readPosition %d and length %d should be smaller than writePosition %d",
262258
this.readPosition, length, this.writePosition);
@@ -281,14 +277,14 @@ public DefaultDataBuffer write(byte b) {
281277

282278
@Override
283279
public DefaultDataBuffer write(byte[] source) {
284-
Assert.notNull(source, "'source' must not be null");
280+
Assert.notNull(source, "Byte array must not be null");
285281
write(source, 0, source.length);
286282
return this;
287283
}
288284

289285
@Override
290286
public DefaultDataBuffer write(byte[] source, int offset, int length) {
291-
Assert.notNull(source, "'source' must not be null");
287+
Assert.notNull(source, "Byte array must not be null");
292288
ensureCapacity(length);
293289

294290
ByteBuffer tmp = this.byteBuffer.duplicate();
@@ -309,11 +305,12 @@ public DefaultDataBuffer write(DataBuffer... buffers) {
309305
}
310306

311307
@Override
312-
public DefaultDataBuffer write(ByteBuffer... byteBuffers) {
313-
Assert.notEmpty(byteBuffers, "'byteBuffers' must not be empty");
314-
int capacity = Arrays.stream(byteBuffers).mapToInt(ByteBuffer::remaining).sum();
315-
ensureCapacity(capacity);
316-
Arrays.stream(byteBuffers).forEach(this::write);
308+
public DefaultDataBuffer write(ByteBuffer... buffers) {
309+
if (!ObjectUtils.isEmpty(buffers)) {
310+
int capacity = Arrays.stream(buffers).mapToInt(ByteBuffer::remaining).sum();
311+
ensureCapacity(capacity);
312+
Arrays.stream(buffers).forEach(this::write);
313+
}
317314
return this;
318315
}
319316

@@ -442,7 +439,7 @@ private void checkIndex(int index, int length) {
442439
assertIndex(length <= this.capacity, "length %d must be <= %d", index, this.capacity);
443440
}
444441

445-
private static void assertIndex(boolean expression, String format, Object... args) {
442+
private void assertIndex(boolean expression, String format, Object... args) {
446443
if (!expression) {
447444
String message = String.format(format, args);
448445
throw new IndexOutOfBoundsException(message);

spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
3636
* {@link ByteBuf}. Typically constructed with {@link NettyDataBufferFactory}.
3737
*
3838
* @author Arjen Poutsma
39+
* @author Brian Clozel
3940
* @since 5.0
4041
*/
4142
public class NettyDataBuffer implements PooledDataBuffer {
@@ -240,8 +241,8 @@ public NettyDataBuffer write(ByteBuf... byteBufs) {
240241

241242
@Override
242243
public DataBuffer write(CharSequence charSequence, Charset charset) {
243-
Assert.notNull(charSequence, "'charSequence' must not be null");
244-
Assert.notNull(charset, "'charset' must not be null");
244+
Assert.notNull(charSequence, "CharSequence must not be null");
245+
Assert.notNull(charset, "Charset must not be null");
245246
if (StandardCharsets.UTF_8.equals(charset)) {
246247
ByteBufUtil.writeUtf8(this.byteBuf, charSequence);
247248
}

spring-core/src/test/java/org/springframework/core/io/buffer/LeakAwareDataBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -186,8 +186,8 @@ public DataBuffer write(DataBuffer... buffers) {
186186
}
187187

188188
@Override
189-
public DataBuffer write(ByteBuffer... byteBuffers) {
190-
return this.delegate.write(byteBuffers);
189+
public DataBuffer write(ByteBuffer... buffers) {
190+
return this.delegate.write(buffers);
191191
}
192192

193193
@Override

spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -140,7 +140,6 @@ private class RequestBodyPublisher extends AbstractListenerReadPublisher<DataBuf
140140

141141
private final ByteBufferPool byteBufferPool;
142142

143-
144143
public RequestBodyPublisher(HttpServerExchange exchange, DataBufferFactory bufferFactory) {
145144
super(UndertowServerHttpRequest.this.getLogPrefix());
146145
this.channel = exchange.getRequestChannel();
@@ -207,6 +206,7 @@ protected void discardData() {
207206
}
208207
}
209208

209+
210210
private static class UndertowDataBuffer implements PooledDataBuffer {
211211

212212
private final DataBuffer dataBuffer;
@@ -316,8 +316,7 @@ public DataBuffer read(byte[] destination) {
316316
}
317317

318318
@Override
319-
public DataBuffer read(byte[] destination, int offset,
320-
int length) {
319+
public DataBuffer read(byte[] destination, int offset, int length) {
321320
return this.dataBuffer.read(destination, offset, length);
322321
}
323322

@@ -332,20 +331,17 @@ public DataBuffer write(byte[] source) {
332331
}
333332

334333
@Override
335-
public DataBuffer write(byte[] source, int offset,
336-
int length) {
334+
public DataBuffer write(byte[] source, int offset, int length) {
337335
return this.dataBuffer.write(source, offset, length);
338336
}
339337

340338
@Override
341-
public DataBuffer write(
342-
DataBuffer... buffers) {
339+
public DataBuffer write(DataBuffer... buffers) {
343340
return this.dataBuffer.write(buffers);
344341
}
345342

346343
@Override
347-
public DataBuffer write(
348-
ByteBuffer... byteBuffers) {
344+
public DataBuffer write(ByteBuffer... byteBuffers) {
349345
return this.dataBuffer.write(byteBuffers);
350346
}
351347

@@ -384,4 +380,5 @@ public OutputStream asOutputStream() {
384380
return this.dataBuffer.asOutputStream();
385381
}
386382
}
383+
387384
}

0 commit comments

Comments
 (0)