This commit is contained in:
Looly 2024-08-08 21:08:31 +08:00
parent 52cf8fdc71
commit fbe899dd2a
3 changed files with 20 additions and 22 deletions

View File

@ -849,8 +849,8 @@ public class IoUtil extends NioUtil {
* @throws IORuntimeException IO异常
* @since 3.1.1
*/
public static void writeUtf8(final OutputStream out, final boolean isCloseOut, final Object... contents) throws IORuntimeException {
write(out, CharsetUtil.UTF_8, isCloseOut, contents);
public static void writeUtf8(final OutputStream out, final boolean isCloseOut, final CharSequence... contents) throws IORuntimeException {
writeStrs(out, CharsetUtil.UTF_8, isCloseOut, contents);
}
/**
@ -863,8 +863,8 @@ public class IoUtil extends NioUtil {
* @throws IORuntimeException IO异常
* @since 3.0.9
*/
public static void write(final OutputStream out, final Charset charset, final boolean isCloseOut, final Object... contents) throws IORuntimeException {
StreamWriter.of(out, isCloseOut).writeStr(charset, contents);
public static void writeStrs(final OutputStream out, final Charset charset, final boolean isCloseOut, final CharSequence... contents) throws IORuntimeException {
StreamWriter.of(out, isCloseOut).writeStrs(charset, contents);
}
/**
@ -876,7 +876,7 @@ public class IoUtil extends NioUtil {
* @throws IORuntimeException IO异常
*/
public static void writeObjects(final OutputStream out, final boolean isCloseOut, final Object... contents) throws IORuntimeException {
StreamWriter.of(out, isCloseOut).writeObj(contents);
StreamWriter.of(out, isCloseOut).writeObjs(contents);
}
// endregion ----------------------------------------------------------------------------------------------- write

View File

@ -12,10 +12,8 @@
package org.dromara.hutool.core.io.stream;
import org.dromara.hutool.core.convert.Convert;
import org.dromara.hutool.core.io.IORuntimeException;
import org.dromara.hutool.core.io.IoUtil;
import org.dromara.hutool.core.text.StrUtil;
import java.io.IOException;
import java.io.ObjectOutputStream;
@ -80,7 +78,7 @@ public class StreamWriter {
* @param contents 写入的内容
* @throws IORuntimeException IO异常
*/
public void writeObj(final Object... contents) throws IORuntimeException {
public void writeObjs(final Object... contents) throws IORuntimeException {
ObjectOutputStream osw = null;
try {
osw = out instanceof ObjectOutputStream ? (ObjectOutputStream) out : new ObjectOutputStream(out);
@ -106,13 +104,13 @@ public class StreamWriter {
* @param contents 写入的内容调用toString()方法不包括不会自动换行
* @throws IORuntimeException IO异常
*/
public void writeStr(final Charset charset, final Object... contents) throws IORuntimeException {
public void writeStrs(final Charset charset, final CharSequence... contents) throws IORuntimeException {
OutputStreamWriter osw = null;
try {
osw = IoUtil.toWriter(out, charset);
for (final Object content : contents) {
for (final CharSequence content : contents) {
if (content != null) {
osw.write(Convert.toStr(content, StrUtil.EMPTY));
osw.write(content.toString());
}
}
osw.flush();

View File

@ -182,7 +182,7 @@ public class MultipartOutputStream extends OutputStream {
}
// 内容
write("\r\n");
write(StrUtil.CRLF);
resource.writeTo(this);
}
@ -200,9 +200,9 @@ public class MultipartOutputStream extends OutputStream {
/**
* 写出对象
*
* @param objs 写出的对象转换为字符串
* @param contents 写出的字符串
*/
private void write(final Object... objs) {
IoUtil.write(this, this.charset, false, objs);
private void write(final CharSequence... contents) {
IoUtil.writeStrs(this, this.charset, false, contents);
}
}