From f5cb27a608baeed78305b9ae36eb009eb64ce113 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 28 Feb 2023 22:45:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEJDK-8080225=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=86=E9=83=A8=E5=88=86=E6=96=B0=E5=BB=BA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B5=81=E5=92=8C=E6=96=87=E4=BB=B6=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=B5=81=E7=9A=84=E5=88=9B=E5=BB=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../cn/hutool/core/img/gif/AnimatedGifEncoder.java | 5 +++-- .../main/java/cn/hutool/core/img/gif/GifDecoder.java | 5 +++-- .../src/main/java/cn/hutool/core/io/FileUtil.java | 12 +++++------- .../main/java/cn/hutool/core/io/file/FileWriter.java | 10 ++++++---- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97b76079f..d3a5bd201 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### 🐣新特性 * 【core 】 PhoneUtil.isTel400800支持400-XXX-XXXX格式(issue#2929@Github) * 【core 】 build(pom): 添加 Automatic-Module-Name属性(pr#2926@Github) +* 【core 】 根据JDK-8080225修改了部分新建文件输入流和文件输出流的创建方式(pr#2930@Github) ### 🐞Bug修复 * 【db 】 修复识别JDBC驱动时重复问题(pr#940@Gitee) diff --git a/hutool-core/src/main/java/cn/hutool/core/img/gif/AnimatedGifEncoder.java b/hutool-core/src/main/java/cn/hutool/core/img/gif/AnimatedGifEncoder.java index f1cf8df40..551d55736 100755 --- a/hutool-core/src/main/java/cn/hutool/core/img/gif/AnimatedGifEncoder.java +++ b/hutool-core/src/main/java/cn/hutool/core/img/gif/AnimatedGifEncoder.java @@ -5,9 +5,10 @@ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.io.BufferedOutputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; /** * 动态GIF动画生成器,可生成一个或多个帧的GIF。 @@ -296,7 +297,7 @@ public class AnimatedGifEncoder { public boolean start(String file) { boolean ok; try { - out = new BufferedOutputStream(new FileOutputStream(file)); + out = new BufferedOutputStream(Files.newOutputStream(Paths.get(file))); ok = start(out); closeStream = true; } catch (IOException e) { diff --git a/hutool-core/src/main/java/cn/hutool/core/img/gif/GifDecoder.java b/hutool-core/src/main/java/cn/hutool/core/img/gif/GifDecoder.java index ecbb6450e..23da5136d 100755 --- a/hutool-core/src/main/java/cn/hutool/core/img/gif/GifDecoder.java +++ b/hutool-core/src/main/java/cn/hutool/core/img/gif/GifDecoder.java @@ -10,10 +10,11 @@ import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.io.BufferedInputStream; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; /** @@ -339,7 +340,7 @@ public class GifDecoder { URL url = new URL(name); in = new BufferedInputStream(url.openStream()); } else { - in = new BufferedInputStream(new FileInputStream(name)); + in = new BufferedInputStream(Files.newInputStream(Paths.get(name))); } status = read(in); } catch (IOException e) { diff --git a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java index db77963f6..809a2dfa1 100755 --- a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java @@ -29,9 +29,7 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileFilter; -import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.LineNumberReader; @@ -1917,7 +1915,7 @@ public class FileUtil extends PathUtil { */ public static BOMInputStream getBOMInputStream(File file) throws IORuntimeException { try { - return new BOMInputStream(new FileInputStream(file)); + return new BOMInputStream(Files.newInputStream(file.toPath())); } catch (IOException e) { throw new IORuntimeException(e); } @@ -2561,8 +2559,8 @@ public class FileUtil extends PathUtil { public static BufferedOutputStream getOutputStream(File file) throws IORuntimeException { final OutputStream out; try { - out = new FileOutputStream(touch(file)); - } catch (IOException e) { + out = Files.newOutputStream(touch(file).toPath()); + } catch (final IOException e) { throw new IORuntimeException(e); } return IoUtil.toBuffered(out); @@ -3337,8 +3335,8 @@ public class FileUtil extends PathUtil { throw new IllegalArgumentException("Checksums can't be computed on directories"); } try { - return IoUtil.checksum(new FileInputStream(file), checksum); - } catch (FileNotFoundException e) { + return IoUtil.checksum(Files.newInputStream(file.toPath()), checksum); + } catch (IOException e) { throw new IORuntimeException(e); } } diff --git a/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java b/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java index 45c95107e..f07fbd0ad 100644 --- a/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/file/FileWriter.java @@ -13,9 +13,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.Charset; +import java.nio.file.Files; import java.util.Map; import java.util.Map.Entry; @@ -336,11 +338,11 @@ public class FileWriter extends FileWrapper { * @since 5.5.2 */ public File writeFromStream(InputStream in, boolean isCloseIn) throws IORuntimeException { - FileOutputStream out = null; + OutputStream out = null; try { - out = new FileOutputStream(FileUtil.touch(file)); + out = Files.newOutputStream(FileUtil.touch(file).toPath()); IoUtil.copy(in, out); - } catch (IOException e) { + } catch (final IOException e) { throw new IORuntimeException(e); } finally { IoUtil.close(out); @@ -359,7 +361,7 @@ public class FileWriter extends FileWrapper { */ public BufferedOutputStream getOutputStream() throws IORuntimeException { try { - return new BufferedOutputStream(new FileOutputStream(FileUtil.touch(file))); + return new BufferedOutputStream(Files.newOutputStream(FileUtil.touch(file).toPath())); } catch (IOException e) { throw new IORuntimeException(e); }