mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
根据JDK-8080225修改了部分新建文件输入流和文件输出流的创建方式
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user