Polish contribution

See gh-24805
This commit is contained in:
Sam Brannen
2020-03-30 13:42:51 +02:00
parent e63d1cf12d
commit 9e30620ac2
8 changed files with 42 additions and 40 deletions

View File

@@ -398,18 +398,18 @@ public final class ContentDisposition {
Assert.notNull(filename, "'input' String` should not be null");
Assert.notNull(charset, "'charset' should not be null");
byte[] value = filename.getBytes(charset);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int index = 0;
while (index < value.length) {
byte b = value[index];
if (isRFC5987AttrChar(b)) {
bos.write((char) b);
baos.write((char) b);
index++;
}
else if (b == '%' && index < value.length - 2) {
char[] array = new char[]{(char) value[index + 1], (char) value[index + 2]};
try {
bos.write(Integer.parseInt(String.valueOf(array), 16));
baos.write(Integer.parseInt(String.valueOf(array), 16));
}
catch (NumberFormatException ex) {
throw new IllegalArgumentException(INVALID_HEADER_FIELD_PARAMETER_FORMAT, ex);
@@ -420,7 +420,7 @@ public final class ContentDisposition {
throw new IllegalArgumentException(INVALID_HEADER_FIELD_PARAMETER_FORMAT);
}
}
return StreamUtils.baosToString(bos, charset);
return StreamUtils.copyToString(baos, charset);
}
private static boolean isRFC5987AttrChar(byte c) {

View File

@@ -347,20 +347,20 @@ final class HierarchicalUriComponents extends UriComponents {
return source;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
for (byte b : bytes) {
if (type.isAllowed(b)) {
bos.write(b);
baos.write(b);
}
else {
bos.write('%');
baos.write('%');
char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16));
char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
bos.write(hex1);
bos.write(hex2);
baos.write(hex1);
baos.write(hex2);
}
}
return StreamUtils.baosToString(bos, charset);
return StreamUtils.copyToString(baos, charset);
}
private Type getHostType() {