Skip to content

Commit 8fe530c

Browse files
committed
Polishing (backported from 5.2.x)
1 parent 5b4f3e8 commit 8fe530c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskScheduler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 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,10 +37,11 @@
3737
*
3838
* @author Juergen Hoeller
3939
* @since 4.0
40+
* @see javax.enterprise.concurrent.ManagedScheduledExecutorService
4041
*/
4142
public class DefaultManagedTaskScheduler extends ConcurrentTaskScheduler implements InitializingBean {
4243

43-
private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
44+
private final JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
4445

4546
@Nullable
4647
private String jndiName = "java:comp/DefaultManagedScheduledExecutorService";

spring-core/src/main/java/org/springframework/util/StreamUtils.java

Lines changed: 16 additions & 15 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-2020 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.
@@ -46,7 +46,7 @@
4646
public abstract class StreamUtils {
4747

4848
/**
49-
* The default buffer size used why copying bytes.
49+
* The default buffer size used when copying bytes.
5050
*/
5151
public static final int BUFFER_SIZE = 4096;
5252

@@ -55,7 +55,7 @@ public abstract class StreamUtils {
5555

5656
/**
5757
* Copy the contents of the given InputStream into a new byte array.
58-
* Leaves the stream open when done.
58+
* <p>Leaves the stream open when done.
5959
* @param in the stream to copy from (may be {@code null} or empty)
6060
* @return the new byte array that has been copied to (possibly empty)
6161
* @throws IOException in case of I/O errors
@@ -72,8 +72,9 @@ public static byte[] copyToByteArray(@Nullable InputStream in) throws IOExceptio
7272

7373
/**
7474
* Copy the contents of the given InputStream into a String.
75-
* Leaves the stream open when done.
75+
* <p>Leaves the stream open when done.
7676
* @param in the InputStream to copy from (may be {@code null} or empty)
77+
* @param charset the {@link Charset} to use to decode the bytes
7778
* @return the String that has been copied to (possibly empty)
7879
* @throws IOException in case of I/O errors
7980
*/
@@ -85,16 +86,16 @@ public static String copyToString(@Nullable InputStream in, Charset charset) thr
8586
StringBuilder out = new StringBuilder();
8687
InputStreamReader reader = new InputStreamReader(in, charset);
8788
char[] buffer = new char[BUFFER_SIZE];
88-
int bytesRead = -1;
89-
while ((bytesRead = reader.read(buffer)) != -1) {
90-
out.append(buffer, 0, bytesRead);
89+
int charsRead;
90+
while ((charsRead = reader.read(buffer)) != -1) {
91+
out.append(buffer, 0, charsRead);
9192
}
9293
return out.toString();
9394
}
9495

9596
/**
9697
* Copy the contents of the given byte array to the given OutputStream.
97-
* Leaves the stream open when done.
98+
* <p>Leaves the stream open when done.
9899
* @param in the byte array to copy from
99100
* @param out the OutputStream to copy to
100101
* @throws IOException in case of I/O errors
@@ -107,16 +108,16 @@ public static void copy(byte[] in, OutputStream out) throws IOException {
107108
}
108109

109110
/**
110-
* Copy the contents of the given String to the given output OutputStream.
111-
* Leaves the stream open when done.
111+
* Copy the contents of the given String to the given OutputStream.
112+
* <p>Leaves the stream open when done.
112113
* @param in the String to copy from
113114
* @param charset the Charset
114115
* @param out the OutputStream to copy to
115116
* @throws IOException in case of I/O errors
116117
*/
117118
public static void copy(String in, Charset charset, OutputStream out) throws IOException {
118119
Assert.notNull(in, "No input String specified");
119-
Assert.notNull(charset, "No charset specified");
120+
Assert.notNull(charset, "No Charset specified");
120121
Assert.notNull(out, "No OutputStream specified");
121122

122123
Writer writer = new OutputStreamWriter(out, charset);
@@ -126,7 +127,7 @@ public static void copy(String in, Charset charset, OutputStream out) throws IOE
126127

127128
/**
128129
* Copy the contents of the given InputStream to the given OutputStream.
129-
* Leaves both streams open when done.
130+
* <p>Leaves both streams open when done.
130131
* @param in the InputStream to copy from
131132
* @param out the OutputStream to copy to
132133
* @return the number of bytes copied
@@ -138,7 +139,7 @@ public static int copy(InputStream in, OutputStream out) throws IOException {
138139

139140
int byteCount = 0;
140141
byte[] buffer = new byte[BUFFER_SIZE];
141-
int bytesRead = -1;
142+
int bytesRead;
142143
while ((bytesRead = in.read(buffer)) != -1) {
143144
out.write(buffer, 0, bytesRead);
144145
byteCount += bytesRead;
@@ -170,7 +171,7 @@ public static long copyRange(InputStream in, OutputStream out, long start, long
170171
}
171172

172173
long bytesToCopy = end - start + 1;
173-
byte[] buffer = new byte[StreamUtils.BUFFER_SIZE];
174+
byte[] buffer = new byte[(int) Math.min(StreamUtils.BUFFER_SIZE, bytesToCopy)];
174175
while (bytesToCopy > 0) {
175176
int bytesRead = in.read(buffer);
176177
if (bytesRead == -1) {
@@ -190,7 +191,7 @@ else if (bytesRead <= bytesToCopy) {
190191

191192
/**
192193
* Drain the remaining content of the given InputStream.
193-
* Leaves the InputStream open when done.
194+
* <p>Leaves the InputStream open when done.
194195
* @param in the InputStream to drain
195196
* @return the number of bytes read
196197
* @throws IOException in case of I/O errors

0 commit comments

Comments
 (0)