Improve usage of ByteArrayOutputStream/ByteArrayInputStream

Closes gh-24805
This commit is contained in:
Сергей Цыпанов
2020-03-28 19:24:09 +02:00
committed by Sam Brannen
parent 821984a5cf
commit e63d1cf12d
10 changed files with 47 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StreamUtils;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -419,7 +420,7 @@ public final class ContentDisposition {
throw new IllegalArgumentException(INVALID_HEADER_FIELD_PARAMETER_FORMAT);
}
}
return new String(bos.toByteArray(), charset);
return StreamUtils.baosToString(bos, charset);
}
private static boolean isRFC5987AttrChar(byte c) {

View File

@@ -36,6 +36,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
/**
@@ -359,7 +360,7 @@ final class HierarchicalUriComponents extends UriComponents {
bos.write(hex2);
}
}
return new String(bos.toByteArray(), charset);
return StreamUtils.baosToString(bos, charset);
}
private Type getHostType() {